get() public static method

public static get ( $id ) : null | TmpStore
$id
return null | TmpStore
Example #1
0
 /**
  * @param $documentId
  * @param $config
  * @throws \Exception
  */
 public function preparePdfGeneration($documentId, $config)
 {
     $document = $this->getPrintDocument($documentId);
     if (Model\Tool\TmpStore::get($document->getLockKey())) {
         throw new \Exception("Process with given document alredy running.");
     }
     Model\Tool\TmpStore::add($document->getLockKey(), true);
     $jobConfig = new \stdClass();
     $jobConfig->documentId = $documentId;
     $jobConfig->config = $config;
     $this->saveJobConfigObjectFile($jobConfig);
     $this->updateStatus($documentId, 0, "prepare_pdf_generation");
     $args = ["-p " . $jobConfig->documentId];
     $env = \Pimcore\Config::getEnvironment();
     if ($env !== false) {
         $args[] = "--environment=" . $env;
     }
     $cmd = Tool\Console::getPhpCli() . " " . realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php") . " web2print:pdf-creation " . implode(" ", $args);
     Logger::info($cmd);
     if (!$config['disableBackgroundExecution']) {
         Tool\Console::execInBackground($cmd, PIMCORE_LOG_DIRECTORY . DIRECTORY_SEPARATOR . "web2print-output.log");
     } else {
         Processor::getInstance()->startPdfGeneration($jobConfig->documentId);
     }
 }
 /**
  * @param \Zend_Controller_Request_Abstract $request
  */
 public function routeStartup(\Zend_Controller_Request_Abstract $request)
 {
     // this is a filter which checks for common used files (by browser, crawlers, ...) and prevent the default
     // error page, because this is more resource-intensive than exiting right here
     if (preg_match("@^/website/var/tmp/image-thumbnails(.*)?/([0-9]+)/thumb__([a-zA-Z0-9_\\-]+)([^\\@]+)(\\@[0-9.]+x)?\\.([a-zA-Z]{2,5})@", $request->getPathInfo(), $matches)) {
         $assetId = $matches[2];
         $thumbnailName = $matches[3];
         $format = $matches[6];
         if ($asset = Asset::getById($assetId)) {
             try {
                 $page = 1;
                 $thumbnailFile = null;
                 $thumbnailConfig = null;
                 $deferredConfigId = "thumb_" . $assetId . "__" . md5($request->getPathInfo());
                 if ($thumbnailConfigItem = TmpStore::get($deferredConfigId)) {
                     $thumbnailConfig = $thumbnailConfigItem->getData();
                     TmpStore::delete($deferredConfigId);
                     if (!$thumbnailConfig instanceof Asset\Image\Thumbnail\Config) {
                         throw new \Exception("Deferred thumbnail config file doesn't contain a valid \\Asset\\Image\\Thumbnail\\Config object");
                     }
                     $tmpPage = array_pop(explode("-", $thumbnailName));
                     if (is_numeric($tmpPage)) {
                         $page = $tmpPage;
                     }
                 } else {
                     //get thumbnail for e.g. pdf page thumb__document_pdfPage-5
                     if (preg_match("|document_(.*)\\-(\\d+)\$|", $thumbnailName, $matchesThumbs)) {
                         $thumbnailName = $matchesThumbs[1];
                         $page = (int) $matchesThumbs[2];
                     }
                     // just check if the thumbnail exists -> throws exception otherwise
                     $thumbnailConfig = Asset\Image\Thumbnail\Config::getByName($thumbnailName);
                 }
                 if ($asset instanceof Asset\Document) {
                     $thumbnailConfig->setName(preg_replace("/\\-[\\d]+/", "", $thumbnailConfig->getName()));
                     $thumbnailConfig->setName(str_replace("document_", "", $thumbnailConfig->getName()));
                     $thumbnailFile = PIMCORE_DOCUMENT_ROOT . $asset->getImageThumbnail($thumbnailConfig, $page);
                 } else {
                     if ($asset instanceof Asset\Image) {
                         //check if high res image is called
                         if (array_key_exists(5, $matches)) {
                             $highResFactor = (double) str_replace(array("@", "x"), "", $matches[5]);
                             $thumbnailConfig->setHighResolution($highResFactor);
                         }
                         $thumbnailFile = PIMCORE_DOCUMENT_ROOT . $asset->getThumbnail($thumbnailConfig);
                     }
                 }
                 if ($thumbnailFile && file_exists($thumbnailFile)) {
                     $fileExtension = \Pimcore\File::getFileExtension($thumbnailFile);
                     if (in_array($fileExtension, array("gif", "jpeg", "jpeg", "png", "pjpeg"))) {
                         header("Content-Type: image/" . $fileExtension, true);
                     } else {
                         header("Content-Type: " . $asset->getMimetype(), true);
                     }
                     header("Content-Length: " . filesize($thumbnailFile), true);
                     while (@ob_end_flush()) {
                     }
                     flush();
                     readfile($thumbnailFile);
                     exit;
                 }
             } catch (\Exception $e) {
                 // nothing to do
                 \Logger::error("Thumbnail with name '" . $thumbnailName . "' doesn't exist");
             }
         }
     }
 }
