/** * Third step: install downloaded upgrades * * @return void */ protected function doActionInstallUpgrades() { $this->setReturnURL($this->buildURL('upgrade')); if (\XLite\Upgrade\Cell::getInstance()->isUnpacked()) { \Includes\SafeMode::sendNotification(); $restorePoint = \Includes\Utils\ModulesManager::getEmptyRestorePoint(); //write current state $current = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->findBy(array('enabled' => true)); foreach ($current as $module) { $restorePoint['current'][$module->getModuleId()] = $module->getActualName(); } \Includes\Utils\Operator::showMessage('Installing updates, please wait...'); if (\XLite\Core\Request::getInstance()->preUpgradeWarningModules) { \XLite\Upgrade\Cell::getInstance()->setPreUpgradeWarningModules(array_keys(array_filter(\XLite\Core\Request::getInstance()->preUpgradeWarningModules, function ($value) { return 0 == $value; }))); } // Disable selected modules $modules = array(); foreach (\XLite\Upgrade\Cell::getInstance()->getIncompatibleModules(true) as $module) { $module->setEnabled(false); $modules[] = $module; $restorePoint['disabled'][$module->getModuleId()] = $module->getActualName(); } \XLite\Core\Database::getRepo('XLite\\Model\\Module')->updateInBatch($modules); // Do actions according the admin choice for the disabled modules with hooks $modulesToEnable = array(); /** @var \XLite\Model\Module $module */ foreach (\XLite\Upgrade\Cell::getInstance()->getDisabledModulesHooks() as $marketplaceId => $module) { $action = \XLite\Core\Request::getInstance()->disabledModulesHooks[$marketplaceId]; $module = \XLite\Core\Database::getEM()->merge($module); if (1 == $action) { // Enable module $module->setEnabled(true); $modulesToEnable[] = $module; $restorePoint['enabled'][$module->getModuleId()] = $module->getActualName(); } elseif (0 == $action) { // Uninstall module \XLite\Upgrade\Cell::getInstance()->removeModuleEntry($module); $this->uninstallModule($module); $restorePoint['deleted'][] = $module->getActualName(); } } \XLite\Core\Database::getRepo('XLite\\Model\\Module')->updateInBatch($modulesToEnable); if (\XLite\Upgrade\Cell::getInstance()->getEntries()) { foreach (\XLite\Upgrade\Cell::getInstance()->getEntries() as $module) { $restorePoint['installed'][] = $module->getActualName(); } // Perform upgrade // pre_upgrade / post_upgrade hooks will be proceeded here $this->runStep('upgrade', array(false, $this->getFilesToOverWrite())); if ($this->isForce()) { if ($this->isNextStepAvailable()) { $target = 'installed'; $this->showInfo(null, 1 < count($modules) ? static::t('Modules have been successfully installed') : static::t('Module has been successfully installed')); if ($this->isOnlySkins()) { $target = 'layout'; } elseif ($this->getPaymentMethodToInstall()) { $target = 'payment_settings'; } else { $target = 'addons_list_installed'; } } else { $target = 'addons_list_marketplace'; $this->showError(__FUNCTION__); } $this->setReturnURL($this->buildURL('upgrade', '', $this->getActionParamsCommon() + array('redirect' => $target))); } } else { // All modules for upgrade were set for uninstallation // There are no upgrade procedures to perform \XLite\Core\Marketplace::getInstance()->clearActionCache(); $this->setReturnURL($this->buildURL('addons_list_installed')); } // Set cell status \XLite\Upgrade\Cell::getInstance()->clear(true, false, false); \XLite\Upgrade\Cell::getInstance()->setUpgraded(true); \Includes\Utils\ModulesManager::updateModuleMigrationLog($restorePoint); // Rebuild cache if (!($this->isForce() && $this->isOnlySkins())) { \XLite::setCleanUpCacheFlag(true); } } else { $this->showWarning(__FUNCTION__, static::t('unable to install: not all archives were unpacked. Please, try again', array('list' => $this->getErrorEntriesHTML()))); } }
/** * Third step: install downloaded upgrades * * @return void */ protected function doActionInstallUpgrades() { $this->setReturnURL($this->buildURL('upgrade')); if (\XLite\Upgrade\Cell::getInstance()->isUnpacked()) { if (!$this->isForce()) { \Includes\SafeMode::sendNotification(); } $restorePoint = \Includes\Utils\ModulesManager::getEmptyRestorePoint(); //write current state $current = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->findBy(array('enabled' => true)); foreach ($current as $module) { $restorePoint['current'][$module->getModuleId()] = $module->getActualName(); } \Includes\Utils\Operator::showMessage('Installing updates, please wait...'); if (\XLite\Core\Request::getInstance()->preUpgradeWarningModules) { \XLite\Upgrade\Cell::getInstance()->setPreUpgradeWarningModules(array_keys(array_filter(\XLite\Core\Request::getInstance()->preUpgradeWarningModules, function ($value) { return 0 == $value; }))); } // Disable selected modules $modules = array(); foreach (\XLite\Upgrade\Cell::getInstance()->getIncompatibleModules(true) as $module) { $module->setEnabled(false); $modules[] = $module; $restorePoint['disabled'][$module->getModuleId()] = $module->getActualName(); } \XLite\Core\Database::getRepo('XLite\\Model\\Module')->updateInBatch($modules); // Do actions according the admin choice for the disabled modules with hooks $modulesToEnable = array(); /** @var \XLite\Model\Module $module */ foreach (\XLite\Upgrade\Cell::getInstance()->getDisabledModulesHooks() as $marketplaceId => $module) { $action = \XLite\Core\Request::getInstance()->disabledModulesHooks[$marketplaceId]; $module = \XLite\Core\Database::getEM()->merge($module); if (1 == $action) { // Enable module $module->setEnabled(true); $modulesToEnable[] = $module; $restorePoint['enabled'][$module->getModuleId()] = $module->getActualName(); } elseif (0 == $action) { // Uninstall module \XLite\Upgrade\Cell::getInstance()->removeModuleEntry($module); $this->uninstallModule($module); $restorePoint['deleted'][] = $module->getActualName(); } } \XLite\Core\Database::getRepo('XLite\\Model\\Module')->updateInBatch($modulesToEnable); if (\XLite\Upgrade\Cell::getInstance()->getEntries()) { foreach (\XLite\Upgrade\Cell::getInstance()->getEntries() as $module) { $restorePoint['installed'][] = $module->getActualName(); } \XLite\Upgrade\Cell::getInstance()->initUpgradeHooks(); $this->setReturnURL($this->buildURL('upgrade', 'pre_upgrade_hooks', $this->getActionParamsCommon())); } else { // All modules for upgrade were set for uninstallation // There are no upgrade procedures to perform \XLite\Core\Marketplace::getInstance()->clearActionCache(); $this->setReturnURL($this->buildURL('addons_list_installed')); } \Includes\Utils\ModulesManager::updateModuleMigrationLog($restorePoint); } else { $this->showWarning(__FUNCTION__, static::t('unable to install: not all archives were unpacked. Please, try again', array('list' => $this->getErrorEntriesHTML()))); } }
/** * Switch module * * @return void */ public function doActionSwitch() { $changed = false; $deleted = false; $data = (array) \XLite\Core\Request::getInstance()->switch; $modules = array(); $firstModule = null; $switchModules = $this->getModules('switch'); $switchModulesKeys = array(); $excludedModules = array(); $excludedEnableModules = array(); $restorePoint = \Includes\Utils\ModulesManager::getEmptyRestorePoint(); $current = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->findBy(array('enabled' => true)); foreach ($current as $module) { $restorePoint['current'][$module->getModuleId()] = $module->getActualName(); } // Correct modules list foreach ($switchModules as $key => $module) { $toDelete = false; $toDisable = false; $toEnable = false; $switchModulesKeys[] = $module->getModuleId(); if (!empty($data[$module->getModuleId()]['delete'])) { $toDelete = true; } else { $old = !empty($data[$module->getModuleId()]['old']); $new = !empty($data[$module->getModuleId()]['new']); $toDisable = !$new && $old != $new; $toEnable = $new && $old != $new; } if ($toDelete || $toDisable) { $dependentModules = $module->getDependentModules(); if ($dependentModules) { foreach ($dependentModules as $dep) { $depModule = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->getModuleInstalled($dep); if ($depModule) { $depDelete = !empty($data[$depModule->getModuleId()]['delete']); $depDisable = empty($data[$depModule->getModuleId()]['new']); if ($toDelete && !$depDelete || $toDisable && !$depDelete && !$depDisable) { // Remove current module from the actions list if it has active dependent modules $excludedModules[] = $module->getModuleName(); unset($data[$module->getModuleId()]); unset($switchModules[$key]); break; } } } } } elseif ($toEnable) { // Get the list of modules which current module depends on $list = $this->getAllDisabledModuleDependencies($module); if ($list) { foreach ($list as $m) { if (empty($data[$m->getModuleId()]) || empty($data[$m->getModuleId()]['delete']) && empty($data[$m->getModuleId()]['new'])) { $data[$m->getModuleId()] = array('old' => 0, 'new' => 1); $additionalSwitchModules[$m->getModuleId()] = $m; } } } elseif (false === $list) { // Remove current module from the actions list as it can't be enabled $excludedEnableModules[] = $module->getModuleName(); unset($data[$module->getModuleId()]); } } } if ($excludedModules) { \XLite\Core\TopMessage::addWarning('The following selected modules cannot be disabled or uninstalled as they have dependent modules', array('list' => implode(', ', $excludedModules))); // Selection has excluded modules - this is a critical case, break an entire operation return; } if ($excludedEnableModules) { \XLite\Core\TopMessage::addWarning('The following selected modules cannot be enabled as they depend on disabled modules which cannot be enabled', array('list' => implode(', ', $excludedEnableModules))); // Selection has excluded modules - this is a critical case, break an entire operation return; } if (!empty($additionalSwitchModules)) { // Extend $switchModules list by additional modules foreach ($additionalSwitchModules as $k => $am) { if (!in_array($k, $switchModulesKeys)) { $switchModules[] = $am; } } } foreach ($switchModules as $module) { if (!empty($data[$module->getModuleId()]['delete'])) { $old = $new = null; $delete = true; } else { $old = !empty($data[$module->getModuleId()]['old']); $new = !empty($data[$module->getModuleId()]['new']); $delete = false; } if ($delete) { // Uninstall module if ($module->getEnabled()) { $module->setEnabled(false); $module->callModuleMethod('callDisableEvent'); } if (!defined('LC_MODULE_CONTROL')) { define('LC_MODULE_CONTROL', true); } if ($this->uninstallModule($module)) { $deleted = true; $restorePoint['deleted'][] = $module->getActualName(); } } elseif ($old !== $new) { // Change module status $module->setEnabled($new); // Call disable event to make some module specific changes if ($old) { $module->callModuleMethod('callDisableEvent'); } elseif (is_null($firstModule)) { $firstModule = $module; } if ($new) { $restorePoint['enabled'][$module->getModuleId()] = $module->getActualName(); } else { $restorePoint['disabled'][$module->getModuleId()] = $module->getActualName(); } $modules[] = $module; $changed = true; } } // Flag to rebuild cache if ($changed) { // We redirect the admin to the modules page on the activated module anchor // The first module in a batch which is available now \XLite\Core\Session::getInstance()->returnURL = $firstModule ? $this->getModulePageURL($firstModule) : (\XLite\Core\Request::getInstance()->return ?: ''); \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->updateInBatch($modules); } if ($deleted) { // Refresh marketplace modules cache \XLite\Core\Marketplace::getInstance()->saveAddonsList(0); \XLite\Core\Marketplace::getInstance()->clearActionCache(\XLite\Core\Marketplace::ACTION_CHECK_FOR_UPDATES); } if ($changed || $deleted) { // Flag to rebuild classes cache \XLite::setCleanUpCacheFlag(true); } \Includes\Utils\ModulesManager::updateModuleMigrationLog($restorePoint); }