Exemple #1
0
 /**
  * Perform upgrade
  *
  * @param boolean    $isTestMode       Flag OPTIONAL
  * @param array|null $filesToOverwrite List of custom files to overwrite OPTIONAL
  *
  * @return void
  */
 public function upgrade($isTestMode = true, $filesToOverwrite = null)
 {
     parent::upgrade($isTestMode, $filesToOverwrite);
     if (!$isTestMode) {
         list($author, $name) = explode('\\', $this->getActualName());
         if (!$this->isValid()) {
             \Includes\SafeMode::markModuleAsUnsafe($author, $name);
         }
         // Load fixtures
         if (!$this->isInstalled()) {
             $yaml = \Includes\Utils\ModulesManager::getModuleYAMLFile($author, $name);
             if (\Includes\Utils\FileManager::isFileReadable($yaml)) {
                 \XLite\Core\Database::getInstance()->loadFixturesFromYaml($yaml);
             }
         }
         $this->updateDBRecords();
     }
 }
Exemple #2
0
 /**
  * Third step: install downloaded upgrades
  *
  * @return void
  */
 protected function doActionInstallUpgrades()
 {
     $this->setReturnURL($this->buildURL('upgrade'));
     if (\XLite\Upgrade\Cell::getInstance()->isUnpacked()) {
         if (!$this->isForce()) {
             \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();
             }
             \XLite\Upgrade\Cell::getInstance()->initUpgradeHooks();
             $this->setReturnURL($this->buildURL('upgrade', 'pre_upgrade_hooks', $this->getActionParamsCommon()));
         } 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'));
         }
         \Includes\Utils\ModulesManager::updateModuleMigrationLog($restorePoint);
     } else {
         $this->showWarning(__FUNCTION__, static::t('unable to install: not all archives were unpacked. Please, try again', array('list' => $this->getErrorEntriesHTML())));
     }
 }
Exemple #3
0
 /**
  * Email safe mode links to the site administrator
  *
  * @return void
  */
 public function doActionEmailLinks()
 {
     \Includes\SafeMode::sendNotification();
     \XLite\Core\TopMessage::addInfo('Safe mode links were emailed');
     $this->setPureAction(true);
 }
Exemple #4
0
 /**
  * Get Soft Reset URL
  *
  * @return string
  */
 public function getSoftResetURL()
 {
     return \Includes\SafeMode::getResetURL(true);
 }
Exemple #5
0
 /**
  * Perform upgrade
  *
  * @param boolean    $isTestMode       Flag OPTIONAL
  * @param array|null $filesToOverwrite List of custom files to overwrite OPTIONAL
  *
  * @return void
  */
 public function upgrade($isTestMode = true, $filesToOverwrite = null)
 {
     parent::upgrade($isTestMode, $filesToOverwrite);
     if (!$isTestMode) {
         list($author, $name) = explode('\\', $this->getActualName());
         if (!$this->isValid()) {
             \Includes\SafeMode::markModuleAsUnsafe($author, $name);
         }
         $this->updateDBRecords();
     }
 }
Exemple #6
0
/**
 * Do some final actions
 *
 * @param array  $params     Database access data and other parameters
 * @param bool   $silentMode Do not display any output during installing
 *
 * @return bool
 */
