Exemplo n.º 1
0
 /**
  * Unpack PHAR archive
  *
  * @param string $file File path
  * @param string $dir  Dir to extract to
  *
  * @return string
  */
 public static function unpack($file, $dir)
 {
     $dir = \Includes\Utils\FileManager::getCanonicalDir($dir) . pathinfo($file, PATHINFO_FILENAME);
     try {
         $phar = new \PharData($file);
         $result = $phar->extractTo($dir, null, true);
     } catch (\Exception $exception) {
         $result = false;
         \XLite\Upgrade\Logger::getInstance()->logError($exception->getMessage());
     }
     return array($dir, $result);
 }
Exemplo n.º 2
0
 /**
  * Show log file content
  *
  * @return void
  */
 protected function doActionViewLogFile()
 {
     $path = \XLite\Upgrade\Logger::getInstance()->getLastLogFile();
     if ($path) {
         header('Content-Type: text/plain', true);
         \Includes\Utils\Operator::flush(\Includes\Utils\FileManager::read($path));
         exit(0);
     } else {
         \XLite\Core\TopMessage::addWarning('Log files not found');
     }
 }
Exemplo n.º 3
0
 /**
  * Common logging procedure
  *
  * @param string $method  Method to call
  * @param string $action  Current request action
  * @param string $message Message to log
  * @param array  $args    Message args OPTIONAL
  * @param array  $data    Data sent/received OPTIONAL
  *
  * @return void
  */
 protected function logCommon($method, $action, $message, array $args = array(), array $data = array())
 {
     $message = 'Marketplace [' . $action . ']: ' . lcfirst($message);
     if (!empty($data) && \Includes\Utils\ConfigParser::getOptions(array('marketplace', 'log_data'))) {
         $message .= '; data: ' . PHP_EOL . '{{data}}';
         $args += array('data' => print_r($data, true));
     }
     \XLite\Upgrade\Logger::getInstance()->{'log' . $method}($message, $args, false);
 }
Exemplo n.º 4
0
 /**
  * We send the free license activation key
  *
  * @return void
  */
 protected function doActivateFreeLicense()
 {
     $info = \XLite\Core\Marketplace::getInstance()->activateFreeLicense(\XLite\Core\Request::getInstance()->email);
     if (\XLite\Core\Marketplace::getInstance()->getError()) {
         // Marketplace returned an error
         $message = \XLite\Core\Marketplace::getInstance()->getError();
         if (\XLite\Core\Marketplace::ERROR_CODE_FREE_LICENSE_REGISTERED == \XLite\Core\Marketplace::getInstance()->getLastErrorCode()) {
             // Free license is already registered: prepare specific error message
             $message = static::t('Free license key for this email is already registered', array('email' => \XLite\Core\Request::getInstance()->email, 'url' => $this->buildURL('activate_free_license', 'resend_key', array('email' => \XLite\Core\Request::getInstance()->email))));
         }
         \XLite\Core\TopMessage::addError($message);
     } elseif ($info && isset($info[\XLite\Core\Marketplace::XC_FREE_LICENSE_KEY])) {
         // License key is successfully activated: register the key in database
         $key = $info[\XLite\Core\Marketplace::XC_FREE_LICENSE_KEY][0];
         // Get key value from the response field 'key' or (if empty) use default value
         $keyValue = !empty($key[\XLite\Core\Marketplace::FIELD_KEY]) ? $key[\XLite\Core\Marketplace::FIELD_KEY] : \XLite\Core\Marketplace::XC_FREE_LICENSE_KEY;
         \XLite\Core\Database::getRepo('\\XLite\\Model\\ModuleKey')->insert($key + array('keyValue' => $keyValue));
         // Clear cache for proper installation
         \XLite\Core\Marketplace::getInstance()->clearActionCache(\XLite\Core\Marketplace::ACTION_GET_ADDONS_LIST);
         // Search for modules from non-free edition
         $nonFreeModules = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->getNonFreeEditionModulesList(false);
         if ($nonFreeModules) {
             // Try to uninstall these modules...
             foreach ($nonFreeModules as $module) {
                 $messages = array();
                 $res = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->uninstallModule($module, $messages);
                 if ($messages) {
                     foreach ($messages as $message) {
                         $method = $res ? 'Info' : 'Error';
                         \XLite\Upgrade\Logger::getInstance()->{'log' . $method}($message, array(), false);
                     }
                 }
             }
             // Initialize rebuild cache routine as a next step
             \XLite::setCleanUpCacheFlag(true);
         }
         \XLite\Core\TopMessage::addInfo('Free license is activated successfully');
         $this->setReturnURL($this->buildURL());
     } else {
         \XLite\Core\TopMessage::addError('Can\'t connect to the marketplace server');
     }
 }
