예제 #1
0
 /**
  * init to build informations we need
  *
  * @return void
  */
 public function init()
 {
     // For later use, let's set up prodRootDir and adminDir
     // This way it will be easier to upgrade a different path if needed
     $this->prodRootDir = _PS_ROOT_DIR_;
     $this->adminDir = _PS_ADMIN_DIR_;
     if (!defined('__PS_BASE_URI__')) {
         // _PS_DIRECTORY_ replaces __PS_BASE_URI__ in 1.5
         if (defined('_PS_DIRECTORY_')) {
             define('__PS_BASE_URI__', _PS_DIRECTORY_);
         } else {
             define('__PS_BASE_URI__', realpath(dirname($_SERVER['SCRIPT_NAME'])) . '/../../');
         }
     }
     // from $_POST or $_GET
     $this->action = empty($_REQUEST['action']) ? null : $_REQUEST['action'];
     $this->currentParams = empty($_REQUEST['params']) ? null : $_REQUEST['params'];
     // test writable recursively
     if (!class_exists('ConfigurationTest', false)) {
         require_once dirname(__FILE__) . '/classes/ConfigurationTest.php';
         if (!class_exists('ConfigurationTest', false) and class_exists('ConfigurationTestCore')) {
             eval('class ConfigurationTest extends ConfigurationTestCore{}');
         }
     }
     $this->initPath();
     $upgrader = new Upgrader();
     preg_match('#([0-9]+\\.[0-9]+)(?:\\.[0-9]+){1,2}#', _PS_VERSION_, $matches);
     if (isset($matches[1])) {
         $upgrader->branch = $matches[1];
     }
     $channel = $this->getConfig('channel');
     switch ($channel) {
         case 'archive':
             $this->install_version = $this->getConfig('archive.version_num');
             $this->destDownloadFilename = $this->getConfig('archive.filename');
             $upgrader->checkPSVersion(true, array('archive'));
             break;
         case 'directory':
             $this->install_version = $this->getConfig('directory.version_num');
             $upgrader->checkPSVersion(true, array('directory'));
             break;
         default:
             $upgrader->channel = $channel;
             if ($this->getConfig('channel') == 'private' && !$this->getConfig('private_allow_major')) {
                 $upgrader->checkPSVersion(true, array('private', 'minor'));
             } else {
                 $upgrader->checkPSVersion(true, array('minor'));
             }
             $this->install_version = $upgrader->version_num;
     }
     $this->upgrader = $upgrader;
     // If you have defined this somewhere, you know what you do
     /* load options from configuration if we're not in ajax mode */
     if (!$this->ajax) {
         $this->createCustomToken();
         $postData = 'version=' . _PS_VERSION_ . '&method=listing&action=native&iso_code=all';
         $xml_local = $this->prodRootDir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'modules_native_addons.xml';
         $xml = $upgrader->getApiAddons($xml_local, $postData, true);
         if (is_object($xml)) {
             foreach ($xml as $mod) {
                 $this->modules_addons[(string) $mod->id] = (string) $mod->name;
             }
         }
         // installedLanguagesIso is used to merge translations files
         $iso_ids = Language::getIsoIds(false);
         foreach ($iso_ids as $v) {
             $this->installedLanguagesIso[] = $v['iso_code'];
         }
         $rand = dechex(mt_rand(0, min(0xffffffff, mt_getrandmax())));
         $date = date('Ymd-His');
         $this->backupName = 'V' . _PS_VERSION_ . '_' . $date . '-' . $rand;
         $this->backupFilesFilename = 'auto-backupfiles_' . $this->backupName . '.zip';
         $this->backupDbFilename = 'auto-backupdb_XXXXXX_' . $this->backupName . '.sql';
         // removing temporary files
         $this->cleanTmpFiles();
     } else {
         foreach ($this->ajaxParams as $prop) {
             if (property_exists($this, $prop)) {
                 $this->{$prop} = isset($this->currentParams[$prop]) ? $this->currentParams[$prop] : '';
             }
         }
     }
     $this->keepImages = $this->getConfig('PS_AUTOUP_KEEP_IMAGES');
     $this->updateDefaultTheme = $this->getConfig('PS_AUTOUP_UPDATE_DEFAULT_THEME');
     $this->changeToDefaultTheme = $this->getConfig('PS_AUTOUP_CHANGE_DEFAULT_THEME');
     $this->keepMails = $this->getConfig('PS_AUTOUP_KEEP_MAILS');
     $this->manualMode = defined('_PS_MODE_DEV_') && _PS_MODE_DEV_ ? (bool) $this->getConfig('PS_AUTOUP_MANUAL_MODE') : false;
     $this->deactivateCustomModule = $this->getConfig('PS_AUTOUP_CUSTOM_MOD_DESACT');
     // during restoration, do not remove :
     $this->restoreIgnoreAbsoluteFiles[] = '/app/config/parameters.php';
     $this->restoreIgnoreAbsoluteFiles[] = '/app/config/parameters.yml';
     $this->restoreIgnoreAbsoluteFiles[] = '/modules/autoupgrade';
     $this->restoreIgnoreAbsoluteFiles[] = '/admin/autoupgrade';
     $this->restoreIgnoreAbsoluteFiles[] = '.';
     $this->restoreIgnoreAbsoluteFiles[] = '..';
     // during backup, do not save
     $this->backupIgnoreAbsoluteFiles[] = '/app/cache';
     $this->backupIgnoreAbsoluteFiles[] = '/cache/smarty/compile';
     $this->backupIgnoreAbsoluteFiles[] = '/cache/smarty/cache';
     $this->backupIgnoreAbsoluteFiles[] = '/cache/tcpdf';
     $this->backupIgnoreAbsoluteFiles[] = '/cache/cachefs';
     // do not care about the two autoupgrade dir we use;
     $this->backupIgnoreAbsoluteFiles[] = '/modules/autoupgrade';
     $this->backupIgnoreAbsoluteFiles[] = '/admin/autoupgrade';
     $this->backupIgnoreFiles[] = '.';
     $this->backupIgnoreFiles[] = '..';
     $this->backupIgnoreFiles[] = '.svn';
     $this->backupIgnoreFiles[] = '.git';
     $this->backupIgnoreFiles[] = $this->autoupgradeDir;
     $this->excludeFilesFromUpgrade[] = '.';
     $this->excludeFilesFromUpgrade[] = '..';
     $this->excludeFilesFromUpgrade[] = '.svn';
     $this->excludeFilesFromUpgrade[] = '.git';
     // do not copy install, neither app/config/parameters.php in case it would be present
     $this->excludeAbsoluteFilesFromUpgrade[] = '/app/config/parameters.php';
     $this->excludeAbsoluteFilesFromUpgrade[] = '/app/config/parameters.yml';
     $this->excludeAbsoluteFilesFromUpgrade[] = '/install';
     $this->excludeAbsoluteFilesFromUpgrade[] = '/install-dev';
     // this will exclude autoupgrade dir from admin, and autoupgrade from modules
     $this->excludeFilesFromUpgrade[] = $this->autoupgradeDir;
     if ($this->keepImages === '0') {
         $this->backupIgnoreAbsoluteFiles[] = '/img';
         $this->restoreIgnoreAbsoluteFiles[] = '/img';
     } else {
         $this->backupIgnoreAbsoluteFiles[] = '/img/tmp';
         $this->restoreIgnoreAbsoluteFiles[] = '/img/tmp';
     }
     if (!$this->updateDefaultTheme) {
         $this->excludeAbsoluteFilesFromUpgrade[] = '/themes/classic';
     }
 }