function doFinishInstallation(&$params, $silentMode = false)
{
    global $lcSettings, $error;
    $result = true;
    // Update config settings
    update_config_settings($params);
    generate_safe_mode_key();
    // Save authcode for the further install runs
    $authcode = save_authcode($params);
    $install_name = rename_install_script();
    if ($install_name) {
        // Text for email notification
        $install_rename_email = xtr('script_renamed_text', array(':newname' => $install_name, ':host' => $params['xlite_http_host'], ':webdir' => $params['xlite_web_dir']));
        // Text for confirmation web page
        $install_rename = xtr('script_renamed_text_html', array(':newname' => $install_name));
    } else {
        $install_rename = xtr('script_cannot_be_renamed_text');
        $install_rename_email = strip_tags($install_rename);
    }
    // Prepare files permissions recommendation text
    $perms = '';
    if (!LC_OS_IS_WIN) {
        $_perms = array();
        if (@is_writable(LC_DIR_ROOT)) {
            $_perms[] = 'chmod 755 ' . LC_DIR_ROOT;
        }
        if (@is_writable(LC_DIR_CONFIG)) {
            $_perms[] = 'chmod 755 ' . LC_DIR_CONFIG;
        }
        if (@is_writable(LC_DIR_CONFIG . constant('LC_CONFIG_FILE'))) {
            $_perms[] = "chmod 644 " . LC_DIR_CONFIG . constant('LC_CONFIG_FILE');
        }
        if (@is_writable(LC_DIR_ROOT . '.htaccess')) {
            $_perms[] = "chmod 644 " . LC_DIR_ROOT . '.htaccess';
        }
        if (!empty($_perms)) {
            $perms = implode("<br />\n", $_perms);
            $perms = xtr('correct_permissions_text', array(':perms' => $perms));
        }
    }
    // Prepare email notification text
    $perms_no_tags = strip_tags($perms);
    $message = xtr('congratulations_text', array(':host' => $params['xlite_http_host'], ':webdir' => $params['xlite_web_dir'], ':login' => $params['login'], ':password' => $params['password'], ':perms' => $perms_no_tags, ':renametext' => $install_rename_email, ':authcode' => $authcode, ':safekey' => \Includes\SafeMode::getAccessKey()));
    // Send email notification to the admin account email
    @mail($params["login"], "X-Cart installation complete", $message, "From: \"X-Cart software\" <" . $params["login"] . ">\r\n" . "X-Mailer: PHP");
    if (!$silentMode) {
        ?>

<script type="text/javascript">
  document.cookie = 'xcInstallComplete=1';
  document.cookie = 'xcInstallStarted=; expires=-1';
  document.cookie = 'passed_steps=; expires=-1';
</script>

<br />
<br />

<div class="field-label"><?php 
        echo xtr('X-Cart software has been successfully installed and is now available at the following URLs:');
        ?>
</div>
<img src="//www.x-cart.com/img/spacer2.gif" width="1" height="1" alt="" />

<br />

<a href="cart.php" class="final-link" target="_blank"><?php 
        echo xtr('Customer zone (front-end)');
        ?>
: cart.php</a>

<br />
<br />

<a href="admin.php" class="final-link" target="_blank"><?php 
        echo xtr('Administrator zone (backoffice)');
        ?>
: admin.php</a>

<br />
<br />
<br />

<?php 
        echo $perms;
        ?>

<br />
<br />

<?php 
        echo $install_rename;
        ?>

<?php 
        echo xtr('Your auth code for running install.php in the future is:');
        ?>
 <code><?php 
        echo get_authcode();
        ?>
</code>

<br />

<?php 
        echo xtr('PLEASE WRITE THIS CODE DOWN UNLESS YOU ARE GOING TO REMOVE ":filename"', array(':filename' => $install_name));
        ?>

<?php 
    }
    x_install_log(xtr('Installation complete'));
    return $result;
}
Exemple #7
0
 /**
  * Get an action URL
  *
  * @return string
  */
 protected function getHardResetURL()
 {
     return \Includes\SafeMode::getResetURL(false);
 }
Exemple #8
0
 /**
  * Re-generate safe mode access key
  *
  * @return void
  */
 public function doActionSafeModeKeyRegen()
 {
     \Includes\SafeMode::regenerateAccessKey(true);
     \XLite\Core\TopMessage::addInfo('Safe mode access key has been re-generated');
     $this->setReturnURL($this->buildURL($this->get('target')));
 }
