/**
  * @return bool
  */
 private function _upgradeCore()
 {
     $package_info =& $this->session->data['package_info'];
     if (versionCompare(VERSION, $package_info['package_version'], ">=")) {
         $this->session->data['error'] = str_replace('%VERSION%', VERSION, $this->language->get('error_core_version')) . $package_info['package_version'] . '!';
         unset($this->session->data['package_info']);
         $this->redirect($this->_get_begin_href());
     }
     $corefiles = $package_info['package_content']['core'];
     $pmanager = new APackageManager();
     //#1 backup files
     $backup = new ABackup('abantecart_' . str_replace('.', '', VERSION));
     foreach ($corefiles as $core_file) {
         if (file_exists(DIR_ROOT . '/' . $core_file)) {
             if (!$backup->backupFile(DIR_ROOT . '/' . $core_file, false)) {
                 return false;
             }
         }
     }
     //#2 backup database
     if ($backup->dumpDatabase()) {
         $backup_dirname = $backup->getBackupName();
         if ($backup_dirname) {
             if (!$backup->dumpDatabase()) {
                 $this->session->data['error'] = $backup->error;
                 return false;
             }
             if (!$backup->archive(DIR_BACKUP . $backup_dirname . '.tar.gz', DIR_BACKUP, $backup_dirname)) {
                 $this->session->data['error'] = $backup->error;
                 return false;
             }
         } else {
             $this->session->data['error'] = 'Error: Unknown directory name for backup.';
             return false;
         }
         $install_upgrade_history = new ADataset('install_upgrade_history', 'admin');
         $install_upgrade_history->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => 'Backup before core upgrade. Core version: ' . VERSION, 'version' => VERSION, 'backup_file' => $backup_dirname . '.tar.gz', 'backup_date' => date("Y-m-d H:i:s", time()), 'type' => 'backup', 'user' => $this->user->getUsername()));
     } else {
         $this->session->data['error'] = $backup->error;
         return false;
     }
     //#3 replace files
     $pmanager->replaceCoreFiles();
     //#4 run sql and php upgare procedure files
     $package_dirname = $package_info['tmp_dir'] . $package_info['package_dir'];
     /**
      * @var SimpleXmlElement $config
      */
     $config = simplexml_load_string(file_get_contents($package_dirname . '/package.xml'));
     if (!$config) {
         $this->session->data['error'] = 'Error: package.xml from package content is not valid xml-file!';
         unset($this->session->data['package_info']);
         $this->redirect($this->_get_begin_href());
     }
     $pmanager->upgradeCore($config);
     $pmanager->updateCoreVersion((string) $config->version);
     return true;
 }
Exemplo n.º 2
0
 /**
  * Function make backup and move it into admin/system/backup/directory
  * @param string $extension_id
  * @return bool
  */
 public function backupPrevious($extension_id = '')
 {
     $old_path = !$extension_id ? DIR_ROOT . '/' . $this->session->data['package_info']['dst_dir'] : DIR_EXT;
     $package_id = !$extension_id ? $this->session->data['package_info']['package_id'] : $extension_id;
     if (!$package_id) {
         return false;
     }
     if (file_exists($old_path . $package_id)) {
         $backup = new ABackup($extension_id);
         $backup_dirname = $backup->getBackupName();
         if ($backup_dirname) {
             if (!$backup->backupDirectory($old_path . $package_id)) {
                 $this->error = $backup->error;
                 return false;
             }
             if (!$backup->dumpDatabase()) {
                 return false;
             }
             if (!$backup->archive(DIR_BACKUP . $backup_dirname . '.tar.gz', DIR_BACKUP, $backup_dirname)) {
                 return false;
             }
         } else {
             return false;
         }
         $info = $this->extensions->getExtensionInfo($package_id);
         $install_upgrade_history = new ADataset('install_upgrade_history', 'admin');
         $install_upgrade_history->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => $package_id, 'version' => $info['version'], 'backup_file' => $backup_dirname . '.tar.gz', 'backup_date' => date("Y-m-d H:i:s", time()), 'type' => 'backup', 'user' => $this->user->getUsername()));
         //delete previous version
         $this->removeDir($old_path . $package_id);
     }
     return true;
 }