/** * 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(); }
/** * 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 handler * * @return void */ public function executeHookHandler() { // Truncate old if (!\Includes\Decorator\Utils\CacheManager::isCapsular()) { $this->clearAll(); } // Create new $this->createLists(); }
/** * Execute certain hook handler * * @return void */ public function executeHookHandler() { // Delete old and rename new if (\Includes\Decorator\Utils\CacheManager::isCapsular()) { $repo = \XLite\Core\Database::getRepo('XLite\\Model\\TemplatePatch'); $key = \Includes\Decorator\Utils\CacheManager::getKey(); $repo->deleteObsolete($key); $repo->markCurrentVersion($key); } }
/** * Execute certain hook handle * * @return void */ public function executeHookHandler() { $this->saveMetadata(); if (!\Includes\Decorator\Utils\CacheManager::isCapsular() || $this->isMetadataChanged()) { \Includes\Decorator\Utils\CacheInfo::set('metadataChangedState', true); \Includes\Decorator\Plugin\Doctrine\Utils\DBSchemaManager::prepareDBSchema(); } else { \Includes\Decorator\Utils\CacheInfo::set('metadataChangedState', false); \Includes\Decorator\Plugin\Doctrine\Utils\DBSchemaManager::removeDBSchema(); } }
/** * Check and execute hook handlers * * @param string $hook Hook name * * @return void */ public static function invokeHook($hook) { // Get plugins "subscribed" for the hook foreach (static::getPlugins($hook) as $plugin => $instance) { if (!isset($instance)) { $class = '\\Includes\\Decorator\\Plugin\\' . str_replace('_', '\\', $plugin) . '\\Main'; static::$plugins[$plugin] = $instance = new $class(); } // Show message \Includes\Decorator\Utils\CacheManager::showStepMessage('Run the "' . $plugin . '" plugin...'); // Execute plugin main method $instance->executeHookHandler(); // Show memory usage \Includes\Decorator\Utils\CacheManager::showStepInfo(); } }
/** * Execute certain hook handle * * @return void */ public function executeHookHandler() { $schema = \Includes\Decorator\Plugin\Doctrine\Utils\DBSchemaManager::getDBSchema(); if ($schema) { do { $queries = array(); foreach ($schema as $k => $query) { $queries[] = $query; unset($schema[$k]); } if ($queries) { \XLite\Core\Database::getInstance()->executeQueries($queries); } } while ($schema && !\Includes\Decorator\Utils\CacheManager::isTimeExceeds(static::STEP_TTL)); \Includes\Decorator\Plugin\Doctrine\Utils\DBSchemaManager::updateDBSchema($schema); } }
/** * Check and execute hook handlers * * @param string $hook Hook name * * @return void */ public static function invokeHook($hook) { // Get plugins "subscribed" for the hook foreach (static::getPlugins($hook) as $plugin => $instance) { if (!isset($instance)) { $class = '\\Includes\\Decorator\\Plugin\\' . str_replace('_', '\\', $plugin) . '\\Main'; static::$plugins[$plugin] = $instance = new $class(); } if ($instance->isBlockingPlugin()) { // Block software before run plugin \Includes\Decorator\Utils\CacheManager::setRebuildBlockMark(\Includes\Decorator\Utils\CacheManager::getStep(), array('hook' => $hook, 'class' => get_class($instance))); } // Show message $title = $instance->getTitle() ?: 'Run the "' . $plugin . '" plugin...'; \Includes\Decorator\Utils\CacheManager::showStepMessage($title); // Execute plugin main method $instance->executeHookHandler(); // Show memory usage \Includes\Decorator\Utils\CacheManager::showStepInfo(); } }
/** * Execute certain hook handler * * @return void */ public function executeHookHandler() { // Remove old capsular directories if (\Includes\Decorator\Utils\CacheManager::isCapsular()) { $currentKey = \Includes\Decorator\Utils\CacheManager::getKey(); foreach (\Includes\Decorator\Utils\CacheManager::getCacheDirs(true) as $dir) { $list = glob(rtrim($dir, LC_DS) . '.*'); if ($list) { foreach ($list as $subdir) { list($main, $key) = explode('.', $subdir, 2); if ($key && $key != $currentKey) { \Includes\Utils\FileManager::unlinkRecursive($subdir); } } } } } \Includes\Decorator\Utils\CacheManager::cleanupCache(); // Load classes from "classes" (do not use cache) \Includes\Autoloader::switchLcAutoloadDir(); \Includes\Decorator\Plugin\Doctrine\Plugin\QuickData\Main::initializeCounter(); }
/** * Generate a cache of classes * * @return bool */ function doBuildCache() { $result = true; x_install_log(xtr('Cache building...')); ob_start(); try { define('DO_ONE_STEP_ONLY', true); \Includes\Decorator\Utils\CacheManager::rebuildCache(); } catch (\Exception $e) { x_install_log('Exception: ' . $e->getMessage()); $result = false; } $message = ob_get_contents(); ob_end_clean(); if (!$result) { x_install_log(xtr('Cache building procedure failed: :message', array(':message' => $e->getMessage()))); } return $result; }
/** * Execute certain hook handler * * @return void */ public function executeHookHandler() { \Includes\Decorator\Utils\CacheManager::getClassesTree(); }
/** * Error handler * * @param array $error catched error * * @return void */ public static function handleError(array $error) { \Includes\Decorator\Utils\CacheManager::checkRebuildIndicatorState(); if (isset($error['type']) && E_ERROR == $error['type']) { static::logInfo($error['message'], $error['type']); static::showErrorPage(__CLASS__ . '::ERROR_FATAL_ERROR', $error['message']); } }
/** * Check - current plugin is bocking or not * * @return boolean */ public function isBlockingPlugin() { return !\Includes\Decorator\Utils\CacheManager::isCapsular(); }
/** * Construct data key * * @param mixed $key Key * * @return string */ protected static function constructDataKey($key) { if (true === $key) { $key = \Includes\Decorator\Utils\CacheManager::isCapsular() ? \Includes\Decorator\Utils\CacheManager::getkey() : '_'; } elseif (false === $key) { $key = '_'; } return $key; }
/** * Constructor * * @return void */ protected function __construct() { parent::__construct(); $this->checkTemplateStatus = LC_DEVELOPER_MODE || \XLite::getInstance()->getOptions(array('skin_details', 'check_templates_status')); $this->rootDirLength = strlen(LC_DIR_ROOT); $this->compileDir = \Includes\Decorator\Utils\CacheManager::getCompileDir(); }
/** * Ability to provoke cache cleanup (or to prevent it) * * @param boolean $flag If it's needed to cleanup cache or not * * @return void */ public static function setCleanUpCacheFlag($flag) { static::$isNeedToCleanupCache = true === $flag; if (static::$isNeedToCleanupCache) { \Includes\Decorator\Utils\CacheManager::setCacheRebuildMark(); } else { \Includes\Decorator\Utils\CacheManager::unsetCacheRebuildMark(); } }
/** * getStartupFlag * * @return boolean */ protected function getStartupFlag() { return \XLite::getInstance()->getOptions(array('profiler_details', 'enabled')) && $this->isTargetAllowed() && !\XLite\Core\Request::getInstance()->isPost() && !\XLite\Core\Request::getInstance()->isCLI() && !\XLite\Core\Request::getInstance()->isAJAX() && !\Includes\Decorator\Utils\CacheManager::isRebuildNeeded(); }
/** * Copy state name to custom_state field to preserve data when state is removed * * @return void * * @PrePersist * @PreUpdate */ public function duplicateStateName() { if (!\Includes\Decorator\Utils\CacheManager::isRebuildBlock() && $this->getState() && $this->getCustomState() !== $this->getStateName()) { $this->setCustomState($this->getStateName()); } }
/** * Clean up classes cache (if needed) * * @return void */ public function __destruct() { if (static::$isNeedToCleanupCache) { \Includes\Decorator\Utils\CacheManager::cleanupCacheIndicators(); } }
/** * Initialization * * @return void */ public static function initialize() { if (static::isSafeModeRequested() && !static::isSafeModeStarted()) { if (static::isSoftwareResetEnabled()) { // Put safe mode indicator \Includes\Utils\FileManager::write(static::getIndicatorFileName(), static::getIndicatorFileContent()); // Clean cache indicators to force cache generation \Includes\Decorator\Utils\CacheManager::cleanupCacheIndicators(); } // Redirect to avoid loop \Includes\Utils\Operator::redirect('admin.php?target=main'); } }
/** * Check file * * @return void */ protected function checkFile() { $path = $this->getFile(); if (!file_exists($path)) { $class = $this->getClass(); \Includes\Decorator\Utils\CacheManager::fireError('Class ' . $class . ' is not defined in ' . $path . ' file.' . ' Class ' . $class . ' is not added to var/run/ directory.'); } }
/** * Defines the cache dir for the media type * * @param string $media Media type * @param boolean $original Get original path OPTIONAL * * @return string */ protected function getCacheDir($media, $original = false) { $interface = is_null($this->interface) ? \XLite::isAdminZone() ? 'admin' : 'default' : $this->interface; $http = is_null($this->http) ? \XLite\Core\Request::getInstance()->isHTTPS() ? 'https' : 'http' : $this->http; return \Includes\Decorator\Utils\CacheManager::getResourcesDir($original) . $interface . LC_DS . $http . LC_DS . $media . LC_DS; }
/** * Get file path with DB schema * * @return string */ protected static function getDBSchemaFilePath() { return \Includes\Decorator\Utils\CacheManager::buildCopsularFilename(LC_DIR_VAR . '.decorator.dbSchema.php'); }
/** * Constructor * * @return void */ protected function __construct() { parent::__construct(); $this->filesRepositories = array(\Includes\Decorator\Utils\CacheManager::getCompileDir() => 'compiled classes repository', LC_DIR_ROOT => 'X-Cart root'); }
/** * Mark templates * * @return boolean */ protected function isMarkTemplates() { return !\XLite::isAdminZone() && \XLite\Module\XC\ThemeTweaker\Main::isTargetAllowed() && \XLite\Module\XC\ThemeTweaker\Main::isUserAllowed() && !\XLite\Core\Request::getInstance()->isPost() && !\XLite\Core\Request::getInstance()->isCLI() && !\XLite\Core\Request::getInstance()->isAJAX() && !\Includes\Decorator\Utils\CacheManager::isRebuildNeeded() && \XLite\Core\Config::getInstance()->XC->ThemeTweaker->edit_mode; }
/** * Get namespace * * @return string */ protected function getNamespace() { $namespace = empty($this->options['namespace']) ? '' : $this->options['namespace'] . '_'; if (isset($this->options['original'])) { $namespace .= \Includes\Decorator\Utils\CacheManager::getDataCacheSuffix($this->options['original']); } else { $namespace .= \Includes\Decorator\Utils\CacheManager::getDataCacheSuffix(); } return $namespace; }
/** * Initialization * * @return void */ public static function initialize() { if (static::isDropCacheRequested()) { // Drop classes cache \Includes\Decorator\Utils\CacheManager::cleanupCacheIndicators(); // Redirect to avoid loop \Includes\Utils\Operator::redirect(\XLite::getAdminScript() . '?target=main'); } elseif (static::isSafeModeRequested() && !static::isSafeModeStarted()) { $restorePoint = null; if (static::isRestoreDateSet()) { $restorePoint = \Includes\Utils\ModulesManager::getRestorePoint(static::getRestoreDate()); } if (static::isSoftwareResetEnabled()) { if (!($restorePoint != null ^ static::isRestoreDateSet())) { // Put safe mode indicator \Includes\Utils\FileManager::write(static::getIndicatorFileName(), static::getIndicatorFileContent()); // Clean cache indicators to force cache generation \Includes\Decorator\Utils\CacheManager::cleanupCacheIndicators(); } else { $date = \DateTime::createFromFormat(\Includes\Utils\ModulesManager::RESTORE_DATE_FORMAT, static::getRestoreDate()); \Includes\Decorator\Utils\PersistentInfo::set('restoreFailed', $date->getTimestamp()); } } // Redirect to avoid loop \Includes\Utils\Operator::redirect(\XLite::getAdminScript() . '?target=main'); } }
/** * Check if LiteCommerce installed * Use into Drupal connector * * :FIXME: check this carefully * * @param string $dbURL Database Url string (e.g. mysql://username:password@localhost/databasename) * * @return bool */ function isLiteCommerceInstalled($dbURL = null, &$message) { // Check by template and config.php file $checkResult = file_exists(LC_DIR_SKINS . 'admin/en/welcome.tpl') && (file_exists(LC_DIR_CONFIG . 'config.php') || file_exists(LC_DIR_CONFIG . 'config.local.php')); if ($checkResult) { // Get database options from config.php $configData = \Includes\Utils\ConfigParser::getOptions('database_details'); if (is_array($configData)) { // Check if host, dbname and username is not empty $checkResult = !empty($configData['hostspec']) && !empty($configData['database']) && !empty($configData['username']); if ($checkResult) { if (isset($dbURL)) { // Support of Drupal 6 installation if (is_array($dbURL)) { $data = $dbURL; } else { $data = parseDbURL($dbURL); } if (!empty($data)) { // Compare database options from config and from parameter $checkResult = $configData['hostspec'] == $data['mysqlhost'] && $configData['username'] == $data['mysqluser'] && $configData['password'] == $data['mysqlpass'] && $configData['database'] == $data['mysqlbase'] && (!isset($data['mysqlport']) || $configData['port'] == $data['mysqlport']) && (!isset($data['mysqlsock']) || $configData['socket'] == $data['mysqlsock']); if (!$checkResult) { $message = 'Database parameters (specified in Drupal and LiteCommerce configs) comparison failed'; } } else { $message = '$dbURL passed but hasn\'t any data or corrupted'; $checkResult = false; } } else { $data = null; } if ($checkResult) { // Check if connection works $checkResult = dbConnect($data, $errorMsg); if ($checkResult) { $res = dbFetchColumn('SELECT profile_id from xlite_profiles LIMIT 1', $errorMsg); if (empty($res)) { $message = 'There are no profiles found in the database'; $checkResult = false; } elseif (\Includes\Decorator\Utils\CacheManager::isRebuildNeeded(\Includes\Decorator\Utils\CacheManager::STEP_THIRD)) { $message = 'Cache isn\'t built yet'; $checkResult = false; } } else { $message = 'Cannot connect to the database'; } } } else { $message = 'Host, username or database name are empty'; } } else { $message = 'Corrupted LiteCommerce config file'; $checkResult = false; } } else { $message = 'config.php or admin/en/welcome.tpl files are not found'; } return $checkResult; }
/** * Add cleanup cache mark * * @param string $location URL * * @return string */ protected function addCleanupCacheMark($location) { if (\XLite::getCleanUpCacheFlag()) { $location .= (strpos($location, '?') === false ? '?' : '&') . \Includes\Decorator\Utils\CacheManager::KEY_NAME . '=' . \Includes\Decorator\Utils\CacheManager::getKey(true); } return $location; }
/** * Prepare common properties * * @param array $data Data describe the patch * @param string $class Patcher class * * @return array */ protected function getCommonData(array $data, $class) { $parts = explode(':', $data[$class::PATCHER_CELL_TPL], 3); if (1 == count($parts)) { $parts = array('customer', '', $parts[0]); } elseif (2 == count($parts)) { $parts = array($parts[0], '', $parts[1]); } $version = \Includes\Decorator\Utils\CacheManager::isCapsular() ? \Includes\Decorator\Utils\CacheManager::getKey() : null; return array('patch_type' => $data[$class::PATCHER_CELL_TYPE], 'version' => $version) + array_combine(array('zone', 'lang', 'tpl'), $parts); }