/** * @param InputInterface $input * @param OutputInterface $output * @return int|null */ protected function execute(InputInterface $input, OutputInterface $output) { $this->getApplication()->setAutoExit(false); $this->detectMagento($output); if (!$this->initMagento()) { return; } try { if (false === $input->getOption('no-implicit-cache-flush')) { $this->flushCache(); } /** * Put output in buffer. \Mage_Core_Model_Resource_Setup::_modifyResourceDb should print any error * directly to stdout. Use execption which will be thrown to show error */ \ob_start(); \Mage_Core_Model_Resource_Setup::applyAllUpdates(); if (is_callable(array('\\Mage_Core_Model_Resource_Setup', 'applyAllDataUpdates'))) { \Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); } \ob_end_clean(); $output->writeln('<info>done</info>'); } catch (Exception $e) { \ob_end_clean(); $this->printException($output, $e); $this->printStackTrace($output, $e->getTrace()); $this->printFile($output, $e); return 1; // exit with error status } }
/** * @covers Mage_Core_Model_Resource_Setup::applyAllUpdates * @covers Mage_Core_Model_Resource_Setup::applyAllDataUpdates */ public function testApplyAllDataUpdates() { /*reset versions*/ Mage::getResourceModel('Mage_Core_Model_Resource_Resource')->setDbVersion('adminnotification_setup', false); Mage::getResourceModel('Mage_Core_Model_Resource_Resource')->setDataVersion('adminnotification_setup', false); $this->_model->deleteTableRow('core_resource', 'code', 'adminnotification_setup'); $this->_model->getConnection()->dropTable($this->_model->getTable('adminnotification_inbox')); try { $this->_model->applyAllUpdates(); $this->_model->applyAllDataUpdates(); } catch (Exception $e) { $this->fail("Impossible to continue other tests, because database is broken: {$e}"); } $this->assertNotEmpty($this->_model->getTableRow('core_resource', 'code', 'adminnotification_setup', 'version')); $this->assertNotEmpty($this->_model->getTableRow('core_resource', 'code', 'adminnotification_setup', 'data_version')); }
/** * This is a first observer in magento * where we can update module list and configuration. * * @param $observer */ public function resourceGetTableName($observer) { if ($observer->getTableName() !== 'core_website') { return; } try { Mage::getSingleton('eltrino_compatibility/modules')->loadModules(); Mage_Core_Model_Resource_Setup::applyAllUpdates(); } catch (Exception $e) { Mage::logException($e); } }
public function execute() { Mage::app('admin'); \Mage_Core_Model_Resource_Setup::applyAllUpdates(); \Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); try { $this->setup(); } catch (Exception $e) { $msg .= $e->getMessage() . ' (' . $e->getFile() . ' l. ' . $e->getLine() . ")\n"; Logger::error('An error occured while initializing InitGermanSetup:', array(), false); Logger::log('%s (%s, line %s)', array($e->getMessage(), $e->getFile(), $e->getLine())); } }
/** * @see vendor/symfony/src/Symfony/Component/Console/Command/Symfony\Component\Console\Command.Command::execute() */ protected function execute(InputInterface $input, OutputInterface $output) { $this->preExecute($input, $output); $this->createExtensionFolder(); foreach ($this->config->getExtensions() as $name => $extension) { $this->installExtension($name, $extension); } $this->initMagento(); \Mage_Core_Model_Resource_Setup::applyAllUpdates(); \Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); \Mage::getModel('core/cache')->flush(); Logger::notice('Done'); }
/** * Flush an entire magento cache * * @return Aitoc_Aitsys_Model_Core_Cache */ public function flush() { if (version_compare(Mage::getVersion(), '1.4', '>=')) { Mage::app()->getCacheInstance()->flush(); } else { Mage::app()->getCache()->clean(); } Mage::getConfig()->reinit(); if (sizeof(Mage::getConfig()->getNode('aitsys')->events)) { Mage::app()->addEventArea('aitsys'); } if (!Mage::app()->getUpdateMode()) { Mage_Core_Model_Resource_Setup::applyAllUpdates(); } return $this; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { $this->getApplication()->setAutoExit(false); $this->detectMagento($output); if ($this->initMagento()) { try { /** * Get events before cache flush command is called. */ $reflectionApp = new \ReflectionObject(\Mage::app()); $appEventReflectionProperty = $reflectionApp->getProperty('_events'); $appEventReflectionProperty->setAccessible(true); $eventsBeforeCacheFlush = $appEventReflectionProperty->getValue(\Mage::app()); $this->getApplication()->run(new StringInput('cache:flush'), new NullOutput()); /** * Restore initially loaded events which was reset during setup script run */ $appEventReflectionProperty->setValue(\Mage::app(), $eventsBeforeCacheFlush); /** * Put output in buffer. \Mage_Core_Model_Resource_Setup::_modifyResourceDb should print any error * directly to stdout. Use execption which will be thrown to show error */ \ob_start(); \Mage_Core_Model_Resource_Setup::applyAllUpdates(); if (is_callable(array('\\Mage_Core_Model_Resource_Setup', 'applyAllDataUpdates'))) { \Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); } \ob_end_clean(); $output->writeln('<info>done</info>'); } catch (\Exception $e) { \ob_end_clean(); $this->printException($output, $e); $this->printStackTrace($output, $e->getTrace()); $this->printFile($output, $e); return 1; // exit with error status } } return 0; }
<?php define('_TEST', true); require_once '../app/Mage.php'; Mage::app("default")->setUseSessionInUrl(false); Mage::setIsDeveloperMode(true); Mage_Core_Model_Resource_Setup::applyAllUpdates(); if (!function_exists('test_autoload')) { function test_autoload($class) { $file = dirname(__FILE__) . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php'; if (file_exists($file)) { require_once $file; } } spl_autoload_register('test_autoload'); } Mana_Core_Test_Case::installTestData();
/** * Initialize active modules configuration and data * * @return Mage_Core_Model_App */ protected function _initModules() { if (!$this->_config->loadModulesCache()) { $this->_config->loadModules(); if ($this->_config->isLocalConfigLoaded() && !$this->_shouldSkipProcessModulesUpdates()) { Varien_Profiler::start('mage::app::init::apply_db_schema_updates'); Mage_Core_Model_Resource_Setup::applyAllUpdates(); Varien_Profiler::stop('mage::app::init::apply_db_schema_updates'); } $this->_config->loadDb(); $this->_config->saveCache(); } return $this; }
/** * Initialization of core configuration * * @return Mage_Core_Model_Config */ public function init($etcDir = null) { $this->setCacheChecksum(null); $saveCache = true; if (is_null($etcDir)) { $etcDir = Mage::getRoot() . DS . 'etc'; } $this->_customEtcDir = $etcDir; $this->loadFile($etcDir . DS . 'local.xml'); // check if local modules are disabled $disableLocalModules = (string) $this->getNode('global/disable_local_modules'); $disableLocalModules = !empty($disableLocalModules) && ('true' === $disableLocalModules || '1' === $disableLocalModules); if ($disableLocalModules) { /** * Reset include path */ set_include_path(BP . '/app/code/community' . PS . BP . '/app/code/core' . PS . BP . '/lib' . PS . Mage::registry('original_include_path')); } Varien_Profiler::start('config/load-cache'); if (Mage::app()->isInstalled()) { if ($this->loadCache()) { if (!Mage::app()->useCache('config')) { Mage::app()->removeCache($this->getCacheId()); } else { Varien_Profiler::stop('config/load-cache'); return $this; } } if (!Mage::app()->useCache('config')) { $saveCache = false; } } else { $saveCache = false; } Varien_Profiler::stop('config/load-cache'); $mergeConfig = new Mage_Core_Model_Config_Base(); /** * Load base configuration data */ Varien_Profiler::start('config/load-base'); $configFile = $etcDir . DS . 'config.xml'; $this->loadFile($configFile); $moduleFiles = glob($etcDir . DS . 'modules' . DS . '*.xml'); if ($moduleFiles) { foreach ($moduleFiles as $file) { $mergeConfig->loadFile($file); $this->extend($mergeConfig); } } Varien_Profiler::stop('config/load-base'); /** * Load local configuration data */ Varien_Profiler::start('config/load-local'); $configFile = $etcDir . DS . 'local.xml'; if (is_readable($configFile)) { $mergeConfig->loadFile($configFile); $this->extend($mergeConfig); $localConfigLoaded = true; } else { $localConfigLoaded = false; } Varien_Profiler::stop('config/load-local'); if (!$localConfigLoaded) { Varien_Profiler::start('config/load-distro'); $mergeConfig->loadString($this->loadDistroConfig()); $this->extend($mergeConfig, true); Varien_Profiler::stop('config/load-distro'); $saveCache = false; } /** * Load modules configuration data */ Varien_Profiler::start('config/load-modules'); $modules = $this->getNode('modules')->children(); foreach ($modules as $modName => $module) { if ($module->is('active')) { if ($disableLocalModules && 'local' === (string) $module->codePool) { continue; } $configFile = $this->getModuleDir('etc', $modName) . DS . 'config.xml'; if ($mergeConfig->loadFile($configFile)) { $this->extend($mergeConfig, true); } } } Varien_Profiler::stop('config/load-modules'); Varien_Profiler::start('config/apply-extends'); $this->applyExtends(); Varien_Profiler::stop('config/apply-extends'); /** * Load configuration from DB */ if ($localConfigLoaded) { Varien_Profiler::start('dbUpdates'); Mage_Core_Model_Resource_Setup::applyAllUpdates(); Varien_Profiler::stop('dbUpdates'); Varien_Profiler::start('config/load-db'); $dbConf = Mage::getResourceModel('core/config'); $dbConf->loadToXml($this); Varien_Profiler::stop('config/load-db'); } if ($saveCache) { Varien_Profiler::start('config/save-cache'); $this->saveCache(); Varien_Profiler::stop('config/save-cache'); } return $this; }
/** * Install application using temporary directory and vendor-specific database settings * * @throws Magento_Exception */ protected function _install() { $this->_ensureDirExists($this->_installDir); $this->_ensureDirExists($this->_installEtcDir); $this->_ensureDirExists($this->_installDir . DIRECTORY_SEPARATOR . 'media'); $this->_ensureDirExists($this->_installDir . DIRECTORY_SEPARATOR . 'theme'); /* Copy *.xml configuration files */ $dirs = array($this->_installEtcDir => $this->_globalEtcFiles, $this->_installEtcDir . '/modules' => $this->_moduleEtcFiles); foreach ($dirs as $targetEtcDir => $sourceEtcFiles) { $this->_ensureDirExists($targetEtcDir); foreach ($sourceEtcFiles as $sourceEtcFile) { $targetEtcFile = $targetEtcDir . '/' . basename($sourceEtcFile); copy($sourceEtcFile, $targetEtcFile); } } /* Make sure that local.xml contains an invalid installation date */ $installDate = (string) $this->_localXml->global->install->date; if ($installDate && strtotime($installDate)) { throw new Magento_Exception("Configuration file '{$this->_localXmlFile}' must contain an invalid installation date."); } /* Replace local.xml */ $targetLocalXml = $this->_installEtcDir . '/local.xml'; $this->_localXml->asNiceXml($targetLocalXml); /* Initialize an application in non-installed mode */ $this->initialize(); /* Run all install and data-install scripts */ Mage_Core_Model_Resource_Setup::applyAllUpdates(); Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); /* Enable configuration cache by default in order to improve tests performance */ Mage::app()->getCacheInstance()->saveOptions(array('config' => 1)); /* Fill installation date in local.xml to indicate that application is installed */ $localXml = file_get_contents($targetLocalXml); $localXml = str_replace($installDate, date('r'), $localXml, $replacementCount); if ($replacementCount != 1) { throw new Magento_Exception("Unable to replace installation date properly in '{$targetLocalXml}' file."); } file_put_contents($targetLocalXml, $localXml, LOCK_EX); /* Add predefined admin user to the system */ $this->_createAdminUser(); /* Switch an application to installed mode */ $this->initialize(); }
/** * End install package(s) * */ public function endInstall() { if ($this->isInstalled()) { try { if (!empty($_GET['clean_sessions'])) { Mage::app()->cleanAllSessions(); } Mage::app()->cleanCache(); } catch (Exception $e) { $this->session()->addMessage('error', "Exception during cache and session cleaning: " . $e->getMessage()); } // reinit config and apply all updates Mage::app()->getConfig()->reinit(); Mage_Core_Model_Resource_Setup::applyAllUpdates(); Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); } if ($this->_getMaintenanceFlag()) { $maintenance_filename = 'maintenance.flag'; $config = $this->config(); if (!$this->isWritable() && strlen($config->__get('remote_config')) > 0) { $ftpObj = new Mage_Connect_Ftp(); $ftpObj->connect($config->__get('remote_config')); $ftpObj->delete($maintenance_filename); $ftpObj->close(); } else { @unlink($this->_getMaintenanceFilePath()); } } }
/** * Database installation * * @return Mage_Install_Model_Installer */ public function installDb() { Mage_Core_Model_Resource_Setup::applyAllUpdates(); $data = $this->getDataModel()->getConfigData(); /** * Saving host information into DB */ $setupModel = new Mage_Core_Model_Resource_Setup('core_setup'); if (!empty($data['use_rewrites'])) { $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_USE_REWRITES, 1); } if (!empty($data['enable_charts'])) { $setupModel->setConfigData(Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS, 1); } else { $setupModel->setConfigData(Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS, 0); } if (!empty($data['admin_no_form_key'])) { $setupModel->setConfigData('admin/security/use_form_key', 0); } $unsecureBaseUrl = Mage::getBaseUrl('web'); if (!empty($data['unsecure_base_url'])) { $unsecureBaseUrl = $data['unsecure_base_url']; $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL, $unsecureBaseUrl); } if (!empty($data['use_secure'])) { $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND, 1); $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $data['secure_base_url']); if (!empty($data['use_secure_admin'])) { $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_IN_ADMINHTML, 1); } } elseif (!empty($data['unsecure_base_url'])) { $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $unsecureBaseUrl); } /** * Saving locale information into DB */ $locale = $this->getDataModel()->getLocaleData(); if (!empty($locale['locale'])) { $setupModel->setConfigData(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $locale['locale']); } if (!empty($locale['timezone'])) { $setupModel->setConfigData(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $locale['timezone']); } if (!empty($locale['currency'])) { $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE, $locale['currency']); $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_DEFAULT, $locale['currency']); $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_ALLOW, $locale['currency']); } if (!empty($data['order_increment_prefix'])) { $this->_setOrderIncrementPrefix($setupModel, $data['order_increment_prefix']); } return $this; }
/** * Initialization of core configuration * * @return Mage_Core_Model_Config */ public function init($options = array()) { $this->setCacheChecksum(null); $saveCache = true; $this->_options = new Mage_Core_Model_Config_Options($options); $etcDir = $this->getOptions()->getEtcDir(); $this->_customEtcDir = $etcDir; $localConfigLoaded = $this->loadFile($etcDir . DS . 'local.xml'); // check if local modules are disabled $disableLocalModules = (string) $this->getNode('global/disable_local_modules'); $disableLocalModules = !empty($disableLocalModules) && ('true' === $disableLocalModules || '1' === $disableLocalModules); if ($disableLocalModules) { /** * Reset include path */ $codeDir = $this->getOptions()->getCodeDir(); $libDir = $this->getOptions()->getLibDir(); set_include_path(BP . DS . 'app' . DS . 'code' . DS . 'community' . PS . BP . DS . 'app' . DS . 'code' . DS . 'core' . PS . BP . DS . 'lib' . PS . Mage::registry('original_include_path')); } if (Mage::isInstalled()) { if (Mage::app()->useCache('config')) { Varien_Profiler::start('mage::app::init::config::load_cache'); $loaded = $this->loadCache(); Varien_Profiler::stop('mage::app::init::config::load_cache'); if ($loaded) { return $this; } } } $mergeConfig = new Mage_Core_Model_Config_Base(); /** * Load base configuration data */ Varien_Profiler::start('config/load-base'); $configFile = $etcDir . DS . 'config.xml'; $this->loadFile($configFile); Varien_Profiler::stop('config/load-base'); $this->_loadDeclaredModules($mergeConfig); /** * Load modules configuration data */ Varien_Profiler::start('config/load-modules'); $modules = $this->getNode('modules')->children(); foreach ($modules as $modName => $module) { if ($module->is('active')) { if ($disableLocalModules && 'local' === (string) $module->codePool) { continue; } $configFile = $this->getModuleDir('etc', $modName) . DS . 'config.xml'; if ($mergeConfig->loadFile($configFile)) { $this->extend($mergeConfig, true); } } } Varien_Profiler::stop('config/load-modules'); /** * Load local configuration data */ Varien_Profiler::start('config/load-local'); $configFile = $etcDir . DS . 'local.xml'; if (is_readable($configFile)) { $mergeConfig->loadFile($configFile); $this->extend($mergeConfig); } Varien_Profiler::stop('config/load-local'); Varien_Profiler::start('config/apply-extends'); $this->applyExtends(); Varien_Profiler::stop('config/apply-extends'); /** * Load configuration from DB */ if ($localConfigLoaded) { Varien_Profiler::start('dbUpdates'); Mage_Core_Model_Resource_Setup::applyAllUpdates(); Varien_Profiler::stop('dbUpdates'); Varien_Profiler::start('config/load-db'); $dbConf = $this->getResourceModel(); $dbConf->loadToXml($this); Varien_Profiler::stop('config/load-db'); } if (Mage::app()->useCache('config')) { Varien_Profiler::start('config/save-cache'); $this->saveCache(array('config')); Varien_Profiler::stop('config/save-cache'); } return $this; }
/** * Runs a single named setup resource * * This method nukes the global/resources node in the global config * and then repopulates it with **only** the $name resource. Then it * calls the standard Contao `applyAllUpdates` method. * * The benefit of this approach is we don't need to recreate the entire * setup resource running logic ourselves. Yay for code reuse * * The downside is we should probably exit quickly, as anything else that * uses the global/resources node is going to behave weird. * * @todo Repopulate global config after running? Non trivial since setNode escapes strings * * @param string $name * @param bool $needsUpdate * @param string $type * @throws \Exception * @internal param $string */ protected function _runNamedSetupResource($name, $needsUpdate, $type) { $output = $this->_output; if (!in_array($type, array(self::TYPE_MIGRATION_STRUCTURE, self::TYPE_MIGRATION_DATA))) { throw new \Exception('Invalid Type [' . $type . ']: structure, data are valid'); } if (!array_key_Exists($name, $needsUpdate)) { $output->writeln('<error>No updates to run for ' . $name . ', skipping </error>'); return; } //remove all other setup resources from configuration //(in memory, do not persist this to cache) $realConfig = \Mage::getConfig(); $resources = $realConfig->getNode('global/resources'); foreach ($resources->children() as $resource) { if (!$resource->setup) { continue; } unset($resource->setup); } //recreate our specific node in <global><resources></resource></global> //allows for theoretical multiple runs $setupResource = $needsUpdate[$name]; $setupResourceConfig = $this->_secondConfig->getNode('global/resources/' . $name); $moduleName = $setupResourceConfig->setup->module; $className = $setupResourceConfig->setup->class; $specificResource = $realConfig->getNode('global/resources/' . $name); $setup = $specificResource->addChild('setup'); if ($moduleName) { $setup->addChild('module', $moduleName); } else { $output->writeln('<error>No module node configured for ' . $name . ', possible configuration error </error>'); } if ($className) { $setup->addChild('class', $className); } //and finally, RUN THE UPDATES try { ob_start(); if ($type == self::TYPE_MIGRATION_STRUCTURE) { $this->_stashEventContext(); \Mage_Core_Model_Resource_Setup::applyAllUpdates(); $this->_restoreEventContext(); } else { if ($type == self::TYPE_MIGRATION_DATA) { \Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); } } $exceptionOutput = ob_get_clean(); $this->_output->writeln($exceptionOutput); } catch (\Exception $e) { $exceptionOutput = ob_get_clean(); $this->_processExceptionDuringUpdate($e, $name, $setupResource, $exceptionOutput); if ($this->_input->getOption('stop-on-error')) { throw new \RuntimeException('Setup stopped with errors'); } } }
/** * Database installation * * @return Mage_Install_Model_Installer */ public function installDb() { Mage_Core_Model_Resource_Setup::applyAllUpdates(); $data = $this->getDataModel()->getConfigData(); /** * Saving host information into DB */ $setupModel = new Mage_Core_Model_Resource_Setup('core_setup'); if (!empty($data['use_rewrites'])) { $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_USE_REWRITES, 1); } $unsecureBaseUrl = Mage::getBaseUrl('web'); if (!empty($data['unsecure_base_url'])) { $unsecureBaseUrl = $data['unsecure_base_url']; $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL, $unsecureBaseUrl); } if (!empty($data['use_secure'])) { $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND, 1); $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $data['secure_base_url']); if (!empty($data['use_secure_admin'])) { $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_IN_ADMINHTML, 1); } } elseif (!empty($data['unsecure_base_url'])) { $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $unsecureBaseUrl); } /** * Saving locale information into DB */ $locale = Mage::getSingleton('install/session')->getLocaleData(); if (!empty($locale['locale'])) { $setupModel->setConfigData(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $locale['locale']); } if (!empty($locale['timezone'])) { $setupModel->setConfigData(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $locale['timezone']); } if (!empty($locale['currency'])) { $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE, $locale['currency']); $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_DEFAULT, $locale['currency']); $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_ALLOW, $locale['currency']); } return $this; }
/** * Install application using temporary directory and vendor-specific database settings */ protected function _install() { $this->_ensureDirExists($this->_installDir); $this->_ensureDirExists($this->_installEtcDir); $this->_ensureDirExists($this->_installDir . DIRECTORY_SEPARATOR . 'media'); $this->_ensureDirExists($this->_installDir . DIRECTORY_SEPARATOR . 'skin'); /* Copy *.xml configuration files */ $dirs = array($this->_installEtcDir => $this->_globalEtcFiles, $this->_installEtcDir . '/modules' => $this->_moduleEtcFiles); foreach ($dirs as $targetEtcDir => $sourceEtcFiles) { $this->_ensureDirExists($targetEtcDir); foreach ($sourceEtcFiles as $sourceEtcFile) { $targetEtcFile = $targetEtcDir . '/' . basename($sourceEtcFile); copy($sourceEtcFile, $targetEtcFile); } } /* Make sure that local.xml contains an invalid installation date */ $installDate = (string) $this->_localXml->global->install->date; if ($installDate && strtotime($installDate)) { throw new Exception("Configuration file '{$this->_localXmlFile}' must contain an invalid installation date."); } /* Replace local.xml */ $targetLocalXml = $this->_installEtcDir . '/local.xml'; copy($this->_localXmlFile, $targetLocalXml); /* Initialize an application in non-installed mode */ $this->initialize(); /* Run all install and data-install scripts */ Mage_Core_Model_Resource_Setup::applyAllUpdates(); Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); /* Enable configuration cache by default in order to improve tests performance */ Mage::app()->getCacheInstance()->saveOptions(array('config' => 1)); /* Fill installation date in local.xml to indicate that application is installed */ $localXml = file_get_contents($targetLocalXml); $localXml = str_replace($installDate, date('r'), $localXml, $replacementCount); if ($replacementCount != 1) { throw new Exception("Unable to replace installation date properly in '{$targetLocalXml}' file."); } file_put_contents($targetLocalXml, $localXml, LOCK_EX); /* Make a database backup to be able to restore it to initial state any time */ $this->_db->createBackup(self::DB_BACKUP_NAME); /* Switch an application to installed mode */ $this->initialize(); /** * Initialization of front controller with all routers. * Should be here as needed only once after installation process. */ Mage::app()->getFrontController(); }
/** * Initialize active modules configuration and data * * @return Mage_Core_Model_App */ protected function _initModules() { // If cache locking is enabled then use that if ((bool) (string) $this->_config->getNode(self::XML_PATH_CACHE_LOCK_ENABLE) === true) { return $this->_initModulesWithLocking(); } if (!$this->_config->loadModulesCache()) { $this->_config->loadModules(); if ($this->_config->isLocalConfigLoaded() && !$this->_shouldSkipProcessModulesUpdates()) { Varien_Profiler::start('mage::app::init::apply_db_schema_updates'); Mage_Core_Model_Resource_Setup::applyAllUpdates(); Varien_Profiler::stop('mage::app::init::apply_db_schema_updates'); } $this->_config->loadDb(); $this->_config->saveCache(); } return $this; }
/** * Initialization of core configuration * * @return Mage_Core_Model_Config */ public function init($options = array()) { $this->setCacheChecksum(null); $this->_cacheLoadedSections = array(); if (is_array($options)) { $this->getOptions()->addData($options); } $etcDir = $this->getOptions()->getEtcDir(); $localConfigLoaded = $this->loadFile($etcDir . DS . 'local.xml'); if (Mage::isInstalled()) { if ($this->_canUseCacheForInit()) { Varien_Profiler::start('mage::app::init::config::load_cache'); $loaded = $this->loadCache(); Varien_Profiler::stop('mage::app::init::config::load_cache'); if ($loaded) { $this->_useCache = true; return $this; } } } /** * Load base configuration data */ $configFile = $etcDir . DS . 'config.xml'; $this->loadFile($configFile); $this->_loadDeclaredModules(); /** * Load modules configuration data */ Varien_Profiler::start('config/load-modules'); $this->loadModulesConfiguration('config.xml', $this); Varien_Profiler::stop('config/load-modules'); /** * Load local configuration data */ Varien_Profiler::start('config/load-local'); $mergeConfig = new Mage_Core_Model_Config_Base(); $configFile = $etcDir . DS . 'local.xml'; if (is_readable($configFile)) { $mergeConfig->loadFile($configFile); $this->extend($mergeConfig); } Varien_Profiler::stop('config/load-local'); $this->applyExtends(); /** * Load configuration from DB */ if ($localConfigLoaded) { Varien_Profiler::start('dbUpdates'); Mage_Core_Model_Resource_Setup::applyAllUpdates(); Varien_Profiler::stop('dbUpdates'); Varien_Profiler::start('config/load-db'); $dbConf = $this->getResourceModel(); $dbConf->loadToXml($this); Varien_Profiler::stop('config/load-db'); } if (Mage::app()->useCache('config')) { $this->saveCache(array(self::CACHE_TAG)); } return $this; }
protected function cleanCache() { $result = true; $message = ''; try { if ($this->isInstalled()) { if (!empty($_REQUEST['clean_sessions'])) { Mage::app()->cleanAllSessions(); $message .= 'Session cleaned successfully. '; } Mage::app()->cleanCache(); // reinit config and apply all updates Mage::app()->getConfig()->reinit(); Mage_Core_Model_Resource_Setup::applyAllUpdates(); Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); $message .= 'Cache cleaned successfully'; } else { $result = true; } } catch (Exception $e) { $result = false; $message = "Exception during cache and session cleaning: " . $e->getMessage(); $this->session()->addMessage('error', $message); } if ($result && $this->_getMaintenanceFlag()) { $maintenance_filename = 'maintenance.flag'; $config = $this->config(); if (!$this->isWritable() && strlen($config->__get('remote_config')) > 0) { $ftpObj = new Mage_Connect_Ftp(); $ftpObj->connect($config->__get('remote_config')); $ftpObj->delete($maintenance_filename); $ftpObj->close(); } else { @unlink($this->_getMaintenanceFilePath()); } } return array('result' => $result, 'message' => $message); }
/** * Initialize active modules configuration and data * * @return Mage_Core_Model_App */ protected function _initModules() { if (get_class($this->_config) === 'Made_Cache_Model_Config') { $backend = Mage::app()->getCacheInstance()->getFrontend()->getBackend(); if (get_class($backend) === 'Made_Cache_Redis_Backend') { return $this->_initModulesSafe(); } } if (!$this->_config->loadModulesCache()) { $this->_config->loadModules(); if ($this->_config->isLocalConfigLoaded() && !$this->_shouldSkipProcessModulesUpdates()) { Varien_Profiler::start('mage::app::init::apply_db_schema_updates'); Mage_Core_Model_Resource_Setup::applyAllUpdates(); Varien_Profiler::stop('mage::app::init::apply_db_schema_updates'); } $this->_config->loadDb(); $this->_config->saveCache(); } return $this; }