2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
14 * DAO for "patches" table
20 if (!defined('TR_INCLUDE_PATH')) exit;
22 require_once(TR_INCLUDE_PATH. 'classes/DAO/DAO.class.php');
24 class PatchesDAO extends DAO {
29 * @param system_patch_id: atutor patch id,
36 * remove_permission_files,
40 * @return patch id, if successful
41 * false and add error into global var $msg, if unsuccessful
44 public function Create($system_patch_id, $applied_version,
45 $patch_folder, $description,
46 $available_to, $sql_statement,
47 $status, $remove_permission_files,
48 $backup_files, $patch_files, $author)
52 $sql = "INSERT INTO " . TABLE_PREFIX. "patches " .
60 remove_permission_files,
66 ('".$addslashes($system_patch_id)."',
67 '".$addslashes($applied_version)."',
68 '".$addslashes($patch_folder)."',
69 '".$addslashes($description)."',
70 '".$addslashes($available_to)."',
71 '".$addslashes($sql_statement)."',
72 '".$addslashes($status)."',
73 '".$addslashes($remove_permission_files)."',
74 '".$addslashes($backup_files)."',
75 '".$addslashes($patch_files)."',
76 '".$addslashes($author)."',
80 if (!$this->execute($sql))
82 $msg->addError('DB_NOT_UPDATED');
87 return mysql_insert_id();
92 * update table "patches" accroding to the fields/values in the given array
94 * @param patchID, fieldArray
97 public function UpdateByArray($patchID, $fieldArray)
99 $sql_prefix = "Update ". TABLE_PREFIX. "patches set ";
101 foreach ($fieldArray as $key => $value)
103 $sql_middle .= $key . "='" . $value . "', ";
106 $sql = substr($sql_prefix . $sql_middle, 0, -2) .
107 " WHERE patches_id = " . $patchID;
109 return $this->execute($sql);
113 * Return the patch info with the given patch id
117 * @author Cindy Qi Li
119 public function getByID($patchID)
121 $sql = "SELECT * from ".TABLE_PREFIX."patches where patches_id=". $patchID;
123 $rows = $this->execute($sql);
125 if (is_array($rows)) return $rows[0];
130 * Return patch information by given version
134 * @author Cindy Qi Li
136 public function getPatchByVersion($version)
138 $sql = "SELECT * FROM ".TABLE_PREFIX."patches
139 WHERE applied_version = '" . $version . "'
140 ORDER BY system_patch_id";
142 return $this->execute($sql);
146 * Return user information by given web service ID
148 * @param web service ID
150 * @author Cindy Qi Li
152 public function getInstalledPatchByIDAndVersion($patchID, $version)
154 $sql = "select * from ".TABLE_PREFIX."patches " .
155 "where system_patch_id = '" . $patchID ."'".
156 " and applied_version = '".$version."'".
157 " and status like '%Installed'";
159 return $this->execute($sql);