/**
  * Downloads a file and cleans up old temporary assets
  */
 public function actionDownloadFile()
 {
     // Clean up temp assets files that are more than a day old
     $fileResults = array();
     $files = IOHelper::getFiles(craft()->path->getTempPath(), true);
     foreach ($files as $file) {
         $lastModifiedTime = IOHelper::getLastTimeModified($file, true);
         if (substr(IOHelper::getFileName($file, false, true), 0, 6) === "assets" && DateTimeHelper::currentTimeStamp() - $lastModifiedTime->getTimestamp() >= 86400) {
             IOHelper::deleteFile($file);
         }
     }
     // Sort out the file we want to download
     $id = craft()->request->getParam('id');
     $criteria = craft()->elements->getCriteria(ElementType::Asset);
     $criteria->id = $id;
     $asset = $criteria->first();
     if ($asset) {
         // Get a local copy of the file
         $sourceType = craft()->assetSources->getSourceTypeById($asset->sourceId);
         $localCopy = $sourceType->getLocalCopy($asset);
         // Send it to the browser
         craft()->request->sendFile($asset->filename, IOHelper::getFileContents($localCopy), array('forceDownload' => true));
         craft()->end();
     }
 }
 /**
  * Returns the element's status.
  *
  * @return string|null
  */
 public function getStatus()
 {
     $currentTime = DateTimeHelper::currentTimeStamp();
     $startDate = $this->startDate ? $this->startDate->getTimestamp() : null;
     $endDate = $this->endDate ? $this->endDate->getTimestamp() : null;
     $pluginSettings = craft()->plugins->getPlugin('maintenance')->pluginSettings;
     $interval = $pluginSettings['maintenanceImminent'];
     $interval = DateInterval::createFromDateString($interval);
     $secondsInAdvance = (new DateTime('@0'))->add($interval)->getTimeStamp();
     if (!$startDate) {
         return static::NONE;
     }
     if (!$this->blockCp && !$this->blockSite) {
         return static::DISABLED;
     } else {
         if ($startDate > $currentTime) {
             if ($startDate > $currentTime + $secondsInAdvance) {
                 return static::PENDING;
             } else {
                 return static::IMMINENT;
             }
         } else {
             if ($startDate <= $currentTime && (!$endDate || $endDate > $currentTime)) {
                 return static::INPROGRESS;
             } else {
                 if ($startDate <= $currentTime) {
                     return static::COMPLETED;
                 }
             }
         }
     }
 }
Beispiel #3
0
 /**
  * @param     $endpoint
  * @param int $timeout
  * @param int $connectTimeout
  *
  * @return Et
  */
 public function __construct($endpoint, $timeout = 30, $connectTimeout = 2)
 {
     $endpoint .= craft()->config->get('endpointSuffix');
     $this->_endpoint = $endpoint;
     $this->_timeout = $timeout;
     $this->_connectTimeout = $connectTimeout;
     $this->_model = new EtModel(array('licenseKey' => $this->_getLicenseKey(), 'requestUrl' => craft()->request->getHostInfo() . craft()->request->getUrl(), 'requestIp' => craft()->request->getIpAddress(), 'requestTime' => DateTimeHelper::currentTimeStamp(), 'requestPort' => craft()->request->getPort(), 'localBuild' => CRAFT_BUILD, 'localVersion' => CRAFT_VERSION, 'localEdition' => craft()->getEdition(), 'userEmail' => craft()->userSession->getUser()->email, 'track' => CRAFT_TRACK, 'serverInfo' => array('extensions' => get_loaded_extensions(), 'phpVersion' => PHP_VERSION, 'mySqlVersion' => craft()->db->getServerVersion())));
     $this->_userAgent = 'Craft/' . craft()->getVersion() . '.' . craft()->getBuild();
 }
Beispiel #4
0
 /**
  * @param     $endpoint
  * @param int $timeout
  */
 function __construct($endpoint, $timeout = 30)
 {
     $endpoint .= craft()->config->get('endpointSuffix');
     $this->_endpoint = $endpoint;
     $this->_timeout = $timeout;
     $this->_model = new EtModel(array('licenseKey' => $this->_getLicenseKey(), 'requestUrl' => craft()->request->getHostInfo() . craft()->request->getUrl(), 'requestIp' => craft()->request->getIpAddress(), 'requestTime' => DateTimeHelper::currentTimeStamp(), 'requestPort' => craft()->request->getPort(), 'installedPackages' => Craft::getPackages(), 'localBuild' => CRAFT_BUILD, 'localVersion' => CRAFT_VERSION, 'userEmail' => craft()->userSession->getUser()->email, 'track' => CRAFT_TRACK));
     $this->_options['useragent'] = 'craft-requests/' . \Requests::VERSION;
     $this->_options['timeout'] = $this->_timeout;
 }
 /**
  * Set sql file header
  *
  * @return null
  */
 private function _processHeader()
 {
     $header = '-- Generated by Craft ' . $this->_currentVersion . ' on ' . DateTimeHelper::nice(DateTimeHelper::currentTimeStamp()) . '.' . PHP_EOL . PHP_EOL;
     $header .= '--' . PHP_EOL . '-- Disable foreign key checks and autocommit.' . PHP_EOL . '--' . PHP_EOL . PHP_EOL;
     $header .= 'SET FOREIGN_KEY_CHECKS = 0;' . PHP_EOL;
     $header .= 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";' . PHP_EOL;
     $header .= 'SET AUTOCOMMIT = 0;' . PHP_EOL;
     $header .= 'SET NAMES utf8;' . PHP_EOL . PHP_EOL;
     IOHelper::writeToFile($this->_filePath, $header, true, true);
 }
