Array of states
This commit is contained in:
@@ -40,15 +40,32 @@ class PluginRemotesupportRemotesupport extends CommonDBTM {
|
||||
|
||||
}
|
||||
|
||||
static function getStatesIds() {
|
||||
global $DB;
|
||||
|
||||
$states_ids = [];
|
||||
|
||||
$req = $DB->request('glpi_states', ['FIELDS' => ['glpi_states' => ['id', 'name']]], [ 'OR' => [ 'name' => 'Online', 'name' => 'Offline']]);
|
||||
|
||||
$ret = $req->next();
|
||||
$states_ids[$ret['name']] = $ret['id'];
|
||||
$ret = $req->next();
|
||||
$states_ids[$ret['name']] = $ret['id'];
|
||||
|
||||
return $states_ids;
|
||||
}
|
||||
|
||||
static function cronRemotesupport($task) {
|
||||
global $DB;
|
||||
|
||||
Toolbox::logInFile("remotsupport","Starting search of agents\n");
|
||||
Toolbox::logInFile("remotsupport","Starting search of agents\n");
|
||||
|
||||
$agents = [];
|
||||
$data_set = [];
|
||||
|
||||
$stids = self::getStatesIds();
|
||||
|
||||
|
||||
foreach (getAllDataFromTable(PluginFusioninventoryAgent::getTable()) as $a) {
|
||||
|
||||
$data_set[] = $a["id"];
|
||||
@@ -67,9 +84,9 @@ class PluginRemotesupportRemotesupport extends CommonDBTM {
|
||||
$comp = new Computer();
|
||||
$comp->getFromDB($agents[$id]["computers_id"]);
|
||||
if ($st["message"] == "noanswer")
|
||||
$comp->fields["states_id"] = NULL;
|
||||
$comp->fields["states_id"] = $stids["Offline"];
|
||||
else
|
||||
$comp->fields["states_id"] = 2;
|
||||
$comp->fields["states_id"] = $stids["Online"];
|
||||
$DB->update("glpi_computers", [
|
||||
'states_id' => $comp->fields["states_id"] ],
|
||||
[ 'id' => $agents[$id]["computers_id"] ]
|
||||
|
||||
Reference in New Issue
Block a user