diff --git a/inc/inventorycomputerlib.class.php b/inc/inventorycomputerlib.class.php index 9ea02f60f..d772901d9 100644 --- a/inc/inventorycomputerlib.class.php +++ b/inc/inventorycomputerlib.class.php @@ -1499,33 +1499,36 @@ function updateComputer($a_computerinventory, $computers_id, $no_history, $setdy } if (count($db_crontasks) == 0) { - foreach ($a_computerinventory['crontasks'] as $a_crontask) { - if (isset($a_crontask['user_execution'])) { - $a_crontask['user_id_execution'] = $this->retrieveFusionInventoryCronTaskUserId($DB, $a_crontask['user_execution']); - } + if (isset($a_computerinventory['crontasks'])) { + foreach ($a_computerinventory['crontasks'] as $a_crontask) { + if (isset($a_crontask['user_execution'])) { + $a_crontask['user_id_execution'] = $this->retrieveFusionInventoryCronTaskUserId($DB, $a_crontask['user_execution']); + } - if (isset($a_crontask['user_storage'])) { - $a_crontask['user_id_storage'] = $this->retrieveFusionInventoryCronTaskUserId($DB, $a_crontask['user_storage']); - } + if (isset($a_crontask['user_storage'])) { + $a_crontask['user_id_storage'] = $this->retrieveFusionInventoryCronTaskUserId($DB, $a_crontask['user_storage']); + } - $a_crontask['computers_id'] = $computers_id; - $this->addFusionInventoryCronTask($a_crontask, $no_history); + $a_crontask['computers_id'] = $computers_id; + $this->addFusionInventoryCronTask($a_crontask, $no_history); + } } } else { - foreach ($a_computerinventory['crontasks'] as $key => $arrays) { - $arrayslower = array_map('strtolower', $arrays); - - foreach ($db_crontasks as $keydb => $arraydb) { - if ($arrayslower['name'] == $arraydb['name'] - && $arrayslower['storage'] == $arraydb['storage']) { - $arrays['id'] = $keydb; - $cronTask->update($arrays); - unset($a_computerinventory['crontasks'][$key]); - unset($db_crontasks[$keydb]); - break; + if (isset($a_computerinventory['crontasks'])) { + foreach ($a_computerinventory['crontasks'] as $key => $arrays) { + $arrayslower = array_map('strtolower', $arrays); + + foreach ($db_crontasks as $keydb => $arraydb) { + if ($arrayslower['name'] == $arraydb['name'] + && $arrayslower['storage'] == $arraydb['storage']) { + $arrays['id'] = $keydb; + $cronTask->update($arrays); + unset($a_computerinventory['crontasks'][$key]); + unset($db_crontasks[$keydb]); + break; + } } } - } //delete remaining crontasks in database if (count($db_crontasks) > 0) { @@ -1534,7 +1537,7 @@ function updateComputer($a_computerinventory, $computers_id, $no_history, $setdy } } //add new crontasks in database - if (count($a_computerinventory['crontasks']) != 0) { + if (isset($a_computerinventory['crontasks']) && count($a_computerinventory['crontasks']) != 0) { foreach ($a_computerinventory['crontasks'] as $a_crontask) { if (isset($a_crontask['user_execution'])) { $a_crontask['user_id_execution'] = $this->retrieveFusionInventoryCronTaskUserId($DB, $a_crontask['user_execution']);