protected function execute(InputInterface $input, OutputInterface $output) { $sendingId = $input->getArgument("sendingId"); $tmpStore = Model\Tool\TmpStore::get($sendingId); if (empty($tmpStore)) { Logger::alert("No sending configuration for {$sendingId} found. Cannot send newsletter."); exit; } $data = $tmpStore->getData(); if ($data['inProgress']) { Logger::alert("Cannot send newsletters because there's already one active sending process."); exit; } $data['inProgress'] = 1; $tmpStore->setData($data); $tmpStore->update(); $document = Model\Document\Newsletter::getById($data['documentId']); $addressSourceAdapterName = $data['addressSourceAdapterName']; $adapterParams = $data['adapterParams']; $adapterClass = "\\Pimcore\\Document\\Newsletter\\AddressSourceAdapter\\" . ucfirst($addressSourceAdapterName); /** * @var $addressAdapter \Pimcore\Document\Newsletter\AddressSourceAdapterInterface */ $addressAdapter = new $adapterClass($adapterParams); if ($document->getSendingMode() == Newsletter::SENDING_MODE_BATCH) { $this->doSendMailInBatchMode($document, $addressAdapter, $sendingId); } else { $this->doSendMailInSingleMode($document, $addressAdapter, $sendingId); } Model\Tool\TmpStore::delete($sendingId); }
/** * */ public static function processOptimizeQueue() { $ids = TmpStore::getIdsByTag("image-optimize-queue"); // id = path of image relative to PIMCORE_TEMPORARY_DIRECTORY foreach ($ids as $id) { $file = PIMCORE_TEMPORARY_DIRECTORY . "/" . $id; if (file_exists($file)) { $originalFilesize = filesize($file); \Pimcore\Image\Optimizer::optimize($file); \Logger::debug("Optimized image: " . $file . " saved " . formatBytes($originalFilesize - filesize($file))); } else { \Logger::debug("Skip optimizing of " . $file . " because it doesn't exist anymore"); } TmpStore::delete($id); } }
/** * @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"); } } } }
public function stopSendAction() { $document = Document\Newsletter::getById($this->getParam("id")); Tool\TmpStore::delete($document->getTmpStoreId()); $this->_helper->json(["success" => true]); }
/** * @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()); }
/** * @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"); } } } }
/** * @param $documentId * @throws \Exception */ public function cancelGeneration($documentId) { $document = Document\Printpage::getById($documentId); if (empty($document)) { throw new \Exception("Document with id " . $documentId . " not found."); } Model\Tool\Lock::release($document->getLockKey()); Model\Tool\TmpStore::delete($document->getLockKey()); }
/** * @param $processId */ public static function execute($processId) { $instance = new self(); $instance->setProcessId($processId); $instanceItem = TmpStore::get($instance->getJobStoreId($processId)); $instance = $instanceItem->getData(); $formats = array(); $overallStatus = array(); $conversionStatus = "finished"; // set overall status for all formats to 0 foreach ($instance->queue as $converter) { $overallStatus[$converter->getFormat()] = 0; } // 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 // start converting foreach ($instance->queue as $converter) { try { \Logger::info("start video " . $converter->getFormat() . " to " . $converter->getDestinationFile()); $converter->save(); while (!$converter->isFinished()) { sleep(5); $overallStatus[$converter->getFormat()] = $converter->getConversionStatus(); $a = 0; foreach ($overallStatus as $f => $s) { $a += $s; } $a = $a / count($overallStatus); $instance->setStatus($a); $instance->save(); } \Logger::info("finished video " . $converter->getFormat() . " to " . $converter->getDestinationFile()); // set proper permissions @chmod($converter->getDestinationFile(), File::getDefaultMode()); if ($converter->getConversionStatus() !== "error") { $formats[$converter->getFormat()] = str_replace(PIMCORE_DOCUMENT_ROOT, "", $converter->getDestinationFile()); } else { $conversionStatus = "error"; } $converter->destroy(); } catch (\Exception $e) { \Logger::error($e); } } Model\Tool\Lock::release("video-transcoding"); $asset = Model\Asset::getById($instance->getAssetId()); if ($asset) { $customSetting = $asset->getCustomSetting("thumbnails"); $customSetting = is_array($customSetting) ? $customSetting : array(); 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()] = array("status" => $conversionStatus, "formats" => $formats); $asset->setCustomSetting("thumbnails", $customSetting); $asset->save(); } TmpStore::delete($instance->getJobStoreId()); }