/** * Given a name check if it exists in the table * @param name the unique key from the manifest * @param id the id of the item you are comparing to * @return upgrade_history object if found, null otherwise */ function checkForExisting($patch_to_check) { $uh = new UpgradeHistory(); if ($patch_to_check != null) { if (empty($patch_to_check->id_name)) { $where = " WHERE name = '{$patch_to_check->name}' "; } else { $where = " WHERE id_name = '{$patch_to_check->id_name}' "; } if (!empty($patch_to_check->id)) { $where .= " AND id != '{$patch_to_check->id}' "; } else { $where .= " AND id is not null "; } $query = "SELECT id FROM " . $this->table_name . " " . $where; $result = $uh->db->query($query); if (empty($result)) { return null; } $row = $uh->db->fetchByAssoc($result); if (empty($row)) { return null; } if (!empty($row['id'])) { return $uh->retrieve($row['id']); } } return null; }
break; default: break; } switch ($mode) { case "Install": $file_action = "copied"; // if error was encountered, script should have died before now $new_upgrade = new UpgradeHistory(); //determine if this module has already been installed given the unique_key to //identify the module // $new_upgrade->checkForExisting($unique_key); if (!empty($previous_id)) { $new_upgrade->id = $previous_id; $uh = new UpgradeHistory(); $uh->retrieve($previous_id); unlink($uh->filename); } $new_upgrade->filename = $install_file; $new_upgrade->md5sum = md5_file($install_file); $new_upgrade->type = $install_type; $new_upgrade->version = $version; $new_upgrade->status = "installed"; $new_upgrade->name = $name; $new_upgrade->description = $description; $new_upgrade->id_name = $id_name; $new_upgrade->manifest = $s_manifest; $new_upgrade->save(); break; case "Uninstall": $file_action = "removed";