Exemple #9
0
 /**
  * Send notification about generated safe mode access key
  *
  * @param string $key Access key
  *
  * @return void
  */
 public static function sendSafeModeAccessKeyNotification($key)
 {
     // Register variables
     static::register('key', $key);
     static::register('hard_reset_url', \Includes\SafeMode::getResetURL());
     static::register('soft_reset_url', \Includes\SafeMode::getResetURL(true));
     static::register('article_url', \XLite::getController()->getArticleURL());
     static::compose(static::TYPE_SAFE_MODE_ACCESS_KEY, static::getSiteAdministratorMail(), static::getSiteAdministratorMail(), 'safe_mode_key_generated', array(), true, \XLite::ADMIN_INTERFACE, static::getMailer()->getLanguageCode(\XLite::ADMIN_INTERFACE));
 }
Exemple #10
0
 /**
  * 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() ? static::getSoftDisableList() : static::getHardDisableList();
             // Disable modules
             array_walk($modules, array('static', 'disableModule'));
         } else {
             $restorePoint = static::getRestorePoint(\Includes\SafeMode::getRestoreDate());
             if (static::isRestorePointValid($restorePoint)) {
                 //modules to disable
                 static::restoreToPoint($restorePoint);
             }
         }
         \Includes\SafeMode::cleanupIndicator();
     }
 }
Exemple #11
0
 /**
  * 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())));
     }
 }
Exemple #12
0
define('LC_DIR_CACHE_IMAGES', LC_DIR_VAR . 'images' . LC_DS);
define('LC_DIR_SERVICE', LC_DIR_FILES . 'service' . LC_DS);
define('LC_OS_WINDOWS', 'WIN' === strtoupper(substr(PHP_OS, 0, 3)));
// Disabled xdebug coverage for Selenium-based tests [DEVELOPMENT PURPOSE]
if (isset($_COOKIE) && !empty($_COOKIE['no_xdebug_coverage']) && function_exists('xdebug_stop_code_coverage')) {
    @xdebug_stop_code_coverage();
}
// Autoloading routines
require_once LC_DIR_INCLUDES . 'Autoloader.php';
\Includes\Autoloader::registerAll();
// Fire the error if LC is not installed
if (!defined('XLITE_INSTALL_MODE')) {
    \Includes\ErrorHandler::checkIsLCInstalled();
}
// So called "developer" mode. Set it to "false" in production mode!
define('LC_DEVELOPER_MODE', (bool) \Includes\Utils\ConfigParser::getOptions(array('performance', 'developer_mode')));
// Correct error handling mode
ini_set('display_errors', LC_DEVELOPER_MODE);
// Fatal error and exception handlers
register_shutdown_function(array('\\Includes\\ErrorHandler', 'shutdown'));
set_exception_handler(array('\\Includes\\ErrorHandler', 'handleException'));
@umask(00);
require_once LC_DIR_INCLUDES . 'prepend.php';
// Safe mode
if (!defined('XLITE_INSTALL_MODE')) {
    \Includes\SafeMode::initialize();
}
// Check and (if needed) rebuild classes cache
if (!defined('LC_DO_NOT_REBUILD_CACHE')) {
    \Includes\Decorator\Utils\CacheManager::rebuildCache();
}
Exemple #13
0
 /**
  * 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();
     }
 }
Exemple #14
0
 /**
  * Send notification about generated safe mode access key
  *
  * @param string $key Access key
  *
  * @return void
  */
 public static function sendSafeModeAccessKeyNotification($key)
 {
     static::setMailInterface(\XLite::ADMIN_INTERFACE);
     // Register variables
     static::register('key', $key);
     static::register('hard_reset_url', \Includes\SafeMode::getResetURL());
     static::register('soft_reset_url', \Includes\SafeMode::getResetURL(true));
     static::compose(\XLite\Core\Config::getInstance()->Company->site_administrator, \XLite\Core\Config::getInstance()->Company->site_administrator, 'safe_mode_key_generated');
 }
Exemple #15
0
 /**
  * is current snapshot available
  *
  * @return boolean
  */
 public function isCurrentSnapshotAvailable()
 {
     return (bool) \Includes\SafeMode::getLatestSnapshot();
 }