Example #1
0
 /**
  * Main process to apply patch.
  * @access  public
  * @return  true  if patch is successfully applied
  *          false if failed
  * @author  Cindy Qi Li
  */
 function applyPatch()
 {
     global $msg;
     // Checks on
     // 1. if there's error from class constructor
     // 2. if github server is up. If not, consider all files manipulated by patch as modified
     // 3. if the local file is customized by user
     // 4. if script has write priviledge on local file/folder
     // 5. if dependent patches have been installed
     if (count($this->errors) > 0) {
         print_errors($this->errors, $notes);
         unset($this->errors);
         return false;
     }
     if (!$this->pingDomain($this->github_tag_folder) || !$this->pingDomain($this->github_fetch_tags_url)) {
         $msg->addInfo('CANNOT_CONNECT_GITHUB_SERVER');
         $msg->printInfos();
         $this->github_server_connected = false;
     } else {
         $this->github_server_connected = true;
     }
     if (!$this->checkDependentPatches()) {
         return false;
     }
     if (!$this->checkAppliedVersion()) {
         return false;
     }
     if (!$this->skipFilesModified && $this->hasFilesModified()) {
         return false;
     }
     if (!$this->checkPriviledge()) {
         return false;
     }
     // End of check
     if (strlen(trim($this->patch_array['sql'])) > 0) {
         $this->runSQL();
     }
     // Start applying patch
     $this->createPatchesRecord($this->patch_summary_array);
     // if no file action defined, update database and return true
     if (!is_array($this->patch_array[files])) {
         $updateInfo = array("status" => "Installed");
         updatePatchesRecord($this->patch_id, $updateInfo);
         return true;
     }
     foreach ($this->patch_array[files] as $row_num => $patch_file) {
         $this->createPatchesFilesRecord($this->patch_array['files'][$row_num]);
         if ($patch_file['action'] == 'alter') {
             $this->alterFile($row_num);
         } else {
             if ($patch_file['action'] == 'add') {
                 $this->addFile($row_num);
             } else {
                 if ($patch_file['action'] == 'delete') {
                     $this->deleteFile($row_num);
                 } else {
                     if ($patch_file['action'] == 'overwrite') {
                         $this->overwriteFile($row_num);
                     }
                 }
             }
         }
     }
     // if only has backup files info, patch is considered successfully installed
     // if has permission to remove, considered partly installed
     $updateInfo = array();
     if (count($this->backup_files) > 0) {
         foreach ($this->backup_files as $backup_file) {
             $backup_files .= $backup_file . '|';
         }
         $updateInfo = array("backup_files" => my_add_null_slashes($backup_files));
         if (count($this->patch_files) > 0) {
             foreach ($this->patch_files as $patch_file) {
                 $patch_files .= $patch_file . '|';
             }
             $updateInfo = array_merge($updateInfo, array("patch_files" => my_add_null_slashes($patch_files)));
         }
         if (is_array($_SESSION['remove_permission']) && count($_SESSION['remove_permission'])) {
             foreach ($_SESSION['remove_permission'] as $remove_permission_file) {
                 $remove_permission_files .= $remove_permission_file . '|';
             }
             $updateInfo = array_merge($updateInfo, array("remove_permission_files" => my_add_null_slashes($remove_permission_files), "status" => "Partly Installed"));
         } else {
             $updateInfo = array_merge($updateInfo, array("status" => "Installed"));
         }
         updatePatchesRecord($this->patch_id, $updateInfo);
         unset($_SESSION['remove_permission']);
         return true;
     }
 }
Example #2
0
     if (is_array($_SESSION['remove_permission'])) {
         foreach ($_SESSION['remove_permission'] as $file) {
             if (is_writable($file)) {
                 $permission_files[] = $file;
             }
         }
     }
     if (count($permission_files) == 0) {
         $updateInfo = array("remove_permission_files" => "", "status" => "Installed");
         updatePatchesRecord($patch_id, $updateInfo);
     } else {
         foreach ($permission_files as $permission_file) {
             $remove_permission_files .= $permission_file . '|';
         }
         $updateInfo = array("remove_permission_files" => preg_quote($remove_permission_files), "status" => "Partly Installed");
         updatePatchesRecord($patch_id, $updateInfo);
     }
 }
 // display remove permission info
 unset($_SESSION['remove_permission']);
 $sql = "SELECT * FROM " . TABLE_PREFIX . "patches \n\t         WHERE patches_id = " . $patch_id;
 $result = mysql_query($sql, $db) or die(mysql_error());
 $row = mysql_fetch_assoc($result);
 if ($row["remove_permission_files"] != "") {
     $remove_permission_files = $_SESSION['remove_permission'] = get_array_by_delimiter($row["remove_permission_files"], "|");
     if (count($_SESSION['remove_permission']) > 0) {
         if ($_POST['done']) {
             $msg->printErrors('REMOVE_WRITE_PERMISSION');
         } else {
             $msg->printInfos('PATCH_INSTALLED_AND_REMOVE_PERMISSION');
         }