Example #3
0
 public function sendAction()
 {
     $document = Document\Newsletter::getById($this->getParam("id"));
     if (Tool\TmpStore::get($document->getTmpStoreId())) {
         throw new Exception("newsletter sending already in progress, need to finish first.");
     }
     $document = Document\Newsletter::getById($this->getParam("id"));
     Tool\TmpStore::add($document->getTmpStoreId(), ['documentId' => $document->getId(), 'addressSourceAdapterName' => $this->getParam("addressAdapterName"), 'adapterParams' => json_decode($this->getParam("adapterParams"), true), 'inProgress' => false, 'progress' => 0], 'newsletter');
     \Pimcore\Tool\Console::runPhpScriptInBackground(realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php"), "internal:newsletter-document-send " . escapeshellarg($document->getTmpStoreId()) . " " . escapeshellarg(\Pimcore\Tool::getHostUrl()), PIMCORE_LOG_DIRECTORY . DIRECTORY_SEPARATOR . "newsletter-sending-output.log");
     $this->_helper->json(["success" => true]);
 }
Example #4
0
File: Api.php Project: sfie/pimcore
 /**
  * @param null $scope
  * @return bool|\Google_Client
  * @throws \Zend_Json_Exception
  */
 public static function getServiceClient($scope = null)
 {
     if (!self::isServiceConfigured()) {
         return false;
     }
     $config = self::getConfig();
     if (!$scope) {
         // default scope
         $scope = ['https://www.googleapis.com/auth/analytics.readonly'];
     }
     $clientConfig = new \Google_Config();
     $clientConfig->setClassConfig("Google_Cache_File", "directory", PIMCORE_CACHE_DIRECTORY);
     $client = new \Google_Client($clientConfig);
     $client->setApplicationName("pimcore CMF");
     $key = file_get_contents(self::getPrivateKeyPath());
     $client->setAssertionCredentials(new \Google_Auth_AssertionCredentials($config->email, $scope, $key));
     $client->setClientId($config->client_id);
     // token cache
     $hash = crc32(serialize([$scope]));
     $tokenId = "google-api.token." . $hash;
     if ($tokenData = TmpStore::get($tokenId)) {
         $tokenInfo = \Zend_Json::decode($tokenData->getData());
         if ($tokenInfo["created"] + $tokenInfo["expires_in"] > time() - 900) {
             $token = $tokenData->getData();
         }
     }
     if (!$token) {
         $client->getAuth()->refreshTokenWithAssertion();
         $token = $client->getAuth()->getAccessToken();
         // 1 hour (3600s) is the default expiry time
         TmpStore::add($tokenId, $token, null, 3600);
     }
     $client->setAccessToken($token);
     return $client;
 }
Example #5
0
 /**
  * @param $processId
  */
 public static function execute($processId)
 {
     $instance = new self();
     $instance->setProcessId($processId);
     $instanceItem = TmpStore::get($instance->getJobStoreId($processId));
     $instance = $instanceItem->getData();
     $formats = [];
     $conversionStatus = "finished";
     // check if there is already a transcoding process running, wait if so ...
     Model\Tool\Lock::acquire("video-transcoding", 7200, 10);
     // expires after 2 hrs, refreshes every 10 secs
     $asset = Model\Asset::getById($instance->getAssetId());
     // start converting
     foreach ($instance->queue as $converter) {
         try {
             Logger::info("start video " . $converter->getFormat() . " to " . $converter->getDestinationFile());
             $success = $converter->save();
             Logger::info("finished video " . $converter->getFormat() . " to " . $converter->getDestinationFile());
             File::rename($converter->getDestinationFile(), $converter->getStorageFile());
             // set proper permissions
             @chmod($converter->getStorageFile(), File::getDefaultMode());
             if ($success) {
                 $formats[$converter->getFormat()] = str_replace($asset->getVideoThumbnailSavePath(), "", $converter->getStorageFile());
             } else {
                 $conversionStatus = "error";
             }
             $converter->destroy();
         } catch (\Exception $e) {
             Logger::error($e);
         }
     }
     Model\Tool\Lock::release("video-transcoding");
     if ($asset) {
         $customSetting = $asset->getCustomSetting("thumbnails");
         $customSetting = is_array($customSetting) ? $customSetting : [];
         if (array_key_exists($instance->getConfig()->getName(), $customSetting) && array_key_exists("formats", $customSetting[$instance->getConfig()->getName()]) && is_array($customSetting[$instance->getConfig()->getName()]["formats"])) {
             $formats = array_merge($customSetting[$instance->getConfig()->getName()]["formats"], $formats);
         }
         $customSetting[$instance->getConfig()->getName()] = ["status" => $conversionStatus, "formats" => $formats];
         $asset->setCustomSetting("thumbnails", $customSetting);
         $asset->save();
     }
     TmpStore::delete($instance->getJobStoreId());
 }
Example #6
0
 /**
  * @param \Zend_Controller_Request_Abstract $request
  */
 public function routeStartup(\Zend_Controller_Request_Abstract $request)
 {
     // this is a filter which checks for common used files (by browser, crawlers, ...) and prevent the default
     // error page, because this is more resource-intensive than exiting right here
     if (preg_match("@/image-thumbnails(.*)?/([0-9]+)/thumb__([a-zA-Z0-9_\\-]+)([^\\@]+)(\\@[0-9.]+x)?\\.([a-zA-Z]{2,5})@", rawurldecode($request->getPathInfo()), $matches)) {
         $assetId = $matches[2];
         $thumbnailName = $matches[3];
         if ($asset = Asset::getById($assetId)) {
             try {
                 $page = 1;
                 // default
                 $thumbnailFile = null;
                 $thumbnailConfig = null;
                 //get thumbnail for e.g. pdf page thumb__document_pdfPage-5
                 if (preg_match("|document_(.*)\\-(\\d+)\$|", $thumbnailName, $matchesThumbs)) {
                     $thumbnailName = $matchesThumbs[1];
                     $page = (int) $matchesThumbs[2];
                 }
                 // just check if the thumbnail exists -> throws exception otherwise
                 $thumbnailConfig = Asset\Image\Thumbnail\Config::getByName($thumbnailName);
                 if (!$thumbnailConfig) {
                     // check if there's an item in the TmpStore
                     $deferredConfigId = "thumb_" . $assetId . "__" . md5($matches[0]);
                     if ($thumbnailConfigItem = TmpStore::get($deferredConfigId)) {
                         $thumbnailConfig = $thumbnailConfigItem->getData();
                         TmpStore::delete($deferredConfigId);
                         if (!$thumbnailConfig instanceof Asset\Image\Thumbnail\Config) {
                             throw new \Exception("Deferred thumbnail config file doesn't contain a valid \\Asset\\Image\\Thumbnail\\Config object");
                         }
                     }
                 }
                 if (!$thumbnailConfig) {
                     throw new \Exception("Thumbnail '" . $thumbnailName . "' file doesn't exists");
                 }
                 if ($asset instanceof Asset\Document) {
                     $thumbnailConfig->setName(preg_replace("/\\-[\\d]+/", "", $thumbnailConfig->getName()));
                     $thumbnailConfig->setName(str_replace("document_", "", $thumbnailConfig->getName()));
                     $thumbnailFile = $asset->getImageThumbnail($thumbnailConfig, $page)->getFileSystemPath();
                 } elseif ($asset instanceof Asset\Image) {
                     //check if high res image is called
                     if (array_key_exists(5, $matches)) {
                         $highResFactor = (double) str_replace(["@", "x"], "", $matches[5]);
                         $thumbnailConfig->setHighResolution($highResFactor);
                     }
                     // check if a media query thumbnail was requested
                     if (preg_match("#~\\-~([\\d]+w)#", $matches[4], $mediaQueryResult)) {
                         $thumbnailConfig->selectMedia($mediaQueryResult[1]);
                     }
                     $thumbnailFile = $asset->getThumbnail($thumbnailConfig)->getFileSystemPath();
                 }
                 if ($thumbnailFile && file_exists($thumbnailFile)) {
                     // set appropriate caching headers
                     // see also: https://github.com/pimcore/pimcore/blob/1931860f0aea27de57e79313b2eb212dcf69ef13/.htaccess#L86-L86
                     $lifetime = 86400 * 7;
                     // 1 week lifetime, same as direct delivery in .htaccess
                     header("Cache-Control: public, max-age=" . $lifetime);
                     header("Expires: " . date("D, d M Y H:i:s T", time() + $lifetime));
                     $fileExtension = \Pimcore\File::getFileExtension($thumbnailFile);
                     if (in_array($fileExtension, ["gif", "jpeg", "jpeg", "png", "pjpeg"])) {
                         header("Content-Type: image/" . $fileExtension, true);
                     } else {
                         header("Content-Type: " . $asset->getMimetype(), true);
                     }
                     header("Content-Length: " . filesize($thumbnailFile), true);
                     while (@ob_end_flush()) {
                     }
                     flush();
                     readfile($thumbnailFile);
                     exit;
                 }
             } catch (\Exception $e) {
                 // nothing to do
                 Logger::error("Thumbnail with name '" . $thumbnailName . "' doesn't exist");
             }
         }
     }
 }
 protected function doSendMailInSingleMode(Model\Document\Newsletter $document, AddressSourceAdapterInterface $addressAdapter, $sendingId)
 {
     $totalCount = $addressAdapter->getTotalRecordCount();
     //calculate page size based on total item count - with min page size 3 and max page size 10
     $fifth = $totalCount / 5;
     $limit = $fifth > 10 ? 10 : ($fifth < 3 ? 3 : intval($fifth));
     $offset = 0;
     $hasElements = true;
     while ($hasElements) {
         $tmpStore = Model\Tool\TmpStore::get($sendingId);
         $data = $tmpStore->getData();
         Logger::info("Sending newsletter " . $hasElements . " / " . $totalCount . " [" . $document->getId() . "]");
         $data['progress'] = round($offset / $totalCount * 100, 2);
         $tmpStore->setData($data);
         $tmpStore->update();
         $sendingParamContainers = $addressAdapter->getParamsForSingleSending($limit, $offset);
         foreach ($sendingParamContainers as $sendingParamContainer) {
             $mail = \Pimcore\Tool\Newsletter::prepareMail($document, $sendingParamContainer);
             \Pimcore\Tool\Newsletter::sendNewsletterDocumentBasedMail($mail, $sendingParamContainer);
             if (empty($tmpStore)) {
                 Logger::warn("Sending configuration for sending ID {$sendingId} was deleted. Cancelling sending process.");
                 exit;
             }
         }
         $offset += $limit;
         $hasElements = count($sendingParamContainers);
         \Pimcore::collectGarbage();
     }
 }
Example #8
0
 /**
  * @static
  * @param $processId
  * @return int
  */
 public static function getProgress($processId)
 {
     $instance = new self();
     $instance->setProcessId($processId);
     $instanceItem = TmpStore::get($instance->getJobStoreId());
     if ($instanceItem) {
         $i = $instanceItem->getData();
         if ($i instanceof Processor) {
             $instance = $i;
         }
     }
     return $instance->getStatus();
 }
Example #9
0
 public function getInProgress()
 {
     return TmpStore::get($this->getLockKey());
 }
<?php

use Pimcore\Model\Tool\TmpStore;
if (!TmpStore::get("gpl-license")) {
    TmpStore::add("gpl-license", "true", null, 86400 * 30);
    echo "<b>You're going to install pimcore version 4!</b><br />";
    echo "pimcore 4 is fully backward-compatible with version 3 however it uses a new license.";
    echo "The new license is <a href='http://www.gnu.org/licenses/gpl-3.0.html' target='_blank'>GNU General Public License version 3 (GPLv3)</a>. ";
    echo "If you agree using pimcore under the terms of the GPLv3 license, please start the update again, you will not see this message again.";
    echo "<br />If you have any further questions please have a look at our <a href='https://github.com/pimcore/pimcore/blob/master/license-faq.md' target='blank'>licensing FAQ</a>.";
    exit;
}