Example #1
0
 public static function test_virtual_products_dir($dir)
 {
     return ConfigurationTest::test_dir($dir);
 }
 public static function test_dir($relative_dir, $recursive = false, &$full_report = null)
 {
     $dir = rtrim(_PS_ROOT_DIR_, '\\/') . DIRECTORY_SEPARATOR . trim($relative_dir, '\\/');
     if (!file_exists($dir) || !($dh = opendir($dir))) {
         $full_report = sprintf('Directory %s does not exists or is not writable', $dir);
         // sprintf for future translation
         return false;
     }
     $dummy = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR . uniqid();
     if (false && @file_put_contents($dummy, 'test')) {
         @unlink($dummy);
         if (!$recursive) {
             closedir($dh);
             return true;
         }
     } elseif (!is_writable($dir)) {
         $full_report = sprintf('Directory %s is not writable', $dir);
         // sprintf for future translation
         return false;
     }
     if ($recursive) {
         while (($file = readdir($dh)) !== false) {
             if (is_dir($dir . DIRECTORY_SEPARATOR . $file) && $file != '.' && $file != '..' && $file != '.svn') {
                 if (!ConfigurationTest::test_dir($relative_dir . DIRECTORY_SEPARATOR . $file, $recursive, $full_report)) {
                     return false;
                 }
             }
         }
     }
     closedir($dh);
     return true;
 }
    public function postProcessCallback()
    {
        $return = false;
        $installed_modules = array();
        foreach ($this->map as $key => $method) {
            $modules = Tools::getValue($key);
            if (strpos($modules, '|')) {
                $modules_list_save = $modules;
                $modules = explode('|', $modules);
            } else {
                $modules = empty($modules) ? false : array($modules);
            }
            $module_errors = array();
            if ($modules) {
                foreach ($modules as $name) {
                    $full_report = null;
                    if ($key == 'update') {
                        if (ConfigurationTest::test_dir('modules/' . $name, true, $full_report)) {
                            Tools::deleteDirectory('../modules/' . $name . '/');
                        } else {
                            $module = Module::getInstanceByName(urldecode($name));
                            $this->errors[] = $this->l(sprintf("Module %s can't be upgraded : ", $module->displayName)) . $full_report;
                            continue;
                        }
                    }
                    // If Addons module, download and unzip it before installing it
                    if (!file_exists('../modules/' . $name . '/' . $name . '.php')) {
                        $filesList = array(array('type' => 'addonsNative', 'file' => Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST, 'loggedOnAddons' => 0), array('type' => 'addonsBought', 'file' => Module::CACHE_FILE_CUSTOMER_MODULES_LIST, 'loggedOnAddons' => 1));
                        foreach ($filesList as $f) {
                            if (file_exists(_PS_ROOT_DIR_ . $f['file'])) {
                                $file = $f['file'];
                                $content = Tools::file_get_contents(_PS_ROOT_DIR_ . $file);
                                $xml = @simplexml_load_string($content, null, LIBXML_NOCDATA);
                                foreach ($xml->module as $modaddons) {
                                    if ($name == $modaddons->name && isset($modaddons->id) && ($this->logged_on_addons || $f['loggedOnAddons'] == 0)) {
                                        if ($f['loggedOnAddons'] == 0) {
                                            if (file_put_contents('../modules/' . $modaddons->name . '.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id))))) {
                                                $this->extractArchive('../modules/' . $modaddons->name . '.zip', false);
                                            }
                                        }
                                        if ($f['loggedOnAddons'] == 1 && $this->logged_on_addons) {
                                            if (file_put_contents('../modules/' . $modaddons->name . '.zip', Tools::addonsRequest('module', array('id_module' => pSQL($modaddons->id), 'username_addons' => pSQL(trim($this->context->cookie->username_addons)), 'password_addons' => pSQL(trim($this->context->cookie->password_addons)))))) {
                                                $this->extractArchive('../modules/' . $modaddons->name . '.zip', false);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    // Check potential error
                    if (!($module = Module::getInstanceByName(urldecode($name)))) {
                        $this->errors[] = $this->l('Module not found');
                    } elseif ($key == 'install' && $this->tabAccess['add'] !== '1') {
                        $this->errors[] = Tools::displayError('You do not have permission to install this module.');
                    } elseif ($key == 'uninstall' && ($this->tabAccess['delete'] !== '1' || !$module->getPermission('configure'))) {
                        $this->errors[] = Tools::displayError('You do not have permission to delete this module.');
                    } elseif ($key == 'configure' && ($this->tabAccess['edit'] !== '1' || !$module->getPermission('configure') || !Module::isInstalled(urldecode($name)))) {
                        $this->errors[] = Tools::displayError('You do not have permission to configure this module.');
                    } elseif ($key == 'install' && Module::isInstalled($module->name)) {
                        $this->errors[] = Tools::displayError('This module is already installed:') . ' ' . $module->name;
                    } elseif ($key == 'uninstall' && !Module::isInstalled($module->name)) {
                        $this->errors[] = Tools::displayError('This module has already been uninstalled:') . ' ' . $module->name;
                    } else {
                        if ($key == 'update' && !Module::isInstalled($module->name)) {
                            $this->errors[] = Tools::displayError('This module need to be installed in order to be updated:') . ' ' . $module->name;
                        } else {
                            // If we install a module, force temporary global context for multishop
                            if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && $method != 'getContent') {
                                Context::getContext()->tmpOldShop = clone Context::getContext()->shop;
                                Context::getContext()->shop = new Shop();
                            }
                            //retrocompatibility
                            if (Tools::getValue('controller') != '') {
                                $_POST['tab'] = Tools::safeOutput(Tools::getValue('controller'));
                            }
                            $echo = '';
                            if ($key != 'update') {
                                // We check if method of module exists
                                if (!method_exists($module, $method)) {
                                    throw new PrestaShopException('Method of module can\'t be found');
                                }
                                // Get the return value of current method
                                $echo = $module->{$method}();
                            }
                            // If the method called is "configure" (getContent method), we show the html code of configure page
                            if ($key == 'configure' && Module::isInstalled($module->name)) {
                                if (isset($module->multishop_context)) {
                                    $this->multishop_context = $module->multishop_context;
                                }
                                $backlink = self::$currentIndex . '&token=' . $this->token . '&tab_module=' . $module->tab . '&module_name=' . $module->name;
                                $hooklink = 'index.php?tab=AdminModulesPositions&token=' . Tools::getAdminTokenLite('AdminModulesPositions') . '&show_modules=' . (int) $module->id;
                                $tradlink = 'index.php?tab=AdminTranslations&token=' . Tools::getAdminTokenLite('AdminTranslations') . '&type=modules&lang=';
                                $toolbar = '<table class="table" cellpadding="0" cellspacing="0" style="margin:auto;text-align:center"><tr>
									<th>' . $this->l('Module') . ' <span style="color: green;">' . $module->name . '</span></th>
									<th><a href="' . $backlink . '" style="padding:5px 10px">' . $this->l('Back') . '</a></th>
									<th><a href="' . $hooklink . '" style="padding:5px 10px">' . $this->l('Manage hooks') . '</a></th>
									<th style="padding:5px 10px">' . $this->l('Manage translations') . ' ';
                                foreach (Language::getLanguages(false) as $language) {
                                    $toolbar .= '<a href="' . $tradlink . $language['iso_code'] . '#' . $module->name . '" style="margin-left:5px"><img src="' . _THEME_LANG_DIR_ . $language['id_lang'] . '.jpg" alt="' . $language['iso_code'] . '" title="' . $language['iso_code'] . '" /></a>';
                                }
                                $toolbar .= '</th></tr>';
                                // Display checkbox in toolbar if multishop
                                if (Shop::isFeatureActive()) {
                                    $activateOnclick = 'onclick="location.href = \'' . $this->getCurrentUrl('enable') . '&enable=\'+(($(this).attr(\'checked\')) ? 1 : 0)"';
                                    $toolbar .= '<tr>
										<th colspan="4">
											<input type="checkbox" name="activateModule" value="1" ' . ($module->active ? 'checked="checked"' : '') . ' ' . $activateOnclick . ' /> ' . $this->l('Activate module for') . ' ';
                                    if (Shop::getContext() == Shop::CONTEXT_SHOP) {
                                        $toolbar .= 'shop <b>' . $this->context->shop->name . '</b>';
                                    } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
                                        $shop_group = new ShopGroup((int) Shop::getContextShopGroupID());
                                        $toolbar .= 'all shops of group shop <b>' . $shop_group->name . '</b>';
                                    } else {
                                        $toolbar .= 'all shops';
                                    }
                                    $toolbar .= '</th>
								</tr>';
                                }
                                $toolbar .= '</table>';
                                if (Shop::isFeatureActive() && isset(Context::getContext()->tmpOldShop)) {
                                    Context::getContext()->shop = clone Context::getContext()->tmpOldShop;
                                    unset(Context::getContext()->tmpOldShop);
                                }
                                // Display module configuration
                                $this->context->smarty->assign('module_content', $toolbar . '<div class="clear">&nbsp;</div>' . $echo . '<div class="clear">&nbsp;</div>' . $toolbar);
                            } elseif ($echo === true) {
                                $return = 13;
                                if ($method == 'install') {
                                    $return = 12;
                                    $installed_modules[] = $module->id;
                                }
                            } elseif ($echo === false) {
                                $module_errors[] = array('name' => $name, 'message' => $module->getErrors());
                            }
                            if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL && isset(Context::getContext()->tmpOldShop)) {
                                Context::getContext()->shop = clone Context::getContext()->tmpOldShop;
                                unset(Context::getContext()->tmpOldShop);
                            }
                        }
                    }
                    if ($key != 'configure' && isset($_GET['bpay'])) {
                        Tools::redirectAdmin('index.php?tab=AdminPayment&token=' . Tools::getAdminToken('AdminPayment' . (int) Tab::getIdFromClassName('AdminPayment') . (int) $this->id_employee));
                    }
                }
            }
            if (count($module_errors)) {
                // If error during module installation, no redirection
                $html_error = $this->generateHtmlMessage($module_errors);
                $this->errors[] = sprintf(Tools::displayError('The following module(s) were not installed properly: %s'), $html_error);
                $this->context->smarty->assign('error_module', 'true');
            }
        }
        if ($return) {
            $params = count($installed_modules) ? '&installed_modules=' . implode('|', $installed_modules) : '';
            // If redirect parameter is present and module installed with success, we redirect on configuration module page
            if (Tools::getValue('redirect') == 'config' && Tools::getValue('module_name') != '' && $return == '12' && Module::isInstalled(pSQL(Tools::getValue('module_name')))) {
                Tools::redirectAdmin('index.php?controller=adminmodules&configure=' . Tools::getValue('module_name') . '&token=' . Tools::getValue('token') . '&module_name=' . Tools::getValue('module_name') . $params);
            }
            Tools::redirectAdmin(self::$currentIndex . '&conf=' . $return . '&token=' . $this->token . '&tab_module=' . $module->tab . '&module_name=' . $module->name . '&anchor=anchor' . ucfirst($module->name) . (isset($modules_list_save) ? '&modules_list=' . $modules_list_save : '') . $params);
        }
    }
 /**
  * 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_;
     // test writable recursively
     if (ConfigurationTest::test_dir($this->prodRootDir, true)) {
         $this->rootWritable = true;
     }
     // checkPSVersion will be not
     $this->upgrader = new Upgrader(true);
     $this->upgrader->checkPSVersion();
     // If you have defined this somewhere, you know what you do
     if (defined('_PS_ALLOW_UPGRADE_UNSTABLE_') and _PS_ALLOW_UPGRADE_UNSTABLE_ and function_exists('svn_checkout')) {
         $this->useSvn = Configuration::get('PS_AUTOUP_USE_SVN');
     } else {
         $this->useSvn = false;
     }
     // from $_POST or $_GET
     $this->action = Tools::getValue('action');
     $this->currentParams = Tools::getValue('params');
     // If not exists in this sessions, "create"
     // session handling : from current to next params
     if (isset($this->currentParams['removeList'])) {
         $this->nextParams['removeList'] = $this->currentParams['removeList'];
     }
     if (isset($this->currentParams['filesToUpgrade'])) {
         $this->nextParams['filesToUpgrade'] = $this->currentParams['filesToUpgrade'];
     }
     $this->backupDbFilename = Configuration::get('UPGRADER_BACKUPDB_FILENAME');
     if (!file_exists($this->backupDbFilename)) {
         $this->backupDbFilename = '';
         Configuration::updateValue('UPGRADER_BACKUPDB_FILENAME', '');
     }
     $this->backupFilesFilename = Configuration::get('UPGRADER_BACKUPFILES_FILENAME');
     if (!file_exists($this->backupFilesFilename)) {
         $this->backupFilesFilename = '';
         Configuration::updateValue('UPGRADER_BACKUPFILES_FILENAME', '');
     }
     $this->autoupgradePath = $this->adminDir . DIRECTORY_SEPARATOR . $this->autoupgradeDir;
     if (!file_exists($this->autoupgradePath)) {
         if (!@mkdir($this->autoupgradePath, 0777)) {
             $this->_errors[] = Tools::displayError(sprintf($this->l('unable to create directory %s'), $this->autoupgradePath));
         }
     }
     $latest = $this->autoupgradePath . DIRECTORY_SEPARATOR . 'latest';
     if (!file_exists($latest)) {
         if (!@mkdir($latest, 0777)) {
             $this->_errors[] = Tools::displayError(sprintf($this->l('unable to create directory %s'), $latest));
         }
     }
     $this->latestRootDir = $latest . DIRECTORY_SEPARATOR . 'prestashop';
     $this->adminDir = str_replace($this->prodRootDir, '', $this->adminDir);
     // @TODO future option
     //	$this->testRootDir = $this->autoupgradePath.DIRECTORY_SEPARATOR.'test';
     /* optional skips */
     $this->dontBackupImages = Configuration::get('PS_AUTOUP_DONT_SAVE_IMAGES');
     $this->keepDefaultTheme = Configuration::get('PS_AUTOUP_KEEP_DEFAULT_THEME');
     $this->keepTrad = Configuration::get('PS_AUTOUP_KEEP_TRAD');
     $this->manualMode = Configuration::get('PS_AUTOUP_MANUAL_MODE');
     // We can add any file or directory in the exclude dir : theses files will be not removed or overwritten
     // @TODO cache should be ignored recursively, but we have to reconstruct it after upgrade
     // - compiled from smarty
     // - .svn
     $this->backupIgnoreAbsoluteFiles[] = "/tools/smarty_v2/compile";
     $this->backupIgnoreAbsoluteFiles[] = "/tools/smarty_v2/cache";
     $this->backupIgnoreAbsoluteFiles[] = "/tools/smarty/compile";
     $this->backupIgnoreAbsoluteFiles[] = "/tools/smarty/cache";
     $this->excludeFilesFromUpgrade[] = '.';
     $this->excludeFilesFromUpgrade[] = '..';
     $this->excludeFilesFromUpgrade[] = '.svn';
     $this->excludeFilesFromUpgrade[] = 'install';
     $this->excludeFilesFromUpgrade[] = 'settings.inc.php';
     $this->excludeFilesFromUpgrade[] = 'autoupgrade';
     $this->backupIgnoreFiles[] = '.';
     $this->backupIgnoreFiles[] = '..';
     $this->backupIgnoreFiles[] = '.svn';
     $this->backupIgnoreFiles[] = 'autoupgrade';
     if ($this->dontBackupImages) {
         $this->backupIgnoreAbsoluteFiles[] = "/img";
     }
     if ($this->keepDefaultTheme) {
         $this->excludeAbsoluteFilesFromUpgrade[] = "/themes/prestashop";
     }
     if ($this->keepTrad) {
         $this->excludeFilesFromUpgrade[] = "translations";
     }
 }
    /** this returns fieldset containing the configuration points you need to use autoupgrade
     * @return string
     */
    private function _displayCurrentConfiguration()
    {
        $current_ps_config = $this->getcheckCurrentPsConfig();
        $this->_html .= '<div class="bootstrap" id="currentConfigurationBlock">
            <div class="panel">
                <div class="panel-heading">
                  ' . $this->l('The pre-Upgrade checklist') . '
                </div>';
        if (!$this->configOk()) {
            $this->_html .= '<p class="alert alert-warning">' . $this->l('The checklist is not OK. You can only upgrade your shop once all indicators are green.') . '</p>';
        }
        $this->_html .= '<div id="currentConfiguration">
							<p class="alert alert-info">' . $this->l('Before starting the upgrade process, please make sure this checklist is all green.') . '</p>';
        $pic_ok = '<img src="../img/admin/enabled.gif" alt="ok"/>';
        $pic_nok = '<img src="../img/admin/disabled.gif" alt="nok"/>';
        $pic_warn = '<img src="../img/admin/warning.gif" alt="warn"/>';
        // module version : checkAutoupgradeLastVersion
        $this->_html .= '<table class="table" cellpadding="0" cellspacing="0">
				<tr>
					<td>' . sprintf($this->l('The 1-click upgrade module is up-to-date (your current version is v%s)'), $this->getModuleVersion()) . '
					' . ($current_ps_config['module_version_ok'] ? '' : '&nbsp;&nbsp;' . (version_compare(_PS_VERSION_, '1.5.3.0', '>') ? '<strong><a href="index.php?controller=AdminModules&amp;token=' . Tools14::getAdminTokenLite('AdminModules') . '&update=autoupgrade">' . $this->l('Update') . '</a></strong> - ' : '') . '<strong><a class="_blank" href="http://addons.prestashop.com/en/administration-tools-prestashop-modules/5496-1-click-upgrade-autoupgrade.html">' . $this->l('Download') . '</a><strong> ') . '
					</td>
					<td>' . ($current_ps_config['module_version_ok'] ? $pic_ok : $pic_nok) . '</td>
				</tr>';
        // root : getRootWritable()
        $this->_html .= '
			<tr>
				<td>' . $this->l('Your store\'s root directory is writable (with appropriate CHMOD permissions)') . '</td>
				<td>' . ($current_ps_config['root_writable'] ? $pic_ok : $pic_nok . ' ' . $this->root_writable_report) . '</td>
			</tr>';
        $admin_dir = trim(str_replace($this->prodRootDir, '', $this->adminDir), DIRECTORY_SEPARATOR);
        $report = '';
        ConfigurationTest::test_dir($admin_dir . DIRECTORY_SEPARATOR . $this->autoupgradeDir, true, $report);
        if ($report) {
            $this->_html .= '
				<tr>
					<td>' . $this->l('The "/admin/autoupgrade" directory is writable (appropriate CHMOD permissions)') . '</td>
					<td>' . ($current_ps_config['admin_au_writable'] ? $pic_ok : $pic_nok . ' ' . $report) . '</td>
				</tr>';
        }
        //check safe_mod
        if (!($safe_mode = @ini_get('safe_mode'))) {
            $safe_mode = '';
        }
        $safe_mode = in_array(Tools14::strtolower($safe_mode), array(1, 'on'));
        $this->_html .= '
			<tr><td>' . $this->l('PHP\'s "Safe mode" option is turned off') . '</td>
			<td>' . (!$safe_mode ? $pic_ok : $pic_warn) . '</td></tr>';
        $this->_html .= '
			<tr><td>' . $this->l('PHP\'s "allow_url_fopen" option is turned on, or cURL is installed') . '</td>
			<td>' . (ConfigurationTest::test_fopen() || ConfigurationTest::test_curl() ? $pic_ok : $pic_nok) . '</td></tr>';
        // shop enabled
        $this->_html .= '
			<tr><td>' . $this->l('Your store is in maintenance mode') . ' ' . (!$current_ps_config['shop_deactivated'] ? '<br><form method="post" action="' . $this->currentIndex . '&token=' . $this->token . '"><input type="submit" class="button" name="putUnderMaintenance" value="' . $this->l('Click here to put your shop under maintenance') . '"></form>' : '') . '</td>
			<td>' . ($current_ps_config['shop_deactivated'] ? $pic_ok : $pic_nok) . '</td></tr>';
        $this->_html .= '
			<tr><td>' . $this->l('PrestaShop\'s caching features are disabled') . '</td>
			<td>' . ($current_ps_config['cache_deactivated'] ? $pic_ok : $pic_nok) . '</td></tr>';
        // for informaiton, display time limit
        $max_exec_time = ini_get('max_execution_time');
        $this->_html .= '
			<tr><td>' . sprintf($this->l('PHP\'s max_execution_time setting has a high value or is disabled entirely (current value: %s)'), $max_exec_time == 0 ? $this->l('unlimited') : sprintf($this->l('%s seconds'), $max_exec_time)) . '</td>
			<td>' . ($max_exec_time == 0 ? $pic_ok : $pic_warn) . '</td></tr>
        </table>
        <br/>
        <p class="alert alert-info">' . $this->l('Please also make sure you make a full manual backup of your files and database.') . '</p>
        </div>
        </div>
		</div>';
    }
 /**
  * download PrestaShop archive according to the chosen channel
  *
  * @access public
  */
 public function ajaxProcessDownload()
 {
     if (ConfigurationTest::test_fopen() || ConfigurationTest::test_curl()) {
         if (!is_object($this->upgrader)) {
             $this->upgrader = new Upgrader();
         }
         // regex optimization
         preg_match('#([0-9]+\\.[0-9]+)(?:\\.[0-9]+){1,2}#', _PS_VERSION_, $matches);
         $this->upgrader->channel = $this->getConfig('channel');
         $this->upgrader->branch = $matches[1];
         if ($this->getConfig('channel') == 'private' && !$this->getConfig('private_allow_major')) {
             $this->upgrader->checkPSVersion(false, array('private', 'minor'));
         } else {
             $this->upgrader->checkPSVersion(false, array('minor'));
         }
         if ($this->upgrader->channel == 'private') {
             $this->upgrader->link = $this->getConfig('private_release_link');
             $this->upgrader->md5 = $this->getConfig('private_release_md5');
         }
         $this->nextQuickInfo[] = sprintf($this->l('downloading from %s'), $this->upgrader->link);
         $this->nextQuickInfo[] = sprintf($this->l('file will be saved in %s'), $this->getFilePath());
         if (file_exists($this->downloadPath)) {
             self::deleteDirectory($this->downloadPath, false);
             $this->nextQuickInfo[] = $this->l('download directory has been emptied');
         }
         $report = '';
         $relative_download_path = str_replace(_PS_ROOT_DIR_, '', $this->downloadPath);
         if (ConfigurationTest::test_dir($relative_download_path, false, $report)) {
             $res = $this->upgrader->downloadLast($this->downloadPath, $this->destDownloadFilename);
             if ($res) {
                 $md5file = md5_file(realpath($this->downloadPath) . DIRECTORY_SEPARATOR . $this->destDownloadFilename);
                 if ($md5file == $this->upgrader->md5) {
                     $this->nextQuickInfo[] = $this->l('Download complete.');
                     $this->next = 'unzip';
                     $this->next_desc = $this->l('Download complete. Now extracting');
                 } else {
                     $this->nextQuickInfo[] = sprintf($this->l('Download complete but md5sum does not match (%s)'), $md5file);
                     $this->nextErrors[] = sprintf($this->l('Download complete but md5sum does not match (%s)'), $md5file);
                     $this->next = 'error';
                     $this->next_desc = $this->l('Download complete but md5sum does not match. Operation aborted.');
                 }
             } else {
                 if ($this->upgrader->channel == 'private') {
                     $this->next_desc = $this->l('Error during download. The private key may be incorrect.');
                     $this->nextQuickInfo[] = $this->l('Error during download. The private key may be incorrect.');
                     $this->nextErrors[] = $this->l('Error during download. The private key may be incorrect.');
                 } else {
                     $this->next_desc = $this->l('Error during download');
                     $this->nextQuickInfo[] = $this->l('Error during download');
                     $this->nextErrors[] = $this->l('Error during download');
                 }
                 $this->next = 'error';
             }
         } else {
             $this->next_desc = $this->l('Download directory is not writeable ');
             $this->nextQuickInfo[] = $this->l('Download directory is not writeable ');
             $this->nextErrors[] = $this->l('Download directory is not writeable ') . $this->downloadPath;
             $this->next = 'error';
         }
     } else {
         $this->nextQuickInfo[] = $this->l('you need allow_url_fopen or CURL for automatic download.');
         $this->nextErrors[] = $this->l('you need allow_url_fopen or CURL for automatic download.');
         $this->next = 'error';
         $this->next_desc = sprintf($this->l('you need allow_url_fopen or CURL for automatic download. You can also manually upload it in %s'), $this->getFilePath());
     }
 }
 /**
  * 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_;
     // from $_POST or $_GET
     $this->action = empty($_REQUEST['action']) ? null : $_REQUEST['action'];
     $this->currentParams = empty($_REQUEST['params']) ? null : $_REQUEST['params'];
     // test writable recursively
     if (version_compare(_PS_VERSION_, '1.4.5.0', '<')) {
         require_once 'ConfigurationTest.php';
         if (!class_exists('ConfigurationTest', false) and class_exists('ConfigurationTestCore')) {
             eval('class ConfigurationTest extends ConfigurationTestCore{}');
         }
     }
     if (ConfigurationTest::test_dir($this->prodRootDir, true)) {
         $this->rootWritable = true;
     }
     if (!in_array($this->action, array('upgradeFile', 'upgradeDb', 'upgradeComplete', 'rollback', 'restoreFiles', 'restoreDb'))) {
         // checkPSVersion will be not
         $this->upgrader = new Upgrader();
         $this->upgrader->checkPSVersion();
         $this->nextParams['install_version'] = $this->upgrader->version_num;
         if ($this->upgrader->autoupgrade_module) {
             $this->standalone = true;
         } else {
             $this->standalone = false;
         }
         $this->standalone = true;
     }
     // If you have defined this somewhere, you know what you do
     if (defined('_PS_ALLOW_UPGRADE_UNSTABLE_') and _PS_ALLOW_UPGRADE_UNSTABLE_ and function_exists('svn_checkout')) {
         if (version_compare(_PS_VERSION_, '1.4.5.0', '<') or class_exists('Configuration', false)) {
             $this->useSvn = Configuration::get('PS_AUTOUP_USE_SVN');
         }
     } else {
         $this->useSvn = false;
     }
     // If not exists in this sessions, "create"
     // session handling : from current to next params
     if (isset($this->currentParams['removeList'])) {
         $this->nextParams['removeList'] = $this->currentParams['removeList'];
     }
     if (isset($this->currentParams['filesToUpgrade'])) {
         $this->nextParams['filesToUpgrade'] = $this->currentParams['filesToUpgrade'];
     }
     // set autoupgradePath, to be used in backupFiles and backupDb config values
     $this->autoupgradePath = $this->adminDir . DIRECTORY_SEPARATOR . $this->autoupgradeDir;
     if (!file_exists($this->autoupgradePath)) {
         if (!@mkdir($this->autoupgradePath, 0777)) {
             $this->_errors[] = Tools::displayError(sprintf($this->l('unable to create directory %s'), $this->autoupgradePath));
         }
     }
     $latest = $this->autoupgradePath . DIRECTORY_SEPARATOR . 'latest';
     if (!file_exists($latest)) {
         if (!@mkdir($latest, 0777)) {
             $this->_errors[] = Tools::displayError(sprintf($this->l('unable to create directory %s'), $latest));
         }
     }
     if (class_exists('Configuration', false)) {
         $time = time();
         $this->backupDbFilename = Configuration::get('UPGRADER_BACKUPDB_FILENAME');
         if (!file_exists($this->backupDbFilename)) {
             // If not exists, the filename is generated by Backup.php
             $this->backupDbFilename = '';
             Configuration::updateValue('UPGRADER_BACKUPDB_FILENAME', $this->backupDbFilename);
         }
         $this->backupFilesFilename = Configuration::get('UPGRADER_BACKUPFILES_FILENAME');
         if (!file_exists($this->backupFilesFilename)) {
             $this->backupFilesFilename = $this->autoupgradePath . DIRECTORY_SEPARATOR . 'backupfile-' . date('Y-m-d') . '-' . $time . '.zip';
             Configuration::updateValue('UPGRADER_BACKUPFILES_FILENAME', $this->backupFilesFilename);
         }
     } else {
         // backupDbFilename should never be empty
         $this->backupDbFilename = $this->currentParams['backupDbFilename'];
         // backupFilesFilename should never etc.
         $this->backupFilesFilename = $this->currentParams['backupFilesFilename'];
     }
     $this->latestRootDir = $latest . DIRECTORY_SEPARATOR . 'prestashop';
     $this->adminDir = str_replace($this->prodRootDir, '', $this->adminDir);
     // @TODO future option "install in test dir"
     //	$this->testRootDir = $this->autoupgradePath.DIRECTORY_SEPARATOR.'test';
     /* option */
     if (class_exists('Configuration', false)) {
         $this->dontBackupImages = !Configuration::get('PS_AUTOUP_DONT_SAVE_IMAGES');
         $this->keepDefaultTheme = Configuration::get('PS_AUTOUP_KEEP_DEFAULT_THEME');
         $this->keepTrad = Configuration::get('PS_AUTOUP_KEEP_TRAD');
         $this->manualMode = Configuration::get('PS_AUTOUP_MANUAL_MODE');
         $this->desactivateCustomModule = Configuration::get('PS_AUTOUP_CUSTOM_MOD_DESACT');
     } else {
         $this->dontBackupImages = $this->currentParams['dontBackupImages'];
         $this->keepDefaultTheme = $this->currentParams['keepDefaultTheme'];
         $this->keepTrad = $this->currentParams['keepTrad'];
         $this->manualMode = $this->currentParams['manualMode'];
         $this->desactivateCustomModule = $this->currentParams['desactivateCustomModule'];
     }
     // We can add any file or directory in the exclude dir : theses files will be not removed or overwritten
     // @TODO cache should be ignored recursively, but we have to reconstruct it after upgrade
     // - compiled from smarty
     // - .svn
     $this->backupIgnoreAbsoluteFiles[] = "/tools/smarty_v2/compile";
     $this->backupIgnoreAbsoluteFiles[] = "/tools/smarty_v2/cache";
     $this->backupIgnoreAbsoluteFiles[] = "/tools/smarty/compile";
     $this->backupIgnoreAbsoluteFiles[] = "/tools/smarty/cache";
     $this->excludeFilesFromUpgrade[] = '.';
     $this->excludeFilesFromUpgrade[] = '..';
     $this->excludeFilesFromUpgrade[] = '.svn';
     $this->excludeFilesFromUpgrade[] = 'install';
     $this->excludeFilesFromUpgrade[] = 'settings.inc.php';
     // this will exclude autoupgrade dir from admin, and autoupgrade from modules
     $this->excludeFilesFromUpgrade[] = 'autoupgrade';
     $this->backupIgnoreFiles[] = '.';
     $this->backupIgnoreFiles[] = '..';
     $this->backupIgnoreFiles[] = '.svn';
     $this->backupIgnoreFiles[] = 'autoupgrade';
     if ($this->dontBackupImages) {
         $this->backupIgnoreAbsoluteFiles[] = "/img";
     }
     if ($this->keepDefaultTheme) {
         $this->excludeAbsoluteFilesFromUpgrade[] = "/themes/prestashop";
     }
     if ($this->keepTrad) {
         $this->excludeFilesFromUpgrade[] = "translations";
     }
 }
 public function getRootWritable()
 {
     // test if prodRootDir is writable recursively
     if (ConfigurationTest::test_dir($this->prodRootDir, true)) {
         $this->root_writable = true;
     }
     return $this->root_writable;
 }