Exemplo n.º 5
0
 /**
  * Add new message
  *
  * @param string  $method  Logger method to call
  * @param string  $message Message to add
  * @param boolean $log     Flag
  * @param array   $args    Substitution arguments OPTIONAL
  *
  * @return void
  */
 protected function addMessage($method, $message, $log, array $args = array())
 {
     // It's a quite common case
     $args += array(self::TOKEN_ENTRY => $this->getActualName());
     // Write message to the log (if needed)
     if (!empty($log)) {
         \XLite\Upgrade\Logger::getInstance()->{'log' . $method}($message, $args, false);
     }
 }
Exemplo n.º 6
0
 /**
  * Perform upgrade
  *
  * @param boolean $isTestMode       Flag OPTIONAL
  * @param array   $filesToOverwrite List of custom files to overwrite OPTIONAL
  *
  * @return boolean
  */
 public function upgrade($isTestMode = true, array $filesToOverwrite = array())
 {
     $result = false;
     if (!$this->isUnpacked()) {
         \XLite\Upgrade\Logger::getInstance()->logError('Trying to perform upgrade while not all archives were unpacked');
     } else {
         if (!$isTestMode) {
             $this->preloadLibraries();
         }
         $this->runHelpers('pre_upgrade', $isTestMode);
         foreach ($this->getEntries() as $entry) {
             $entry->upgrade($isTestMode, $filesToOverwrite);
         }
         $this->runHelpers('post_upgrade', $isTestMode);
         $result = $this->isValid();
     }
     return $result;
 }
Exemplo n.º 7
0
 /**
  * Log upgrade info and show top message
  *
  * @param string $method  Method to call
  * @param string $action  Current action
  * @param string $message Message to log and show
  * @param array  $args    Arguments to substitute
  *
  * @return void
  */
 protected function showCommon($method, $action, $message, array $args)
 {
     if (null === $message) {
         $message = static::t(implode('; ', \XLite\Upgrade\Cell::getInstance()->getErrorMessages())) ?: static::t('unknown error');
     }
     if (null !== $action && LC_DEVELOPER_MODE) {
         $message = static::t('Action X::Y, M', array('class' => get_class($this), 'action' => $action, 'message' => $message));
     }
     \XLite\Upgrade\Logger::getInstance()->{'log' . $method}($message, $args, true);
 }
