/** * Execute certain hook handle * * @return void */ public function executeHookHandler() { if (\XLite\Upgrade\Cell::getInstance()->isUpgraded()) { $entries = \XLite\Upgrade\Cell::getInstance()->getEntries(); if ($entries) { \Includes\Utils\Operator::showMessage('', true, false); /** @var \XLite\Upgrade\Entry\AEntry $entry */ foreach ($entries as $entry) { if (!$entry->isPostUpgradeActionsCalled()) { $message = '...Invoke actions for ' . $entry->getActualName(); \Includes\Decorator\Utils\CacheManager::logMessage(PHP_EOL); \Includes\Decorator\Utils\CacheManager::logMessage($message); $isInvoked = \XLite\Upgrade\Cell::getInstance()->runHelper($entry, 'post_rebuild'); if ($isInvoked && \XLite\Upgrade\Cell::getInstance()->getHookRedirect()) { break; } if (!\XLite\Upgrade\Cell::getInstance()->hasUnfinishedUpgradeHooks('post_rebuild', $entry)) { // All post-rebuild hooks completed, run the rest actions... \XLite\Upgrade\Cell::getInstance()->runCommonHelper($entry, 'add_labels'); \XLite\Upgrade\Cell::getInstance()->callInstallEvent($entry); $entry->setPostUpgradeActionsCalled(); } if (\Includes\Decorator\Utils\CacheManager::isTimeExceeds(static::STEP_TTL)) { break; } } } } } \Includes\Decorator\Utils\CacheManager::logMessage(PHP_EOL); \XLite\Core\Database::getEM()->flush(); \XLite\Core\Database::getEM()->clear(); }
/** * Execute certain hook handle * * @return void */ public function executeHookHandler() { $list = \Includes\Decorator\Plugin\Doctrine\Utils\FixturesManager::getFixtures(); if ($list) { \Includes\Utils\Operator::showMessage('', true, false); foreach ($list as $fixture) { $message = '...Load ' . substr($fixture, strlen(LC_DIR_ROOT)); \Includes\Utils\Operator::showMessage($message, true, true); \Includes\Decorator\Utils\CacheManager::logMessage(PHP_EOL); \Includes\Decorator\Utils\CacheManager::logMessage($message); if (static::isYAML($fixture)) { // Load YAML fixture \XLite\Core\Database::getInstance()->loadFixturesFromYaml($fixture); } else { // Load SQL queries \Includes\Utils\Database::uploadSQLFromFile($fixture); } \Includes\Decorator\Plugin\Doctrine\Utils\FixturesManager::removeFixtureFromList($fixture); if (\Includes\Decorator\Utils\CacheManager::isTimeExceeds(static::STEP_TTL)) { break; } } } \Includes\Decorator\Utils\CacheManager::logMessage(PHP_EOL); \XLite\Core\Database::getEM()->clear(); }
/** * Fifth step: copy updated files * * @return void */ protected function doActionUpdateFiles() { $this->setReturnURL($this->buildURL('upgrade')); if (\XLite\Upgrade\Cell::getInstance()->isUnpacked()) { \Includes\Utils\Operator::showMessage('Installing updates, please wait...'); // Perform upgrade // post_upgrade hooks will be proceeded here $this->runStep('upgrade', array(false, $this->getFilesToOverWrite())); $this->finalizeUpgrade(); } else { $this->showWarning(__FUNCTION__, static::t('Files cannot be updated')); } }
/** * showStepInfo * * @return void */ public static function showStepInfo() { $text = number_format(microtime(true) - static::$stepStart, 2) . 'sec, '; $memory = memory_get_usage(); $text .= \Includes\Utils\Converter::formatFileSize($memory, ''); $text .= ' (' . \Includes\Utils\Converter::formatFileSize(memory_get_usage() - static::$stepMemory, '') . ')'; \Includes\Utils\Operator::showMessage(' [' . $text . ']'); }
/** * Common method to manage entry packages * * @param boolean $isUnpack Operation type * * @return boolean */ protected function manageEntryPackages($isUnpack) { $cntProcessed = 0; $cntTotal = 0; $success = true; $entries = $this->getEntries(); foreach ($entries as $entry) { $cntTotal++; $skip = $isUnpack ? $entry->isUnpacked() : $entry->isDownloaded(); if (!$skip) { if ($isUnpack) { $entry->unpack(); $success = $entry->isUnpacked(); \Includes\Utils\Operator::showMessage(\XLite\Core\Translation::getInstance()->translate('...Unpacking {{entry}}...{{status}}', array('entry' => addslashes($entry->getActualName()), 'status' => $success ? 'OK' : 'Failed'))); } else { $entry->download(); $success = $entry->isDownloaded(); \Includes\Utils\Operator::showMessage(\XLite\Core\Translation::getInstance()->translate('...Downloading {{entry}}...{{status}}', array('entry' => addslashes($entry->getActualName()), 'status' => $success ? 'OK' : 'Failed'))); } if ($success) { $cntProcessed++; if ($this->isEntryOperationLimitReached($cntProcessed, $isUnpack)) { break; } } else { break; } } } return $success && (count($entries) > $cntTotal || ($isUnpack ? $this->isUnpacked() : $this->isDownloaded())); }
/** * 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()))); } }
/** * Execute some helper methods * Return true if at least one method was executed * * @param string $type Helper type * * @return boolean */ public function runHelpers($type) { $result = false; $path = \Includes\Utils\FileManager::getCanonicalDir($this->getRepositoryPath()); // Helpers must examine itself if the module has been installed previously if ($path) { $helpers = 'post_rebuild' === $type ? $this->postRebuildHelpers : $this->getHelpers($type); $helpers = (array) $helpers; $invokedHooks = \XLite\Upgrade\Cell::getInstance()->getInvokedHooks(); $pendingHooks = \XLite\Upgrade\Cell::getInstance()->getPendingHooks(); foreach ($helpers as $file) { if (isset($invokedHooks[$file])) { // Hook has been invoked earlier, skip... continue; } /** @var \Closure $function */ $function = (require_once $path . $file); // Prepare argument for hook function $suffix = ''; $arg = null; if (!empty($pendingHooks[$file]) && 0 < $pendingHooks[$file]) { $arg = $pendingHooks[$file]; $suffix = sprintf(' (%d)', $arg); } \Includes\Utils\Operator::showMessage(\XLite\Core\Translation::getInstance()->translate('...Invoke {{type}} hook for {{entry}}...', array('type' => $file, 'entry' => addslashes($this->getActualName()) . $suffix))); // Run hook function $hookResult = $function($arg); // Hook has been invoked - return true $result = true; // Save result of hook function \XLite\Upgrade\Cell::getInstance()->addPassedHook($file, intval($hookResult)); $this->addInfoMessage('Update hook is run: {{type}}:{{file}}', true, array('type' => $this->getActualName(), 'file' => $file . $suffix)); if (0 < intval($hookResult)) { \XLite\Upgrade\Cell::getInstance()->setHookRedirect(true); break; } } if ($helpers) { \XLite\Core\Database::getCacheDriver()->deleteAll(); } } return $result; }
/** * Execute certain hook handle * * @return void */ public function executeHookHandler() { if (static::isCalculateCacheAllowed() && \Includes\Decorator\Utils\CacheInfo::get('rebuildBlockMark')) { $i = static::getCounter(); do { $processed = \XLite\Core\QuickData::getInstance()->updateChunk($i, static::CHUNK_LENGTH); if (0 < $processed) { \XLite\Core\Database::getEM()->clear(); } $i += $processed; static::setCounter($i); \Includes\Utils\Operator::showMessage('.', false, true); } while (0 < $processed && !\Includes\Decorator\Utils\CacheManager::isTimeExceeds(static::STEP_TTL)); } }