Update multiple ids with one query

This commit is contained in:
Jaroslav Drzik
2021-12-10 18:33:19 +01:00
parent 8ac143be27
commit a8e4ddb2e0

View File

@@ -56,6 +56,20 @@ class PluginRemotesupportRemotesupport extends CommonDBTM
return $states_ids;
}
public static function getContactArray()
{
global $DB;
$req = $DB->request('glpi_computers', ['FIELDS' => ['glpi_computers' => ['id', 'contact']]]);
$contactids = [];
while ($ret = $req->next()) {
$contactids[$ret["id"]] = $ret["contact"];
}
return $contactids;
}
public static function cronRemotesupport($task)
{
global $DB;
@@ -117,19 +131,22 @@ class PluginRemotesupportRemotesupport extends CommonDBTM
['1' => '1']
);
$ids = [];
$cids = self::getContactArray();
foreach ($checked as $s) {
$comp = new Computer();
$comp->getFromDB($s->computers_id);
$comp->fields["states_id"] = $stids["Online"];
$DB->update("glpi_computers", [
'states_id' => $comp->fields["states_id"]],
['id' => $s->computers_id]
);
Toolbox::logInFile("remotsupport", $s->computers_id . " " . $comp->fields["contact"] . "\n");
Toolbox::logInFile("remotsupport", $s->computers_id . " " . $cids[$s->computers_id] . "\n");
$ids[] = $s->computers_id;
}
$DB->update("glpi_computers", [
'states_id' => $stids["Online"] ],
['id' => $ids ]
);
return 0;
}