/** * doActionStartExpressCheckout * * @return void */ protected function doActionStartExpressCheckout() { if (Paypal\Main::isExpressCheckoutEnabled()) { $paymentMethod = $this->getExpressCheckoutPaymentMethod(); $this->getCart()->setPaymentMethod($paymentMethod); $this->updateCart(); \XLite\Core\Session::getInstance()->ec_type = Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT; $processor = $paymentMethod->getProcessor(); $token = $processor->doSetExpressCheckout($paymentMethod); if (isset($token)) { \XLite\Core\Session::getInstance()->ec_token = $token; \XLite\Core\Session::getInstance()->ec_date = \XLite\Core\Converter::time(); \XLite\Core\Session::getInstance()->ec_payer_id = null; $processor->redirectToPaypal($token); exit; } else { if (\XLite\Core\Request::getInstance()->inContext) { \XLite\Core\Session::getInstance()->cancelUrl = \XLite\Core\Request::getInstance()->cancelUrl; \XLite\Core\Session::getInstance()->inContextRedirect = true; $this->setReturnURL($this->buildURL('checkout_failed')); } \XLite\Core\TopMessage::getInstance()->addError($processor->getErrorMessage() ?: 'Failure to redirect to PayPal.'); } } }
/** * doActionBackup * * @return void */ protected function doActionBackup() { $destFile = LC_DIR_BACKUP . sprintf('sqldump.backup.%d.sql', \XLite\Core\Converter::time()); $this->startDownload('db_backup.sql'); // Make database backup and store it in $this->sqldumpFile file \XLite\Core\Database::getInstance()->exportSQLToFile($destFile, false); readfile($destFile); \Includes\Utils\FileManager::deleteFile($destFile); exit; }
/** * Get default options * * @return array */ protected function getDefaultOptions() { $time = \XLite\Core\Converter::time(); $allowedDateFormats = \XLite\Core\Converter::getAvailableDateFormats(); $options = array(); foreach ($allowedDateFormats as $phpFormat => $formats) { $options[$phpFormat] = \XLite\Core\Converter::formatDate($time, $phpFormat); } return $options; }
/** * Measure enviroment * * @param boolean $force Force run OPTIONAL * * @return boolean */ public function measure($force = false) { $result = false; if ($force || $this->checkAccess()) { set_time_limit(0); $measure = new \XLite\Model\Measure(); $measure->setDate(\XLite\Core\Converter::time()); $measure->setFsTime(intval($this->measureFilesystem() * 1000)); $measure->setDbTime(intval($this->measureDatabase() * 1000)); $measure->setCpuTime(intval($this->measureComputation() * 1000)); \XLite\Core\Database::getEM()->persist($measure); \XLite\Core\Database::getEM()->flush(); $result = true; } return $result; }
/** * Register event to the order * * @param integer $orderId Order identificator * @param string $code Event code * @param string $description Event description * @param array $data Data for event description OPTIONAL * @param string $comment Event comment OPTIONAL * @param array $details Event details OPTIONAL * * @return void */ public function registerEvent($orderId, $code, $description, array $data = array(), $comment = '', $details = array()) { $order = \XLite\Core\Database::getRepo('XLite\\Model\\Order')->find($orderId); if (!$order->isRemoving()) { $event = new \XLite\Model\OrderHistoryEvents(array('date' => \XLite\Core\Converter::time(), 'code' => $code, 'description' => $description, 'data' => $data, 'comment' => $comment)); if (!empty($details)) { $event->setDetails($details); } if (\XLite\Core\Auth::getInstance()->getProfile()) { $event->setAuthor(\XLite\Core\Auth::getInstance()->getProfile()); } $event->setOrder($order); $order->addEvents($event); $this->insert($event); } }
/** * 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; }
/** * Preprocessor for no-action * * @return void */ protected function doNoAction() { $this->startTime = time(); $this->startMemory = memory_get_usage(true); $this->memoryLimitIni = \XLite\Core\Converter::convertShortSize(ini_get('memory_limit') ?: '16M'); foreach (\XLite\Core\Database::getRepo('XLite\\Model\\Task')->findAll() as $task) { if (!$task->isExpired()) { continue; } $runner = $task->getOwnerInstance(); if ($runner) { $this->runRunner($runner); } sleep($this->sleepTime); if (!$this->checkThreadResource()) { $time = gmdate('H:i:s', \XLite\Core\Converter::time() - $this->startTime); $memory = \XLite\Core\Converter::formatFileSize(memory_get_usage(true)); $this->printContent('Step is interrupted (time: ' . $time . '; memory usage: ' . $memory . ')'); break; } } }
/** * Return time left to unlock * * @return integer */ protected function getTimeLeftToUnlock() { if (!isset($this->timeLeftToUnlock)) { $this->timeLeftToUnlock = \XLite\Core\Session::getInstance()->dateOfLockLogin ? \XLite\Core\Session::getInstance()->dateOfLockLogin + \XLite\Core\Auth::TIME_OF_LOCK_LOGIN - \XLite\Core\Converter::time() : 0; } return $this->timeLeftToUnlock; }
/** * Check - is tracking data are expired or not * * @return boolean */ public function isExpired() { return \XLite\Core\Converter::time() > $this->getExpiry(); }
/** * Get posted data * * @param string $field Name of the field to retrieve OPTIONAL * * @return mixed */ protected function getPostedData($field = null) { $value = parent::getPostedData($field); $time = \XLite\Core\Converter::time(); if (!isset($field)) { if (isset($value['arrivalDate'])) { $value['arrivalDate'] = intval(strtotime($value['arrivalDate'])) ?: mktime(0, 0, 0, date('m', $time), date('j', $time), date('Y', $time)); } if (isset($value['sku']) && \XLite\Core\Converter::isEmptyString($value['sku'])) { $value['sku'] = null; } if (isset($value['productClass'])) { $value['productClass'] = \XLite\Core\Database::getRepo('\\XLite\\Model\\ProductClass')->find($value['productClass']); } if (isset($value['taxClass'])) { $value['taxClass'] = \XLite\Core\Database::getRepo('\\XLite\\Model\\TaxClass')->find($value['taxClass']); } } elseif ('arrivalDate' === $field) { $value = intval(strtotime($value)) ?: mktime(0, 0, 0, date('m', $time), date('j', $time), date('Y', $time)); } elseif ('sku' === $field) { $value = null; } elseif ('productClass' === $field) { $value = \XLite\Core\Database::getRepo('\\XLite\\Model\\ProductClass')->find($value); } elseif ('taxClass' === $field) { $value = \XLite\Core\Database::getRepo('\\XLite\\Model\\TaxClass')->find($value); } return $value; }
/** * Defines if the promo banner is active or expired * Banner is active if no expiration date is defined ('' value) * or the expiration date is greater than current time * * @param string $date Date * * @return boolean */ protected function isPromoBannerActive($date) { $timestamp = strtotime($date); return '' === $date || \XLite\Core\Converter::time() < $timestamp; }
/** * Prepare creation date * * @return void * * @PrePersist */ public function prepareBeforeCreate() { // Assign a profile creation date/time if (!$this->getAdded()) { $this->setAdded(\XLite\Core\Converter::time()); } // Assign current language $language = $this->getLanguage(true); if (empty($language)) { $this->setLanguage(\XLite\Core\Session::getInstance()->getLanguage()->getCode()); } // Assign referer value if (empty($this->referer)) { if (\XLite\Core\Auth::getInstance()->isAdmin()) { $currentlyLoggedInProfile = \XLite\Core\Auth::getInstance()->getProfile(); $this->setReferer(sprintf('Created by administrator (%s)', $currentlyLoggedInProfile->getLogin())); } elseif (isset($_COOKIE[\XLite\Core\Session::LC_REFERER_COOKIE_NAME])) { $this->setReferer($_COOKIE[\XLite\Core\Session::LC_REFERER_COOKIE_NAME]); } } // Assign status 'Enabled' if not defined if (empty($this->status)) { $this->enable(); } }
/** * Initialize search parameters from request data * * @return void */ protected function prepareSearchParams() { $ordersSearch = array(); // Prepare dates $this->startDate = $this->getDateValue('startDate'); $this->endDate = $this->getDateValue('endDate', true); if (0 === $this->startDate || 0 === $this->endDate || $this->startDate > $this->endDate) { $date = getdate(\XLite\Core\Converter::time()); $this->startDate = mktime(0, 0, 0, $date['mon'], 1, $date['year']); $this->endDate = mktime(0, 0, 0, $date['mon'], $date['mday'], $date['year']); } foreach ($this->getSearchParams() as $modelParam => $requestParam) { if (\XLite\Model\Repo\Order::P_DATE === $requestParam) { $ordersSearch[$requestParam] = array($this->startDate, $this->endDate); } elseif (isset(\XLite\Core\Request::getInstance()->{$requestParam})) { $ordersSearch[$requestParam] = \XLite\Core\Request::getInstance()->{$requestParam}; } } if (!isset($ordersSearch[\XLite\Model\Repo\Order::P_PROFILE_ID])) { $ordersSearch[\XLite\Model\Repo\Order::P_PROFILE_ID] = 0; } \XLite\Core\Session::getInstance()->{$this->getSessionCellName()} = $ordersSearch; }
/** * Prepare certain search condition * * @param \Doctrine\ORM\QueryBuilder $queryBuilder Query builder to prepare * @param array|string $value Condition data * @param boolean $countOnly "Count only" flag. Do not need to add "order by" clauses if only count is needed. * * @return void */ protected function prepareCndEnabled(\Doctrine\ORM\QueryBuilder $queryBuilder, $value, $countOnly) { if ($value) { $queryBuilder->andWhere('n.enabled = :true AND n.date < :time')->setParameter('true', true)->setParameter('time', \XLite\Core\Converter::time()); } }
/** * Returns end of the day * * @param integer $time Server time * * @return integer */ public static function getDayEnd($time = null) { if (null === $time) { $time = \XLite\Core\Converter::time(); } return mktime(23, 59, 59, date('n', $time), date('j', $time), date('Y', $time)); }
protected function placeAmazonOrder($payment_method_text) { $cart = $this->getCart(); if (isset(\XLite\Core\Request::getInstance()->notes)) { $cart->setNotes(\XLite\Core\Request::getInstance()->notes); } $cart->setDate(\XLite\Core\Converter::time()); $cart->assignOrderNumber(); $cart->setPaymentStatus(\XLite\Model\Order\Status\Payment::STATUS_QUEUED); $cart->setShippingStatus(\XLite\Model\Order\Status\Shipping::STATUS_NEW); // apply $payment_method_text payment method $_tmp_method = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->findBy(array('service_name' => 'PayWithAmazon')); if ($_tmp_method) { $_tmp_method = $_tmp_method[0]; } else { // auto create it $_tmp_method = new \XLite\Model\Payment\Method(); $_tmp_method->setClass('Model\\Payment\\Processor\\Offline'); $_tmp_method->setServiceName('PayWithAmazon'); $_tmp_method->setName($payment_method_text); $_tmp_method->setModuleName('Amazon_PayWithAmazon'); } $this->getCart()->setPaymentMethod($_tmp_method); $this->getCart()->markAsOrder(); // $this->updateCart(); // old way produce fingerprint warning in logs $this->getCart()->updateOrder(); \XLite\Core\Database::getRepo('XLite\\Model\\Cart')->update($this->getCart()); // Register 'Place order' event in the order history \XLite\Core\OrderHistory::getInstance()->registerPlaceOrder($this->getCart()->getOrderId()); \XLite\Core\Database::getEM()->flush(); return $this->getCart()->getOrderId(); }
/** * Prepare update date * * @return void * * @PreUpdate */ public function prepareBeforeUpdate() { $this->setUpdateDate(\XLite\Core\Converter::time()); if (\XLite\Core\Converter::isEmptyString($this->getSku())) { $this->setSKU(null); } }
/** * Check - coupon is expired or not * * @return boolean */ public function isExpired() { return 0 < $this->getDateRangeEnd() && $this->getDateRangeEnd() < \XLite\Core\Converter::time(); }
/** * recoverPassword * * @param mixed $email Email * @param mixed $requestID Request ID * * @return boolean */ protected function doPasswordRecovery($email, $requestID) { $result = false; $profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findByLogin($email); if (!isset($profile) || !$profile->isAdmin()) { \XLite\Core\TopMessage::addError('There is no user with specified email address'); } elseif ($profile->getPasswordResetKey() != $requestID || \XLite\Core\Converter::time() > $profile->getPasswordResetKeyDate()) { \XLite\Core\TopMessage::addError('Your "Password reset key" has expired. Please enter the email address associated with your user account to get a new "Password reset key".'); $profile->setPasswordResetKey(''); $profile->setPasswordResetKeyDate(0); $profile->update(); } else { $pass = generate_code(); $profile->setPassword(md5($pass)); $profile->setForceChangePassword(true); $profile->setPasswordResetKey(''); $profile->setPasswordResetKeyDate(0); $result = $profile->update(); if ($result) { \XLite\Core\Auth::getInstance()->loginProfile($profile); } } return $result; }
/** * Get last export date * * @return string */ protected function getLastExportDate() { $list = $this->getDownloadFiles(); $file = $list ? current($list) : null; return $this->formatDate($file ? $file->getMTime() : \XLite\Core\Converter::time()); }
/** * Returns true if token initialized and is not expired * * @return boolean */ protected function isTokenValid() { return !empty(\XLite\Core\Session::getInstance()->ec_token) && self::TOKEN_TTL > \XLite\Core\Converter::time() - \XLite\Core\Session::getInstance()->ec_date; }
/** * Renew properties by path * * @param string $path Path * * @return boolean */ protected function renewByPath($path) { $this->setSize(intval(\Includes\Utils\FileManager::getFileSize($path))); $this->setDate(\XLite\Core\Converter::time()); return true; }
/** * Define query for findAllExpiredTemporaryOrders() method * * @return \Doctrine\ORM\QueryBuilder */ protected function defineAllExpiredTemporaryOrdersQuery() { return $this->createQueryBuilder(null, null, false)->leftJoin('o.orig_profile', 'op')->andWhere('o INSTANCE OF XLite\\Model\\Cart')->andWhere('op.profile_id IS NULL')->andWhere('o.date < :time')->setParameter('time', \XLite\Core\Converter::time() - $this->getOrderTTL()); }
/** * Check - cell file is valid or not * * @param string $path CEll file path * * @return boolean */ protected function isKeyValid($path) { if (!isset($this->validationCache[$path]) || !$this->validationCache[$path]) { $result = true; $ttl = intval(file_get_contents($path, false, null, $this->headerLength, $this->ttlLength)); if (0 < $ttl && \XLite\Core\Converter::time() > $ttl) { unlink($path); $result = false; } $this->validationCache[$path] = $result; } return $this->validationCache[$path]; }
/** * Finalize step * * @return void */ protected function finalizeStep() { parent::finalizeStep(); $this->release(); $this->model->setTriggerTime(\XLite\Core\Converter::time() + $this->getPeriod()); }
/** * Constructor * * @param string $majorVersion Core major version * @param string $minorVersion Core minor version * @param integer $revisionDate Core revison date * @param integer $size Pack size * * @return void */ public function __construct($majorVersion, $minorVersion, $revisionDate, $size) { if (!$this->checkMajorVersion($majorVersion) || !$this->checkMinorVersion($majorVersion, $minorVersion)) { $version = \Includes\Utils\Converter::composeVersion($majorVersion, $minorVersion); \Includes\ErrorHandler::fireError('Unallowed core version for upgrade: ' . $version); } if ($revisionDate >= \XLite\Core\Converter::time()) { \Includes\ErrorHandler::fireError('Invalid core revision date: "' . date(DATE_RFC822, $revisionDate) . '"'); } $this->majorVersion = $majorVersion; $this->minorVersion = $minorVersion; $this->revisionDate = $revisionDate; $this->size = $size; parent::__construct(); }
/** * Check if it's necessary to update list of allowed payment methods by date * * @return bool */ protected static function checkUpdateAllowedModulesLoadDate() { $currentDate = \XLite\Core\Converter::time(); $loadDate = \XLite\Core\Config::getInstance()->CDev->XPaymentsConnector->xpc_allowed_modules_load_date; return $currentDate - $loadDate > self::ALLOWED_MODULES_CACHE_TTL; }
/** * Define widget parameters * * @return void */ protected function defineWidgetParams() { parent::defineWidgetParams(); $this->widgetParams += array(self::PARAM_FIELD => new \XLite\Model\WidgetParam\String('Name of date field prefix', 'date'), self::PARAM_VALUE => new \XLite\Model\WidgetParam\Int('Value of date field (timestamp)', null), self::PARAM_HIGH_YEAR => new \XLite\Model\WidgetParam\Int('The high year', date('Y', \XLite\Core\Converter::time()) - 1), self::PARAM_LOW_YEAR => new \XLite\Model\WidgetParam\Int('The low year', 2035)); }
/** * Recover password * * @param string $email Profile email * @param string $requestID Request ID * * @return boolean */ protected function doPasswordRecovery($email, $requestID) { $result = false; $profile = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findByLogin($email); if (!isset($profile) || $profile->isAdmin()) { \XLite\Core\TopMessage::addError('There is no user with specified email address'); } elseif ($profile->getPasswordResetKey() != $requestID || \XLite\Core\Converter::time() > $profile->getPasswordResetKeyDate()) { \XLite\Core\TopMessage::addError('Your "Password reset key" has expired. Please enter the email address associated with your user account to get a new "Password reset key".'); $profile->setPasswordResetKey(''); $profile->setPasswordResetKeyDate(0); $profile->update(); } else { $pass = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->generatePassword(); $profile->setPassword(\XLite\Core\Auth::encryptPassword($pass)); $profile->setForceChangePassword(true); $profile->setPasswordResetKey(''); $profile->setPasswordResetKeyDate(0); $result = $profile->update(); if ($result) { $successfullyLogged = \XLite\Core\Auth::getInstance()->loginProfile($profile); if ($successfullyLogged) { $profileCart = $this->getCart(); // We merge the logged in cart into the session cart $profileCart->login($profile); \XLite\Core\Database::getEM()->flush(); if ($profileCart->isPersistent()) { $this->updateCart(); \XLite\Core\Event::getInstance()->exclude('updateCart'); } } } } return $result; }
/** * Prepare order before save data operation * * @return void * * @PrePersist * @PreUpdate */ public function prepareBeforeSave() { if (!is_numeric($this->date) || !is_int($this->date)) { $this->setDate(\XLite\Core\Converter::time()); } $this->setLastRenewDate(\XLite\Core\Converter::time()); }