Beispiel #6
0
 /**
  * @param     $endpoint
  * @param int $timeout
  * @param int $connectTimeout
  *
  * @return Et
  */
 public function __construct($endpoint, $timeout = 30, $connectTimeout = 30)
 {
     $endpoint .= craft()->config->get('endpointSuffix');
     $this->_endpoint = $endpoint;
     $this->_timeout = $timeout;
     $this->_connectTimeout = $connectTimeout;
     // There can be a race condition after an update from older Craft versions where they lose session
     // and another call to elliott is made during cleanup.
     $userEmail = craft()->userSession->getUser() ? craft()->userSession->getUser()->email : '';
     $this->_model = new EtModel(array('licenseKey' => $this->_getLicenseKey(), 'pluginLicenseKeys' => $this->_getPluginLicenseKeys(), 'requestUrl' => craft()->request->getHostInfo() . craft()->request->getUrl(), 'requestIp' => craft()->request->getIpAddress(), 'requestTime' => DateTimeHelper::currentTimeStamp(), 'requestPort' => craft()->request->getPort(), 'localBuild' => CRAFT_BUILD, 'localVersion' => CRAFT_VERSION, 'localEdition' => craft()->getEdition(), 'userEmail' => $userEmail, 'track' => CRAFT_TRACK, 'showBeta' => craft()->config->get('showBetaUpdates'), 'serverInfo' => array('extensions' => get_loaded_extensions(), 'phpVersion' => PHP_VERSION, 'mySqlVersion' => craft()->db->getServerVersion(), 'proc' => function_exists('proc_open') ? 1 : 0)));
     $this->_userAgent = 'Craft/' . craft()->getVersion() . '.' . craft()->getBuild();
 }
 /**
  * @inheritDoc BaseElementModel::getStatus()
  *
  * @return string|null
  */
 public function getStatus()
 {
     $status = parent::getStatus();
     if ($status == static::ENABLED && $this->postDate) {
         $currentTime = DateTimeHelper::currentTimeStamp();
         $postDate = $this->postDate->getTimestamp();
         $expiryDate = $this->expiryDate ? $this->expiryDate->getTimestamp() : null;
         if ($postDate <= $currentTime && (!$expiryDate || $expiryDate > $currentTime)) {
             return static::LIVE;
         } else {
             if ($postDate > $currentTime) {
                 return static::PENDING;
             } else {
                 return static::EXPIRED;
             }
         }
     }
     return $status;
 }
 /**
  * Deletes any expired caches if we haven't already done that within the past 24 hours.
  *
  * @return bool
  */
 public function deleteExpiredCachesIfOverdue()
 {
     // Ignore if we've already done this once during the request
     if ($this->_deletedExpiredCaches) {
         return false;
     }
     $lastCleanupDate = craft()->cache->get('lastTemplateCacheCleanupDate');
     if ($lastCleanupDate === false || DateTimeHelper::currentTimeStamp() - $lastCleanupDate > static::$_lastCleanupDateCacheDuration) {
         // Don't do it again for a while
         craft()->cache->set('lastTemplateCacheCleanupDate', DateTimeHelper::currentTimeStamp(), static::$_lastCleanupDateCacheDuration);
         return $this->deleteExpiredCaches();
     } else {
         $this->_deletedExpiredCaches = true;
         return false;
     }
 }
Beispiel #9
0
 /**
  * Set sql file header
  * @return string
  */
 private function _processHeader()
 {
     $header = '-- Generated by Craft ' . $this->_currentVersion . ' on ' . DateTimeHelper::nice(DateTimeHelper::currentTimeStamp()) . '.' . PHP_EOL . PHP_EOL;
     $header .= '--' . PHP_EOL . '-- Disable foreign key checks and autocommit and start a transaction.' . PHP_EOL . '--' . PHP_EOL . PHP_EOL;
     $header .= 'SET FOREIGN_KEY_CHECKS = 0;' . PHP_EOL;
     $header .= 'SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";' . PHP_EOL;
     $header .= 'SET AUTOCOMMIT = 0;' . PHP_EOL;
     $header .= 'SET NAMES utf8;' . PHP_EOL;
     $header .= 'START TRANSACTION;' . PHP_EOL . PHP_EOL;
     $header .= '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;' . PHP_EOL;
     $header .= '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;' . PHP_EOL;
     $header .= '/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;' . PHP_EOL;
     $header .= '/*!40101 SET NAMES utf8 */;' . PHP_EOL;
     return $header;
 }
 public function getCpAlerts($path, $fetch)
 {
     if ($announcement = $this->announcement) {
         switch ($announcement->getStatus()) {
             case 'completed':
                 $message = Craft::t('Maintenance is complete.');
                 break;
             case 'inprogress':
                 $message = Craft::t('Maintenance in progress.');
                 break;
             case 'pending':
                 $date = $announcement->startDate;
                 $message = Craft::t('Maintenance will be carried out on {date}.', array('date' => '<span class="maintenanceBanner-date">' . $date->localeDate() . ' ' . $date->localeTime() . '</span>'));
                 break;
             case 'imminent':
                 craft()->templates->includeTranslations('Maintenance in progress.');
                 $currentTime = DateTimeHelper::currentTimeStamp();
                 $startDate = $announcement->startDate->getTimestamp();
                 $this->initCountdown($startDate - $currentTime);
                 $message = '<span class="hidden">' . Craft::t('Maintenance will be carried out in {minutes} minutes.', array('minutes' => '<span id="maintenancecountdown">some</span>')) . '</span>';
                 break;
         }
         return array($message);
     }
 }