Exemplo n.º 8
0
 /**
  * Action of license key registration
  *
  * @return void
  */
 protected function doActionRegisterKey()
 {
     $key = \XLite\Core\Request::getInstance()->key;
     if ($key) {
         $keysInfo = \XLite\Core\Marketplace::getInstance()->checkAddonKey($key);
     } else {
         $keysInfo = null;
         $emptyKey = true;
     }
     $this->setReturnURL($this->buildURL('addons_list_marketplace'));
     if ($keysInfo && $keysInfo[$key]) {
         $keysInfo = $keysInfo[$key];
         $repo = \XLite\Core\Database::getRepo('\\XLite\\Model\\ModuleKey');
         foreach ($keysInfo as $info) {
             if (\XLite\Model\ModuleKey::KEY_TYPE_XCN == $info['keyType']) {
                 $xcnPlan = $info['xcnPlan'];
                 $keyData = $info['keyData'];
                 // Unset some fields which is not in database
                 unset($info['xcnPlan']);
                 unset($info['keyData']);
                 unset($info['key']);
                 $entity = $repo->findOneBy($info);
                 if (!$entity) {
                     $entity = new \XLite\Model\ModuleKey();
                     $entity->map($info);
                 }
                 $entity->setKeyValue($key);
                 $entity->setXcnPlan($xcnPlan);
                 $entity->setKeyData($keyData);
                 if (!empty($keyData['wave'])) {
                     $this->updateUpgradeWaveOption($keyData['wave']);
                 }
                 $isValid = true;
                 if (\XLite::isFreeLicense($entity)) {
                     if (0 == \XLite\Core\Database::getRepo('XLite\\Model\\Module')->hasMarketplaceModules(true)) {
                         $isValid = false;
                         $this->showError(__FUNCTION__, static::t('Cannot gather modules from the marketplace. Please try later.'));
                     }
                 }
                 if ($isValid) {
                     // Save entity (key) in the database
                     \XLite\Core\Database::getEM()->persist($entity);
                     \XLite\Core\Database::getEM()->flush();
                     if (\XLite::isFreeLicense()) {
                         // Search for modules from non-free edition
                         $nonFreeModules = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->getNonFreeEditionModulesList(false);
                         if ($nonFreeModules) {
                             // Try to uninstall these modules...
                             foreach ($nonFreeModules as $module) {
                                 $messages = array();
                                 $res = \XLite\Core\Database::getRepo('XLite\\Model\\Module')->uninstallModule($module, $messages);
                                 if ($messages) {
                                     foreach ($messages as $message) {
                                         $method = $res ? 'Info' : 'Error';
                                         \XLite\Upgrade\Logger::getInstance()->{'log' . $method}($message, array(), false);
                                     }
                                 }
                             }
                         }
                         \XLite::setCleanUpCacheFlag(true);
                     }
                     if (empty($keyData['message'])) {
                         $this->showInfo(__FUNCTION__, static::t('X-Cart license key has been successfully verified'));
                     } else {
                         $this->showWarning(__FUNCTION__, static::t('X-Cart license key has been successfully verified and activated. But this key has expired and do not allow upgrade store.'));
                     }
                     // Clear cache for proper installation
                     \XLite\Core\Marketplace::getInstance()->clearActionCache(\XLite\Core\Marketplace::ACTION_GET_ADDONS_LIST);
                     $this->setHardRedirect();
                 }
             } else {
                 $keyData = $info['keyData'];
                 $module = \XLite\Core\Database::getRepo('\\XLite\\Model\\Module')->findOneBy(array('author' => $info['author'], 'name' => $info['name']));
                 if ($module) {
                     $entity = $repo->findKey($info['author'], $info['name']);
                     if ($entity) {
                         $entity->setKeyValue($key);
                         $repo->update($entity);
                     } else {
                         $entity = $repo->insert($info + array('keyValue' => $key));
                     }
                     if (!empty($keyData['wave'])) {
                         $this->updateUpgradeWaveOption($keyData['wave']);
                     }
                     // Clear cache for proper installation
                     \XLite\Core\Marketplace::getInstance()->clearActionCache(\XLite\Core\Marketplace::ACTION_GET_ADDONS_LIST);
                     if (empty($keyData['message'])) {
                         $this->showInfo(__FUNCTION__, static::t('License key has been successfully verified for "{{name}}" module by "{{author}}" author', array('name' => $module->getModuleName(), 'author' => $module->getAuthorName())));
                     } else {
                         $this->showWarning(__FUNCTION__, static::t('License key has been successfully verified and activated for "{{name}}" module by "{{author}}" author. But this key has expired and do not allow upgrade store.', array('name' => $module->getModuleName(), 'author' => $module->getAuthorName())));
                     }
                     // We install the addon after the successfull key verification
                     $this->setReturnURL($this->buildURL('upgrade', 'install_addon_force', array('moduleIds[]' => $module->getModuleID(), 'agree' => 'Y')));
                 } else {
                     $this->showError(__FUNCTION__, static::t('Key is validated, but the module X was not found', array('module' => implode(',', $info))));
                 }
             }
         }
     } elseif (!isset($emptyKey)) {
         $error = \XLite\Core\Marketplace::getInstance()->getError();
         $message = $error ? static::t('Response from marketplace: X', array('response' => $error)) : static::t('Response from marketplace is not received');
         $this->showError(__FUNCTION__, $message);
     } else {
         $this->showError(__FUNCTION__, static::t('Please specify non-empty key'));
     }
 }
Exemplo n.º 9
0
 /**
  * Log upgrade info and show top message
  *
  * @param string $method  Method to call
  * @param string $action  Current action
  * @param string $message Message to log and show
  * @param array  $args    Arguments to subsistute
  *
  * @return void
  */
 protected function showCommon($method, $action, $message, array $args)
 {
     if (!isset($message)) {
         $message = implode('; ', \XLite\Upgrade\Cell::getInstance()->getErrorMessages()) ?: 'unknown error';
     }
     if (isset($action) && LC_DEVELOPER_MODE) {
         $message = 'Action "' . get_class($this) . '::' . $action . '", ' . lcfirst($message);
     }
     \XLite\Upgrade\Logger::getInstance()->{'log' . $method}($message, $args, true);
 }