/** * 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(); }
/** * Get promotion message * * @return string */ protected function getPromotionMessage() { $addons = $this->getAddons(); $modules = array(); $params = array('clearCnd' => 1); foreach ($addons as $addon => $title) { if (!\Includes\Utils\Operator::checkIfClassExists('\\XLite\\Module\\' . $addon . '\\Main')) { $match = explode('\\', $addon); $mainClassFile = LC_DIR_MODULES . str_replace('\\', '/', $addon) . '/Main.php'; if (\Includes\Utils\FileManager::isExists($mainClassFile)) { // Module is installed but not enabled $limit = \XLite\View\Pager\Admin\Module\Manage::getInstance()->getItemsPerPage(); $pageId = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->getInstalledPageId($match[0], $match[1], $limit); $pageParam = 'page'; $target = 'addons_list_installed'; } else { // Module is not installed list(, $limit) = $this->getWidget(array(), '\\XLite\\View\\Pager\\Admin\\Module\\Install')->getLimitCondition()->limit; $pageId = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->getMarketplacePageId($match[0], $match[1], $limit); $pageParam = 'pageId'; $target = 'addons_list_marketplace'; } if (0 < $pageId) { $params[$pageParam] = $pageId; } $url = $this->buildURL($target, '', $params) . '#' . $match[1]; $modules[] = '<a href="' . $url . '">' . $title . '</a>'; } } return 0 < count($modules) ? static::t('Install additional modules to add more product sources', array('list' => implode(', ', $modules))) : ''; }
/** * This function is called if action is forbidden in demo mode * * @return void */ protected function forbidInDemoMode() { $message = $this->getForbidInDemoModeMessage(); if ($message) { \XLite\Core\TopMessage::addWarning($message); } $url = $this->getForbidInDemoModeRedirectURL(); if ($url) { \Includes\Utils\Operator::redirect($url); } }
/** * Execute certain hook handler * * @return void */ public function executeHookHandler() { // To cache data \Includes\Utils\ModulesManager::getActiveModules(); // Walk through the "XLite/Module" directory foreach ($this->getModuleMainFileIterator()->getIterator() as $path => $data) { $dir = $path; $name = basename($dir = dirname($dir)); $author = basename($dir = dirname($dir)); $class = \Includes\Utils\ModulesManager::getClassNameByAuthorAndName($author, $name); if (!\Includes\Utils\Operator::checkIfClassExists($class)) { require_once $path; } \Includes\Utils\ModulesManager::switchModule($author, $name); } \Includes\Utils\ModulesManager::removeFile(); }
/** * Echo chunk * * @param string &$chunk Text chunk to output * * @return void */ protected function echoChunk(&$chunk) { \Includes\Utils\Operator::flush($chunk, false, null); }
/** * Assemble default dump surcharge * * @param string $type Type * @param string $code Code * @param string $class Class * @param string $name Name * * @return array */ protected function assembleDefaultDumpSurcharge($type, $code, $class, $name) { $surcharge = new \XLite\Model\Order\Surcharge(); $surcharge->setType($type); $surcharge->setCode($code); $surcharge->setClass($class); $surcharge->setValue(0); $surcharge->setName($name); $surcharge->setOwner(static::getTemporaryOrder($this->getOrder()->getOrderId(), false) ?: $this->getOrder()); return array('name' => $surcharge->getTypeName(), 'cost' => $surcharge->getValue(), 'available' => $surcharge->getAvailable(), 'count' => 1, 'lastName' => $surcharge->getName(), 'code' => $surcharge->getCode(), 'widget' => \Includes\Utils\Operator::checkIfClassExists($class) ? $class::getWidgetClass() : \XLite\Logic\Order\Modifier\AModifier::getWidgetClass(), 'object' => $surcharge); }
/** * Forbid action processing * * @param string $message Action message OPTIONAL * @param string $url Redirect URL OPTIONAL * * @return void */ public static function doForbidAction($message = null, $url = null) { self::doForbidOperation($message); \Includes\Utils\Operator::redirect($url ?: \XLite\Core\Converter::buildURL(\XLite\Core\Request::getInstance()->target)); }
/** * Get surcharge totals * * @return array */ public function getSurchargeTotals() { $surcharges = array(); $rawSurcharges = \XLite::isAdminZone() ? array_merge($this->getExcludeSurcharges(), $this->getIncludeSurcharges()) : $this->getExcludeSurcharges(); foreach ($rawSurcharges as $surcharge) { $code = $surcharge->getCode(); if (!isset($surcharges[$code])) { $modifierClass = $surcharge->getClass(); $surcharges[$code] = array('name' => $surcharge->getTypeName(), 'cost' => 0, 'available' => $surcharge->getAvailable(), 'count' => 0, 'lastName' => null, 'code' => $code, 'widget' => \Includes\Utils\Operator::checkIfClassExists($modifierClass) ? $modifierClass::getWidgetClass() : \XLite\Logic\Order\Modifier\AModifier::getWidgetClass(), 'object' => $surcharge); } $surcharges[$code]['cost'] += $surcharge->getValue(); $surcharges[$code]['count']++; $surcharges[$code]['lastName'] = $surcharge->getName(); $surcharges[$code]['weight'] = $surcharge->getSortingWeight(); } uasort($surcharges, function ($a, $b) { return $a['weight'] < $b['weight'] ? -1 : $a['weight'] > $b['weight']; }); return $surcharges; }
/** * 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)); } }
/** * Run a step * * @param string $step Step name * * @return void */ protected static function runStep($step) { // Set internal flag if (!defined('XLITE_CACHE_BUILDING')) { define('XLITE_CACHE_BUILDING', true); } // To prevent multiple processes execution static::checkIfRebuildStarted(); // Write indicator files and show the message static::startStep($step); // Enable output (if needed) static::setFastCGITimeoutEcho(); // Perform step-specific actions \Includes\Utils\Operator::executeWithCustomMaxExecTime(\Includes\Utils\ConfigParser::getOptions(array('decorator', 'time_limit')), static::getStepCallback($step)); // (Un)Set indicator files and redirect static::completeStep($step); }
*/ return function () { $tablePrefix = \XLite::getInstance()->getOptions(array('database_details', 'table_prefix')); $tables = array('news' => 'id'); foreach ($tables as $table => $tableKey) { $tableName = $tablePrefix . $table; $tableColumns = \XLite\Core\Database::getEM()->getConnection()->getSchemaManager()->listTableColumns($tableName); $found = false; foreach (array_keys($tableColumns) as $column) { if (strtolower($column) == 'cleanurl') { $found = true; break; } } if ($found) { $items = array(); $query = 'SELECT ' . $tableKey . ', cleanURL FROM ' . $tableName; $result = \Includes\Utils\Database::fetchAll($query); if ($result) { foreach ($result as $data) { if ($data['cleanURL']) { $items[$data[$tableKey]] = $data['cleanURL']; } } if ($items) { \Includes\Utils\Operator::saveServiceYAML(LC_DIR_VAR . 'cleanURL.newsMessages.yaml', $items); } } } } };
/** * Parse PHP files and return plain array with the class descriptors * * @return array */ protected static function getClassesTreeIndex() { $index = array(); // Iterate over all directories with PHP class files foreach (static::getClassFileIterator()->getIterator() as $path => $data) { // Use PHP Tokenizer to search class declaration if (($class = \Includes\Decorator\Utils\Tokenizer::getFullClassName($path)) && \Includes\Utils\Operator::checkIfLCClass($class)) { // File contains a class declaration: create node (descriptor) $node = new \Includes\Decorator\DataStructure\Graph\Classes($class); // Check parent class (so called optional dependencies for modules) $dependencies = $node->getTag('lc_dependencies', true); if (empty($dependencies) || \Includes\Utils\ModulesManager::areActiveModules($dependencies)) { // Node is valid: add to the index $index[$class] = $node; } else { // The unused class file must be removed from the cache file structure \Includes\Utils\FileManager::deleteFile($node->getFile()); } } } return $index; }
/** * 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; }
/** * 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'); } }
/** * 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())); }
/** * Move registry info entry from ENABLED registry to the DISABLED one. * Module must be set as DISABLED in the DB after this operation * * @param string $module Module actual name * * @return boolean Flag if the registry entry was moved */ public static function moveModuleToDisabledRegistry($module) { $enabledPath = static::getEnabledStructurePath(); $enabledRegistry = \Includes\Utils\Operator::loadServiceYAML($enabledPath); $disabledPath = static::getDisabledStructuresPath(); $disabledRegistry = \Includes\Utils\Operator::loadServiceYAML($disabledPath); $result = false; if (isset($enabledRegistry[$module])) { $disabledRegistry[$module] = $enabledRegistry[$module]; unset($enabledRegistry[$module]); $result = true; } static::storeModuleRegistry($enabledPath, $enabledRegistry); static::storeModuleRegistry($disabledPath, $disabledRegistry); return $result; }
/** * Check if we can call method from the module main class * * @return boolean */ protected function checkModuleMainClass() { return $this->isInstalled() && \Includes\Utils\Operator::checkIfClassExists($this->getMainClass()); }
/** * 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'); } }
/** * Execute a set of SQL queries from file * * :FIXME: must be completely revised * * @param string $fileName Name of SQL-file * @param boolean $verbose Display uploading progress flag OPTIONAL * * @return boolean */ public static function uploadSQLFromFile($fileName, $verbose = false) { $result = false; if (false == \Includes\Utils\FileManager::isFileReadable($fileName)) { throw new \InvalidArgumentException(sprintf('SQL file \'%s\' not found or is not readable', $fileName)); } else { $fp = fopen($fileName, 'rb'); $sql = ''; $result = true; static::exec('SET NAMES utf8'); while ($result && !feof($fp)) { $c = ''; // Read SQL statement from file do { $c .= fgets($fp, 1024); $endPos = strlen($c) - 1; } while (substr($c, $endPos) != PHP_EOL && !feof($fp)); $c = rtrim($c); // Skip comments if (substr($c, 0, 1) == '#' || substr($c, 0, 2) == '--') { continue; } // Parse SQL statement $sql .= $c; if (substr($sql, -1) == ';') { $sql = substr($sql, 0, strlen($sql) - 1); $sql = str_replace(static::TABLE_PREFIX_PLACEHOLDER, static::getTablesPrefix(), $sql); // Execute SQL query try { static::getHandler()->beginTransaction(); $result = false !== static::exec($sql); if ($result) { static::getHandler()->commit(); } else { static::getHandler()->rollBack(); } if ($verbose) { \Includes\Utils\Operator::flush('.'); } } catch (\PDOException $e) { static::getHandler()->rollBack(); $result = false; \Includes\Utils\Operator::flush(LC_EOL . $e->getMessage()); } $sql = ''; } } fclose($fp); } return $result; }
*/ return function () { $tablePrefix = \XLite::getInstance()->getOptions(array('database_details', 'table_prefix')); $tables = array('products' => 'product_id', 'categories' => 'category_id'); foreach ($tables as $table => $tableKey) { $tableName = $tablePrefix . $table; $tableColumns = \XLite\Core\Database::getEM()->getConnection()->getSchemaManager()->listTableColumns($tableName); $found = false; foreach (array_keys($tableColumns) as $column) { if (strtolower($column) == 'cleanurl') { $found = true; break; } } if ($found) { $items = array(); $query = 'SELECT ' . $tableKey . ', cleanURL FROM ' . $tableName; $result = \Includes\Utils\Database::fetchAll($query); if ($result) { foreach ($result as $data) { if ($data['cleanURL']) { $items[$data[$tableKey]] = $data['cleanURL']; } } if ($items) { \Includes\Utils\Operator::saveServiceYAML(LC_DIR_VAR . 'cleanURL.' . $table . '.yaml', $items); } } } } };
/** * Check if we can call method from the module main class * * @return boolean */ public function checkModuleMainClass() { $result = $this->isInstalled(); if ($result && !\Includes\Utils\Operator::checkIfClassExists($this->getMainClass())) { if (defined('LC_MODULE_CONTROL')) { $path = LC_DIR_CLASSES . \Includes\Utils\Converter::getClassFile($this->getMainClass()); if (\Includes\Utils\FileManager::isFileReadable($path)) { require_once $path; } else { $result = false; } } else { $result = false; } } return $result; }
/** * Run an upgrade step * * @param string $method Upgrade cell method to call * @param array $params Call params OPTIONAL * * @return mixed */ protected function runStep($method, array $params = array()) { return \Includes\Utils\Operator::executeWithCustomMaxExecTime(\Includes\Utils\ConfigParser::getOptions(array('marketplace', 'upgrade_step_time_limit')), array(\XLite\Upgrade\Cell::getInstance(), $method), $params); }
/** * Get data storage service header * * @return string */ protected function getServiceHeader() { return \Includes\Utils\Operator::getServiceHeader(); }
/** * Preprocessor for no-action ren * * @return void */ protected function doNoAction() { \Includes\Utils\Operator::flush($this->getInfoMessage()); exit(0); }
/** * Process request * * @return void */ public function processRequest() { header('Content-Type: text/html; charset=utf-8'); \Includes\Utils\Operator::flush($this->getJSONData()); }
* to licensing@x-cart.com so we can send you a copy immediately. * * DISCLAIMER * * Do not modify this file if you wish to upgrade X-Cart to newer versions * in the future. If you wish to customize X-Cart for your needs please * refer to http://www.x-cart.com/ for more information. * * @category X-Cart 5 * @author Qualiteam software Ltd <*****@*****.**> * @copyright Copyright (c) 2011-2015 Qualiteam software Ltd <*****@*****.**>. All rights reserved * @license http://www.x-cart.com/license-agreement.html X-Cart 5 License Agreement * @link http://www.x-cart.com/ */ return function () { $data = \Includes\Utils\Operator::loadServiceYAML(LC_DIR_VAR . 'cleanURL.pages.yaml'); if ($data) { /** @var \XLite\Model\Repo\ARepo $repo */ $repo = \XLite\Core\Database::getRepo('XLite\\Module\\CDev\\SimpleCMS\\Model\\Page'); $iterator = $repo->getExportIterator(); $iterator->rewind(); while ($iterator->valid()) { /** @var \XLite\Model\AEntity $entity */ $entity = $iterator->current(); $entity = $entity[0]; if (!empty($data[$entity->getUniqueIdentifier()])) { $cleanURL = $data[$entity->getUniqueIdentifier()]; $entity->setCleanUrl($cleanURL . '.htm', true); $entity->setCleanUrl($cleanURL . '.html', true); \XLite\Core\Database::getEM()->flush(); \XLite\Core\Database::getEM()->clear();
/** * Common restore database method used by actions * * @param mixed $sqlFile File with SQL data for loading into database * * @return boolean */ protected function restoreDatabase($sqlFile) { $result = false; // File to create temporary backup to be able rollback database $backupSQLFile = LC_DIR_BACKUP . sprintf('sqldump.backup.%d.sql', \XLite\Core\Converter::time()); // Make the process of restoring database verbose $verbose = true; // Start $this->startDump(); // Making the temporary backup file \Includes\Utils\Operator::flush(static::t('Making backup of the current database state ... '), true); $result = \XLite\Core\Database::getInstance()->exportSQLToFile($backupSQLFile, $verbose); \Includes\Utils\Operator::flush(static::t('done') . LC_EOL . LC_EOL, true); // Loading specified SQL-file to the database \Includes\Utils\Operator::flush(static::t('Loading the database from file .')); $result = \Includes\Utils\Database::uploadSQLFromFile($sqlFile, $verbose); $restore = false; if ($result) { // If file has been loaded into database successfully $message = static::t('Database restored successfully!'); // Prepare the cache rebuilding \XLite::setCleanUpCacheFlag(true); } else { // If an error occured while loading file into database $message = static::t('The database has not been restored because of the errors'); $restore = true; } // Display the result message \Includes\Utils\Operator::flush(' ' . static::t('done') . LC_EOL . LC_EOL . $message . LC_EOL); if ($restore) { // Restore database from temporary backup \Includes\Utils\Operator::flush(LC_EOL . static::t('Restoring database from the backup .')); \Includes\Utils\Database::uploadSQLFromFile($backupSQLFile, $verbose); \Includes\Utils\Operator::flush(' ' . static::t('done') . LC_EOL . LC_EOL); } // Display Javascript to cancel scrolling page to bottom func_refresh_end(); // Display the bottom HTML part $this->displayPageFooter(); // Remove temporary backup file unlink($backupSQLFile); return $result; }