From 7b936305954e3b570b66bfdea19abbfdfa2f6e34 Mon Sep 17 00:00:00 2001 From: vAugagneur Date: Fri, 29 Mar 2013 11:27:27 +0100 Subject: [PATCH] //added new step in installer to install addons module --- install-dev/controllers/http/process.php | 30 ++++++++++++++++++++-- install-dev/models/install.php | 32 ++++++++++++++++++------ 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/install-dev/controllers/http/process.php b/install-dev/controllers/http/process.php index ff63be1f0..58bbed13c 100644 --- a/install-dev/controllers/http/process.php +++ b/install-dev/controllers/http/process.php @@ -95,7 +95,9 @@ class InstallControllerHttpProcess extends InstallControllerHttp $this->processConfigureShop(); elseif (Tools::getValue('installModules') && !empty($this->session->process_validated['configureShop'])) $this->processInstallModules(); - elseif (Tools::getValue('installFixtures') && !empty($this->session->process_validated['installModules'])) + elseif (Tools::getValue('installModulesAddons') && !empty($this->session->process_validated['installModules'])) + $this->processInstallAddonsModules(); + elseif (Tools::getValue('installFixtures') && !empty($this->session->process_validated['installModulesAddons'])) $this->processInstallFixtures(); elseif (Tools::getValue('installTheme') && !empty($this->session->process_validated['installModules'])) $this->processInstallTheme(); @@ -231,6 +233,23 @@ class InstallControllerHttpProcess extends InstallControllerHttp $this->session->process_validated = array_merge($this->session->process_validated, array('installModules' => true)); $this->ajaxJsonAnswer(true); } + + /** + * PROCESS : installModulesAddons + * Install modules from addons + */ + public function processInstallAddonsModules() + { + $this->initializeContext(); + if ($module = Tools::getValue('module') && $id_module = Tools::getValue('id_module')) + $result = $this->model_install->installModulesAddons(array('name' => $module, 'id_module' => $id_module)); + else + $result = $this->model_install->installModulesAddons(); + if (!$result || $this->model_install->getErrors()) + $this->ajaxJsonAnswer(false, $this->model_install->getErrors()); + $this->session->process_validated = array_merge($this->session->process_validated, array('installModulesAddons' => true)); + $this->ajaxJsonAnswer(true); + } /** * PROCESS : installFixtures @@ -312,6 +331,8 @@ class InstallControllerHttpProcess extends InstallControllerHttp */ public function display() { + $this->initializeContext(); + // The installer SHOULD take less than 32M, but may take up to 35/36M sometimes. So 42M is a good value :) $low_memory = Tools::getMemoryLimit() < Tools::getOctets('42M'); @@ -333,12 +354,17 @@ class InstallControllerHttpProcess extends InstallControllerHttp $this->process_steps[] = $populate_step; $this->process_steps[] = array('key' => 'configureShop', 'lang' => $this->l('Configure shop information')); - $install_modules = array('key' => 'installModules', 'lang' => $this->l('Install modules')); if ($low_memory) foreach ($this->model_install->getModulesList() as $module) $install_modules['subtasks'][] = array('module' => $module); $this->process_steps[] = $install_modules; + + $install_modules = array('key' => 'installModulesAddons', 'lang' => $this->l('Install modules Addons')); + if ($low_memory) + foreach ($this->model_install->getAddonsModulesList() as $module) + $install_modules['subtasks'][] = array('module' => (string)$module['name'], 'id_module' => (string)$module['id_module']); + $this->process_steps[] = $install_modules; // Fixtures are installed only if option is selected if ($this->session->install_type == 'full') diff --git a/install-dev/models/install.php b/install-dev/models/install.php index 2d60d8ad6..4b5ad2211 100644 --- a/install-dev/models/install.php +++ b/install-dev/models/install.php @@ -585,7 +585,6 @@ class InstallModelInstall extends InstallAbstractModel 'statsvisits', ); } - return $modules; } @@ -602,18 +601,16 @@ class InstallModelInstall extends InstallAbstractModel return $addons_modules; } - /** * PROCESS : installModules * Download module from addons and Install all modules in ~/modules/ directory */ - public function installModules($module = null) + public function installModulesAddons($module = null) { - $modules = $module ? array($module) : $this->getModulesList(); + $addons_modules = $module ? array($module) : $this->getAddonsModulesList(); + $modules = array(); if (!InstallSession::getInstance()->safe_mode) { - $addons_modules = $this->getAddonsModulesList(); - foreach($addons_modules as $addons_module) if (file_put_contents(_PS_MODULE_DIR_.$addons_module['name'].'.zip', Tools::addonsRequest('module', array('id_module' => $addons_module['id_module'])))) if (Tools::ZipExtract(_PS_MODULE_DIR_.$addons_module['name'].'.zip', _PS_MODULE_DIR_)) @@ -622,6 +619,27 @@ class InstallModelInstall extends InstallAbstractModel unlink(_PS_MODULE_DIR_.$addons_module['name'].'.zip'); } } + $errors = array(); + foreach ($modules as $module_name) + if (!$this->installModules($module_name)) + $errors[] = $this->language->l('Cannot install module "%s"', $module_name); + + if ($errors) + { + $this->setError($errors); + return false; + } + return true; + } + + /** + * PROCESS : installModules + * Download module from addons and Install all modules in ~/modules/ directory + */ + public function installModules($module = null) + { + $modules = $module ? array($module) : $this->getModulesList(); + $errors = array(); foreach ($modules as $module_name) { @@ -634,7 +652,7 @@ class InstallModelInstall extends InstallAbstractModel } if ($errors) - { + { $this->setError($errors); return false; }