/**
  * @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();
     /*
     		 * Commented by decision do not use it in community version.
     		 * Pasted alerts before upgrade process start.
     		 * Do not remove code yet.
     		 *
     		//backup files
     		$backup = new ABackup('abantecart_' . str_replace('.','',VERSION));
     		//interrupt if backup directory is inaccessable
     		if ($backup->error) {
     			$this->session->data['error'] = implode("\n", $backup->error);
     			return false;
     		}
     		foreach ($corefiles as $core_file) {
     			if (file_exists(DIR_ROOT . '/' . $core_file)) {
     				if (!$backup->backupFile(DIR_ROOT . '/' . $core_file, false)) {
     					return false;
     				}
     			}
     		}
     		// backup database
     		if ($backup->dumpDatabase()) {
     			$backup_dirname = $backup->getBackupName();
     			if ($backup_dirname) {
     				if (!$backup->dumpDatabase()) {
     					$this->session->data['error'] = implode("\n", $backup->error);
     					return false;
     				}
     				if (!$backup->archive(DIR_BACKUP . $backup_dirname . '.tar.gz', DIR_BACKUP, $backup_dirname)) {
     					$this->session->data['error'] = implode("\n", $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'] = implode("\n", $backup->error);
     			return false;
     		}*/
     //replace files
     $pmanager->replaceCoreFiles();
     //run sql and php upgrade procedure files
     $package_dirname = $package_info['tmp_dir'] . $package_info['package_dir'];
     if ($pmanager->error) {
         $this->session->data['error'] = $pmanager->error;
     }
     /**
      * @var DOMNode $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);
     if ($pmanager->error) {
         $this->session->data['error'] .= "\n" . $pmanager->error;
     }
     return true;
 }
 /**
  * @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_' . 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)) {
                 return false;
             }
         } else {
             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;
 }