Skip to content

Commit

Permalink
Fix error deletecomputer via cronCleanOldAgents
Browse files Browse the repository at this point in the history
  • Loading branch information
amma35 committed Jan 13, 2017
1 parent 573c94e commit 1a35412
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 37 deletions.
7 changes: 4 additions & 3 deletions inc/ocsdbclient.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,10 @@ public function deleteOldAgents($agents)
);
if (isset($tables) and is_array($tables)) {
foreach ($tables as $table) {

$sql = "DELETE FROM $table WHERE HARDWARE_ID='" . $agent . "'";
$this->db->query($sql);
if(self::OcsTableExists($table)){
$sql = "DELETE FROM $table WHERE HARDWARE_ID='" . $agent . "'";
$this->db->query($sql);
}
}
}
$sql = "DELETE FROM download_enable WHERE SERVER_ID='" . $agent . "'";
Expand Down
72 changes: 38 additions & 34 deletions inc/ocsserver.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5836,22 +5836,24 @@ static function updateOfficePack($computers_id, $entity, $ocsComputer, $cfg_ocs)
//---- The software exists in this license for this computer --------------//
//---------------------------- Update comments ----------------------------//
//---------------------------------------------------- --------------------//
if ($software_licenses->getFromDBByQuery("WHERE `softwares_id` = " . $softwares_id . "
AND `serial` = '" . $ocsOfficePack['OFFICEKEY'] . "'
AND `softwareversions_id_use` = " . $softwareversions_id)) {

$software_licenses->update(array('id' => $software_licenses->getID(),
'comment' => $ocsOfficePack['NOTE']));
if (!$computer_softwarelicenses->getFromDBByQuery("WHERE `computers_id` = " . $computers_id . "
AND `softwarelicenses_id` = " . $software_licenses->getID())) {

$computer_soft_l['computers_id'] = $computers_id;
$computer_soft_l['softwarelicenses_id'] = $software_licenses->getID();
$computer_soft_l['is_dynamic'] = -1;
$computer_softwarelicenses->add($computer_soft_l);
//Update for validity
if(!empty($ocsOfficePack['OFFICEKEY'])){
if ($software_licenses->getFromDBByQuery("WHERE `softwares_id` = " . $softwares_id . "
AND `serial` = '" . $ocsOfficePack['OFFICEKEY'] . "'
AND `softwareversions_id_use` = " . $softwareversions_id)) {

$software_licenses->update(array('id' => $software_licenses->getID(),
'is_valid' => 1));
'comment' => $ocsOfficePack['NOTE']));
if (!$computer_softwarelicenses->getFromDBByQuery("WHERE `computers_id` = " . $computers_id . "
AND `softwarelicenses_id` = " . $software_licenses->getID())) {

$computer_soft_l['computers_id'] = $computers_id;
$computer_soft_l['softwarelicenses_id'] = $software_licenses->getID();
$computer_soft_l['is_dynamic'] = -1;
$computer_softwarelicenses->add($computer_soft_l);
//Update for validity
$software_licenses->update(array('id' => $software_licenses->getID(),
'is_valid' => 1));
}
}
}

Expand All @@ -5860,25 +5862,27 @@ static function updateOfficePack($computers_id, $entity, $ocsComputer, $cfg_ocs)
//------------------------------------------------------------------------//
//---- The software doesn't exists in this license for this computer -----//
//------------------------------------------------------------------------//
if ($software_licenses->getFromDBByQuery("WHERE `softwares_id` = " . $softwares_id . "
AND `serial` = '" . $ocsOfficePack['OFFICEKEY'] . "'
AND `softwareversions_id_use` = " . $softwareversions_id)) {
$id_software_licenses = $software_licenses->getID();
} else {
$software_licenses->fields['softwares_id'] = $softwares_id;
$id_software_licenses = $software_licenses->add($soft_l, array(), $cfg_ocs['history_software']);
}

if ($id_software_licenses) {
$computer_soft_l['computers_id'] = $computers_id;
$computer_soft_l['softwarelicenses_id'] = $id_software_licenses;
$computer_soft_l['is_dynamic'] = 1;
$computer_soft_l['number'] = -1;

$computer_softwarelicenses->add($computer_soft_l);
//Update for validity
$software_licenses->update(array('id' => $id_software_licenses,
'is_valid' => 1));
if(!empty($ocsOfficePack['OFFICEKEY'])){
if ($software_licenses->getFromDBByQuery("WHERE `softwares_id` = " . $softwares_id . "
AND `serial` = '" . $ocsOfficePack['OFFICEKEY'] . "'
AND `softwareversions_id_use` = " . $softwareversions_id)) {
$id_software_licenses = $software_licenses->getID();
} else {
$software_licenses->fields['softwares_id'] = $softwares_id;
$id_software_licenses = $software_licenses->add($soft_l, array(), $cfg_ocs['history_software']);
}

if ($id_software_licenses) {
$computer_soft_l['computers_id'] = $computers_id;
$computer_soft_l['softwarelicenses_id'] = $id_software_licenses;
$computer_soft_l['is_dynamic'] = 1;
$computer_soft_l['number'] = -1;

$computer_softwarelicenses->add($computer_soft_l);
//Update for validity
$software_licenses->update(array('id' => $id_software_licenses,
'is_valid' => 1));
}
}
}
}
Expand Down

0 comments on commit 1a35412

Please sign in to comment.