/** * Check if the license is free * * @return boolean */ protected static function restoreToPoint($restorePoint) { $modules = array(); $active = static::getActiveModules(); foreach ($active as $key => $module) { $toDisable = true; foreach ($restorePoint['current'] as $id => $moduleName) { if ($moduleName != null && $key === $moduleName) { $moduleName = null; $toDisable = false; break; } } if ($toDisable) { $modules[] = $key; } } //modules to enable $toEnable = array(); $installed = static::getModulesList(); foreach ($restorePoint['current'] as $id => $moduleName) { $isInstalled = array_key_exists($moduleName, $installed); $isActive = array_key_exists($moduleName, $active); if ($isInstalled && !$isActive) { $toEnable[] = $moduleName; } } // Enable modules array_walk($toEnable, array('static', 'enableModule')); // Disable modules array_walk($modules, array('static', 'disableModule')); $date = \DateTime::createFromFormat(static::RESTORE_DATE_FORMAT, $restorePoint["date"]); \Includes\Decorator\Utils\PersistentInfo::set('restoredTo', $date->getTimestamp()); $restorationRecord = static::getRestorationRecord($restorePoint["date"]); static::updateModuleMigrationLog($restorationRecord); }
/** * 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'); } }
/** * Disable some (or all) modules in SafeMode * * @return void */ protected static function performSafeModeProtection() { if (\Includes\SafeMode::isSafeModeStarted()) { if (!\Includes\SafeMode::isRestoreDateSet()) { // Get unsafe modules list $modules = \Includes\SafeMode::isSoftResetRequested() ? \Includes\SafeMode::getUnsafeModulesList() : array_keys(static::$activeModules); } else { $restorePoint = static::getRestorePoint(\Includes\SafeMode::getRestoreDate()); if (!empty($restorePoint)) { //modules to disable $modules = array(); $active = static::getActiveModules(); foreach ($active as $key => $module) { $toDisable = true; foreach ($restorePoint['current'] as $id => $moduleName) { if ($moduleName != null && $key === $moduleName) { $moduleName = null; $toDisable = false; break; } } if ($toDisable) { $modules[] = $key; } } //modules to enable $toEnable = array(); $installed = static::getModulesList(); foreach ($restorePoint['current'] as $id => $moduleName) { $isInstalled = array_key_exists($moduleName, $installed); $isActive = array_key_exists($moduleName, $active); if ($isInstalled && !$isActive) { $toEnable[] = $moduleName; } } // Enable modules array_walk($toEnable, array('static', 'enableModule')); $date = \DateTime::createFromFormat(static::RESTORE_DATE_FORMAT, $restorePoint["date"]); \Includes\Decorator\Utils\PersistentInfo::set('restoredTo', $date->getTimestamp()); $restorationRecord = static::getRestorationRecord($restorePoint["date"]); static::updateModuleMigrationLog($restorationRecord); } } // Disable modules array_walk($modules, array('static', 'disableModule')); \Includes\SafeMode::cleanupIndicator(); } }