/** * Loads a list of entries for the specicifies parameters, returns an array of Search\Backend\Data * * @return array */ public function load() { $entries = array(); $data = $this->db->fetchAll("SELECT * FROM search_backend_data" . $this->getCondition() . $this->getGroupBy() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($data as $entryData) { if ($entryData['maintype'] == 'document') { $element = Document::getById($entryData['id']); } else { if ($entryData['maintype'] == 'asset') { $element = Asset::getById($entryData['id']); } else { if ($entryData['maintype'] == 'object') { $element = Object::getById($entryData['id']); } else { \Logger::err("unknown maintype "); } } } if ($element) { $entry = new Search\Backend\Data(); $entry->setId(new Search\Backend\Data\Id($element)); $entry->setFullPath($entryData['fullpath']); $entry->setType($entryData['type']); $entry->setSubtype($entryData['subtype']); $entry->setUserOwner($entryData['userowner']); $entry->setUserModification($entryData['usermodification']); $entry->setCreationDate($entryData['creationdate']); $entry->setModificationDate($entryData['modificationdate']); $entry->setPublished($entryData['published'] === 0 ? false : true); $entries[] = $entry; } } $this->model->setEntries($entries); return $entries; }
protected function execute(InputInterface $input, OutputInterface $output) { // get all thumbnails $dir = Asset\Image\Thumbnail\Config::getWorkingDir(); $thumbnails = array(); $files = scandir($dir); foreach ($files as $file) { if (strpos($file, ".xml")) { $thumbnails[] = str_replace(".xml", "", $file); } } $allowedThumbs = array(); if ($input->getOption("thumbnails")) { $allowedThumbs = explode(",", $input->getOption("thumbnails")); } // get only images $conditions = array("type = 'image'"); if ($input->getOption("parent")) { $parent = Asset::getById($input->getOption("parent")); if ($parent instanceof Asset\Folder) { $conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'"; } else { $this->writeError($input->getOption("parent") . " is not a valid asset folder ID!"); exit; } } $list = new Asset\Listing(); $list->setCondition(implode(" AND ", $conditions)); $total = $list->getTotalCount(); $perLoop = 10; for ($i = 0; $i < ceil($total / $perLoop); $i++) { $list->setLimit($perLoop); $list->setOffset($i * $perLoop); $images = $list->load(); foreach ($images as $image) { foreach ($thumbnails as $thumbnail) { if (empty($allowedThumbs) && !$input->getOption("system") || in_array($thumbnail, $allowedThumbs)) { if ($input->getOption("force")) { $image->clearThumbnail($thumbnail); } $this->output->writeln("generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage())); $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail)); } } if ($input->getOption("system")) { $thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig(); if ($input->getOption("force")) { $image->clearThumbnail($thumbnail->getName()); } $this->output->writeln("generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: System Preview (tree) : " . formatBytes(memory_get_usage())); $this->output->writeln("generated thumbnail: " . $image->getThumbnail($thumbnail)); } } \Pimcore::collectGarbage(); } }
public function thumbnailAction() { $a = Asset::getById(22); $a->clearThumbnails(true); $t = $a->getThumbnail("content"); header("Content-Type: image/jpeg"); while (@ob_end_flush()) { } flush(); readfile($t->getFileSystemPath()); exit; }
/** * Get the assets from database * * @return array */ public function load() { $assets = array(); $assetsData = $this->db->fetchAll("SELECT id,type FROM assets" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables()); foreach ($assetsData as $assetData) { if ($assetData["type"]) { if ($asset = Model\Asset::getById($assetData["id"])) { $assets[] = $asset; } } } $this->model->setAssets($assets); return $assets; }
/** * Get the assets from database * * @return array */ public function load() { $assets = []; $select = (string) $this->getQuery(['id', "type"]); $assetsData = $this->db->fetchAll($select, $this->model->getConditionVariables()); foreach ($assetsData as $assetData) { if ($assetData["type"]) { if ($asset = Model\Asset::getById($assetData["id"])) { $assets[] = $asset; } } } $this->model->setAssets($assets); return $assets; }
public function preDispatch() { parent::preDispatch(); if ($this->getParam('ctype') === 'document') { $this->element = Document::getById((int) $this->getParam('cid', 0)); } elseif ($this->getParam('ctype') === 'asset') { $this->element = Asset::getById((int) $this->getParam('cid', 0)); } elseif ($this->getParam('ctype') === 'object') { $this->element = ConcreteObject::getById((int) $this->getParam('cid', 0)); } if (!$this->element) { throw new \Exception('Cannot load element' . $this->getParam('cid') . ' of type \'' . $this->getParam('ctype') . '\''); } //get the latest available version of the element - //$this->element = $this->getLatestVersion($this->element); $this->element->setUserModification($this->getUser()->getId()); }
/** * @param $id * @throws \Exception */ public function getById($id) { $data = $this->db->fetchRow("SELECT * FROM notes WHERE id = ?", $id); if (!$data["id"]) { throw new \Exception("Note item with id " . $id . " not found"); } $this->assignVariablesToModel($data); // get key-value data $keyValues = $this->db->fetchAll("SELECT * FROM notes_data WHERE id = ?", $id); $preparedData = array(); foreach ($keyValues as $keyValue) { $data = $keyValue["data"]; $type = $keyValue["type"]; $name = $keyValue["name"]; if ($type == "document") { if ($data) { $data = Document::getById($data); } } else { if ($type == "asset") { if ($data) { $data = Asset::getById($data); } } else { if ($type == "object") { if ($data) { $data = Object\AbstractObject::getById($data); } } else { if ($type == "date") { if ($data > 0) { $data = new \Zend_Date($data); } } else { if ($type == "bool") { $data = (bool) $data; } } } } } $preparedData[$name] = array("data" => $data, "type" => $type); } $this->model->setData($preparedData); }
protected function updatePathFromInternal() { if ($this->data['internal']) { if ($this->data['internalType'] == 'document') { if ($doc = Document::getById($this->data['internalId'])) { if (!Document::doHideUnpublished() || $doc->isPublished()) { $path = $doc->getFullPath(); $this->data['path'] = \Toolbox\Tools\GlobalLink::parse($path); } } } else { if ($this->data['internalType'] == 'asset') { if ($asset = Asset::getById($this->data['internalId'])) { $this->data['path'] = $asset->getFullPath(); } } } } }
/** end point for asset related data. * - get asset by id * GET http://[YOUR-DOMAIN]/webservice/rest/asset/id/1281?apikey=[API-KEY] * returns json-encoded asset data. * - delete asset by id * DELETE http://[YOUR-DOMAIN]/webservice/rest/asset/id/1281?apikey=[API-KEY] * returns json encoded success value * - create asset * PUT or POST http://[YOUR-DOMAIN]/webservice/rest/asset?apikey=[API-KEY] * body: json-encoded asset data in the same format as returned by get asset by id * but with missing id field or id set to 0 * returns json encoded asset id * - update asset * PUT or POST http://[YOUR-DOMAIN]/webservice/rest/asset?apikey=[API-KEY] * body: same as for create asset but with asset id * returns json encoded success value * @throws \Exception */ public function assetAction() { $id = $this->getParam("id"); $success = false; try { if ($this->isGet()) { $asset = Asset::getById($id); if (!$asset) { $this->encoder->encode(array("success" => false, "msg" => "Asset does not exist", "code" => self::ELEMENT_DOES_NOT_EXIST)); return; } $this->checkPermission($asset, "get"); if ($asset instanceof Asset\Folder) { $object = $this->service->getAssetFolderById($id); } else { $light = $this->getParam("light"); $options = array("LIGHT" => $light ? 1 : 0); $object = $this->service->getAssetFileById($id, $options); $algo = "sha1"; $thumbnailConfig = $this->getParam("thumbnail"); if ($thumbnailConfig && $asset->getType() == "image") { $checksum = $asset->getThumbnail($thumbnailConfig)->getChecksum($algo); $object->thumbnail = (string) $asset->getThumbnail($thumbnailConfig); } else { $checksum = $asset->getChecksum($algo); } $object->checksum = array("algo" => $algo, "value" => $checksum); if ($light) { unset($object->data); } } $this->encoder->encode(array("success" => true, "data" => $object)); return; } else { if ($this->isDelete()) { $asset = Asset::getById($id); if ($asset) { $this->checkPermission($asset, "delete"); } $success = $this->service->deleteAsset($id); $this->encoder->encode(array("success" => $success)); return; } else { if ($this->isPost() || $this->isPut()) { $data = file_get_contents("php://input"); $data = \Zend_Json::decode($data); $type = $data["type"]; $id = null; if ($data["id"]) { $asset = Asset::getById($data["id"]); if ($asset) { $this->checkPermission($asset, "update"); } $isUpdate = true; if ($type == "folder") { $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Asset\\Folder\\In", $data); $success = $this->service->updateAssetFolder($wsData); } else { $wsData = self::fillWebserviceData("\\Pimcore\\Model\\Webservice\\Data\\Asset\\File\\In", $data); $success = $this->service->updateAssetFile($wsData); } } else { if ($type == "folder") { $class = "\\Pimcore\\Model\\Webservice\\Data\\Asset\\Folder\\In"; $method = "createAssetFolder"; } else { $class = "\\Pimcore\\Model\\Webservice\\Data\\Asset\\File\\In"; $method = "createAssetFile"; } $wsData = self::fillWebserviceData($class, $data); $asset = new Asset(); $asset->setId($wsData->parentId); $this->checkPermission($asset, "create"); $id = $this->service->{$method}($wsData); } if (!$isUpdate) { $success = $id != null; } if ($success && !$isUpdate) { $this->encoder->encode(array("success" => $success, "data" => array("id" => $id))); } else { $this->encoder->encode(array("success" => $success)); } return; } } } } catch (\Exception $e) { \Logger::error($e); $this->encoder->encode(array("success" => false, "msg" => (string) $e)); } $this->encoder->encode(array("success" => false)); }
/** * @param $object * @param $idMapping * @param array $params * @return mixed */ public function rewriteIds($object, $idMapping, $params = array()) { $data = $this->getDataFromObjectParam($object, $params); if ($data && $data->getData() instanceof Asset) { if (array_key_exists("asset", $idMapping) and array_key_exists($data->getData()->getId(), $idMapping["asset"])) { $data->setData(Asset::getById($idMapping["asset"][$data->getData()->getId()])); } } if ($data && $data->getPoster() instanceof Asset) { if (array_key_exists("asset", $idMapping) and array_key_exists($data->getPoster()->getId(), $idMapping["asset"])) { $data->setPoster(Asset::getById($idMapping["asset"][$data->getPoster()->getId()])); } } return $data; }
public function typePathAction() { $id = $this->getParam("id"); $type = $this->getParam("type"); $data = []; if ($type == "asset") { $element = Asset::getById($id); } elseif ($type == "document") { $element = Document::getById($id); $data["index"] = $element->getIndex(); } else { $element = Object::getById($id); } $typePath = Element\Service::getTypePath($element); $data["success"] = true; $data["idPath"] = Element\Service::getIdPath($element); $data["typePath"] = $typePath; $data["fullpath"] = $element->getRealFullPath(); $this->_helper->json($data); }
public static function getAssetTypePath($element) { $path = ""; if ($element) { $parentId = $element->getParentId(); if ($parentId) { $ne = Asset::getById($element->getParentId()); } } if ($ne) { $path = self::getAssetTypePath($ne, $path); } if ($element) { $path = $path . "/" . $element->getType(); } return $path; }
/** * @param Document\Webservice\Data\Document\Element $wsElement * @param null $idMapper * @throws \Exception */ public function getFromWebserviceImport($wsElement, $idMapper = null) { $data = $wsElement->value; if ($data->id !== null) { $this->type = $data->type; $this->subtype = $data->subtype; if (is_numeric($this->id)) { if ($idMapper) { $id = $idMapper->getMappedId($this->type, $this->id); } if ($this->type == "asset") { $this->o = Asset::getById($id); if (!$this->o instanceof Asset) { if ($idMapper && $idMapper->ignoreMappingFailures()) { $idMapper->recordMappingFailure($this->getDocumentId(), $this->type, $this->id); } else { throw new \Exception("cannot get values from web service import - referenced asset with id [ " . $this->id . " ] is unknown"); } } } else { if ($this->type == "document") { $this->o = Document::getById($id); if (!$this->o instanceof Document) { if ($idMapper && $idMapper->ignoreMappingFailures()) { $idMapper->recordMappingFailure($this->getDocumentId(), $this->type, $this->id); } else { throw new \Exception("cannot get values from web service import - referenced document with id [ " . $this->id . " ] is unknown"); } } } else { if ($this->type == "object") { $this->o = Object::getById($id); if (!$this->o instanceof Object\AbstractObject) { if ($idMapper && $idMapper->ignoreMappingFailures()) { $idMapper->recordMappingFailure($this->getDocumentId(), $this->type, $this->id); } else { throw new \Exception("cannot get values from web service import - referenced object with id [ " . $this->id . " ] is unknown"); } } } else { p_r($this); throw new \Exception("cannot get values from web service import - type is not valid"); } } } } else { throw new \Exception("cannot get values from web service import - id is not valid"); } } }
/** * This is a dummy and is mostly implemented by relation types * * @param mixed $data * @param array $tags * @return array */ public function getCacheTags($data, $tags = array()) { $tags = is_array($tags) ? $tags : array(); if ($data instanceof Object\Data\Link and $data->getInternal()) { if (intval($data->getInternal()) > 0) { if ($data->getInternalType() == "document") { if ($doc = Document::getById($data->getInternal())) { if (!array_key_exists($doc->getCacheTag(), $tags)) { $tags = $doc->getCacheTags($tags); } } } elseif ($data->getInternalType() == "asset") { if ($asset = Asset::getById($data->getInternal())) { if (!array_key_exists($asset->getCacheTag(), $tags)) { $tags = $asset->getCacheTags($tags); } } } } } return $tags; }
$dir = Asset\Image\Thumbnail\Config::getWorkingDir(); $thumbnails = array(); $files = scandir($dir); foreach ($files as $file) { if (strpos($file, ".xml")) { $thumbnails[] = str_replace(".xml", "", $file); } } $allowedThumbs = array(); if ($opts->getOption("thumbnails")) { $allowedThumbs = explode(",", $opts->getOption("thumbnails")); } // get only images $conditions = array("type = 'image'"); if ($opts->getOption("parent")) { $parent = Asset::getById($opts->getOption("parent")); if ($parent instanceof Asset\Folder) { $conditions[] = "path LIKE '" . $parent->getFullPath() . "/%'"; } else { echo $opts->getOption("parent") . " is not a valid asset folder ID!\n"; exit; } } $list = new Asset\Listing(); $list->setCondition(implode(" AND ", $conditions)); $total = $list->getTotalCount(); $perLoop = 10; for ($i = 0; $i < ceil($total / $perLoop); $i++) { $list->setLimit($perLoop); $list->setOffset($i * $perLoop); $images = $list->load();
/** * @param $config * @return string */ public function getImageThumbnail($config) { if ($this->poster && ($poster = Asset::getById($this->poster))) { return $poster->getThumbnail($config); } if ($this->getVideoAsset()) { return $this->getVideoAsset()->getImageThumbnail($config); } return ""; }
/** * @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 __wakeup() { if (isset($this->_fulldump)) { // set current key and path this is necessary because the serialized data can have a different path than the original element (element was renamed or moved) $originalElement = Asset::getById($this->getId()); if ($originalElement) { $this->setFilename($originalElement->getFilename()); $this->setPath($originalElement->getPath()); } } if (isset($this->_fulldump) && $this->properties !== null) { $this->renewInheritedProperties(); } if (isset($this->_fulldump)) { unset($this->_fulldump); } }
/** * @see Model\Object\ClassDefinition\Data::getDataFromEditmode * @param array $data * @param null|Model\Object\AbstractObject $object * @param mixed $params * @return array */ public function getDataFromEditmode($data, $object = null, $params = []) { //if not set, return null if ($data === null or $data === false) { return null; } $elements = []; if (is_array($data) && count($data) > 0) { foreach ($data as $element) { if ($element["type"] == "object") { $e = Object::getById($element["id"]); } elseif ($element["type"] == "asset") { $e = Asset::getById($element["id"]); } elseif ($element["type"] == "document") { $e = Document::getById($element["id"]); } if ($e instanceof Element\ElementInterface) { $elements[] = $e; } } } //must return array if data shall be set return $elements; }
public function assetThumbnailListAction() { // try to get the tag where the parent folder is specified $parentFolder = $this->document->getElement("parentFolder"); if ($parentFolder) { $parentFolder = $parentFolder->getElement(); } if (!$parentFolder) { // default is the home folder $parentFolder = Asset::getById(1); } // get all children of the parent $list = new Asset\Listing(); $list->setCondition("path like ?", $parentFolder->getFullpath() . "%"); $this->view->list = $list; }
/** * @param $googleResponse */ public function readGoogleResponse($googleResponse) { $googleResponse = $googleResponse["modelData"]; $this->setRaw($googleResponse); // available factes if (array_key_exists("context", $googleResponse) && is_array($googleResponse["context"])) { if (array_key_exists("facets", $googleResponse["context"]) && is_array($googleResponse["context"]["facets"])) { $facets = array(); foreach ($googleResponse["context"]["facets"] as $facet) { $facets[$facet[0]["label"]] = $facet[0]["anchor"]; } $this->setFacets($facets); } } // results incl. promotions, search results, ... $items = array(); // set promotions if (array_key_exists("promotions", $googleResponse) && is_array($googleResponse["promotions"])) { foreach ($googleResponse["promotions"] as $promo) { $promo["type"] = "promotion"; $promo["formattedUrl"] = preg_replace("@^https?://@", "", $promo["link"]); $promo["htmlFormattedUrl"] = $promo["formattedUrl"]; $items[] = new Item($promo); } } // set search results $total = intval($googleResponse["searchInformation"]["totalResults"]); if ($total > 100) { $total = 100; } $this->setTotal($total); if (array_key_exists("items", $googleResponse) && is_array($googleResponse["items"])) { foreach ($googleResponse["items"] as $item) { // check for relation to document or asset // first check for an image if (array_key_exists("pagemap", $item) && is_array($item["pagemap"])) { if (array_key_exists("cse_image", $item["pagemap"]) && is_array($item["pagemap"]["cse_image"])) { if ($item["pagemap"]["cse_image"][0]) { // try to get the asset id if (preg_match("/thumb_([0-9]+)__/", $item["pagemap"]["cse_image"][0]["src"], $matches)) { $test = $matches; if ($matches[1]) { if ($image = Model\Asset::getById($matches[1])) { if ($image instanceof Model\Asset\Image) { $item["image"] = $image; } } } } if (!array_key_exists("image", $item)) { $item["image"] = $item["pagemap"]["cse_image"][0]["src"]; } } } } // now a document $urlParts = parse_url($item["link"]); if ($document = Model\Document::getByPath($urlParts["path"])) { $item["document"] = $document; } $item["type"] = "searchresult"; $items[] = new Item($item); } } $this->setResults($items); }
/** * @return void */ public function setObjectFromId() { if ($this->internalType == "document") { $this->object = Document::getById($this->internal); } else { if ($this->internalType == "asset") { $this->object = Asset::getById($this->internal); } } return $this->object; }
/** * */ public function generate() { $errorImage = PIMCORE_PATH . '/static6/img/filetype-not-supported.png'; $deferred = false; $generated = false; if (!$this->asset) { $this->filesystemPath = $errorImage; } elseif (!$this->filesystemPath) { $cs = $this->asset->getCustomSetting("image_thumbnail_time"); $im = $this->asset->getCustomSetting("image_thumbnail_asset"); if ($im || $this->imageAsset) { if ($this->imageAsset) { $im = $this->imageAsset; } else { $im = Model\Asset::getById($im); } if ($im instanceof Image) { $imageThumbnail = $im->getThumbnail($this->getConfig()); $this->filesystemPath = $imageThumbnail->getFileSystemPath(); } } if (!$this->filesystemPath) { $timeOffset = $this->timeOffset; if (!$this->timeOffset && $cs) { $timeOffset = $cs; } // fallback if (!$timeOffset) { $timeOffset = ceil($this->asset->getDuration() / 3); } $converter = \Pimcore\Video::getInstance(); $converter->load($this->asset->getFileSystemPath()); $path = PIMCORE_TEMPORARY_DIRECTORY . "/video-image-cache/video_" . $this->asset->getId() . "__thumbnail_" . $timeOffset . ".png"; if (!is_dir(dirname($path))) { File::mkdir(dirname($path)); } if (!is_file($path)) { $lockKey = "video_image_thumbnail_" . $this->asset->getId() . "_" . $timeOffset; Model\Tool\Lock::acquire($lockKey); // after we got the lock, check again if the image exists in the meantime - if not - generate it if (!is_file($path)) { $converter->saveImage($path, $timeOffset); $generated = true; } Model\Tool\Lock::release($lockKey); } if ($this->getConfig()) { $this->getConfig()->setFilenameSuffix("time-" . $timeOffset); try { $path = Image\Thumbnail\Processor::process($this->asset, $this->getConfig(), $path, $deferred, true, $generated); } catch (\Exception $e) { Logger::error("Couldn't create image-thumbnail of video " . $this->asset->getRealFullPath()); Logger::error($e); $path = $errorImage; } } $this->filesystemPath = $path; } \Pimcore::getEventManager()->trigger("asset.video.image-thumbnail", $this, ["deferred" => $deferred, "generated" => $generated]); } }
/** * */ public function maintenanceCleanUp() { $conf["document"] = Config::getSystemConfig()->documents->versions; $conf["asset"] = Config::getSystemConfig()->assets->versions; $conf["object"] = Config::getSystemConfig()->objects->versions; $elementTypes = array(); foreach ($conf as $elementType => $tConf) { if (intval($tConf->days) > 0) { $versioningType = "days"; $value = intval($tConf->days); } else { $versioningType = "steps"; $value = intval($tConf->steps); } if ($versioningType) { $elementTypes[] = array("elementType" => $elementType, $versioningType => $value); } } $ignoredIds = array(); while (true) { $versions = $this->getDao()->maintenanceGetOutdatedVersions($elementTypes, $ignoredIds); if (count($versions) == 0) { break; } $counter = 0; \Logger::debug("versions to check: " . count($versions)); if (is_array($versions) && !empty($versions)) { $totalCount = count($versions); foreach ($versions as $index => $id) { try { $version = Version::getById($id); } catch (\Exception $e) { $ignoredIds[] = $id; \Logger::debug("Version with " . $id . " not found\n"); continue; } $counter++; // do not delete public versions if ($version->getPublic()) { $ignoredIds[] = $version->getId(); continue; } if ($version->getCtype() == "document") { $element = Document::getById($version->getCid()); } elseif ($version->getCtype() == "asset") { $element = Asset::getById($version->getCid()); } elseif ($version->getCtype() == "object") { $element = Object::getById($version->getCid()); } if ($element instanceof ElementInterface) { \Logger::debug("currently checking Element-ID: " . $element->getId() . " Element-Type: " . Element\Service::getElementType($element) . " in cycle: " . $counter . "/" . $totalCount); if ($element->getModificationDate() >= $version->getDate()) { // delete version if it is outdated \Logger::debug("delete version: " . $version->getId() . " because it is outdated"); $version->delete(); } else { $ignoredIds[] = $version->getId(); \Logger::debug("do not delete version (" . $version->getId() . ") because version's date is newer than the actual modification date of the element. Element-ID: " . $element->getId() . " Element-Type: " . Element\Service::getElementType($element)); } } else { // delete version if the corresponding element doesn't exist anymore \Logger::debug("delete version (" . $version->getId() . ") because the corresponding element doesn't exist anymore"); $version->delete(); } // call the garbage collector if memory consumption is > 100MB if (memory_get_usage() > 100000000) { \Pimcore::collectGarbage(); } } } } }
public function getBatchAssignmentJobsAction() { $elementId = intval($this->getParam("elementId")); $elementType = strip_tags($this->getParam("elementType")); $idList = []; switch ($elementType) { case "object": $object = \Pimcore\Model\Object\AbstractObject::getById($elementId); if ($object) { $idList = $this->getSubObjectIds($object); } break; case "asset": $asset = \Pimcore\Model\Asset::getById($elementId); if ($asset) { $idList = $this->getSubAssetIds($asset); } break; case "document": $document = \Pimcore\Model\Document::getById($elementId); if ($document) { $idList = $this->getSubDocumentIds($document); } break; } $size = 2; $offset = 0; $idListParts = []; while ($offset < count($idList)) { $idListParts[] = array_slice($idList, $offset, $size); $offset += $size; } $this->_helper->json(['success' => true, 'idLists' => $idListParts, 'totalCount' => count($idList)]); }
/** * */ public static function execute() { $list = new Listing(); $list->setCondition("active = 1 AND date < ?", time()); $tasks = $list->load(); foreach ($tasks as $task) { try { if ($task->getCtype() == "document") { $document = Document::getById($task->getCid()); if ($document instanceof Document) { if ($task->getAction() == "publish-version" && $task->getVersion()) { try { $version = Version::getById($task->getVersion()); $document = $version->getData(); if ($document instanceof Document) { $document->setPublished(true); $document->save(); } else { \Logger::err("Schedule\\Task\\Executor: Could not restore document from version data."); } } catch (\Exception $e) { \Logger::err("Schedule\\Task\\Executor: Version [ " . $task->getVersion() . " ] does not exist."); } } else { if ($task->getAction() == "publish") { $document->setPublished(true); $document->save(); } else { if ($task->getAction() == "unpublish") { $document->setPublished(false); $document->save(); } else { if ($task->getAction() == "delete") { $document->delete(); } } } } } } else { if ($task->getCtype() == "asset") { $asset = Asset::getById($task->getCid()); if ($asset instanceof Asset) { if ($task->getAction() == "publish-version" && $task->getVersion()) { try { $version = Version::getById($task->getVersion()); $asset = $version->getData(); if ($asset instanceof Asset) { $asset->save(); } else { \Logger::err("Schedule\\Task\\Executor: Could not restore asset from version data."); } } catch (\Exception $e) { \Logger::err("Schedule\\Task\\Executor: Version [ " . $task->getVersion() . " ] does not exist."); } } else { if ($task->getAction() == "delete") { $asset->delete(); } } } } else { if ($task->getCtype() == "object") { $object = Object::getById($task->getCid()); if ($object instanceof Object) { if ($task->getAction() == "publish-version" && $task->getVersion()) { try { $version = Version::getById($task->getVersion()); $object = $version->getData(); if ($object instanceof Object\AbstractObject) { $object->setPublished(true); $object->save(); } else { \Logger::err("Schedule\\Task\\Executor: Could not restore object from version data."); } } catch (\Exception $e) { \Logger::err("Schedule\\Task\\Executor: Version [ " . $task->getVersion() . " ] does not exist."); } } else { if ($task->getAction() == "publish") { $object->setPublished(true); $object->save(); } else { if ($task->getAction() == "unpublish") { $object->setPublished(false); $object->save(); } else { if ($task->getAction() == "delete") { $object->delete(); } } } } } } } } $task->setActive(false); $task->save(); } catch (\Exception $e) { \Logger::err("There was a problem with the scheduled task ID: " . $task->getId()); \Logger::err($e); } } }
/** * @param $wsDocument * @throws \Exception */ protected function updateAsset($wsDocument) { $asset = Asset::getById($wsDocument->id); if ($asset === NULL) { throw new \Exception("Asset with given ID (" . $wsDocument->id . ") does not exist."); } $this->setModificationParams($asset, false); if ($asset instanceof Asset and $asset->getType() == strtolower($wsDocument->type)) { $wsDocument->reverseMap($asset); $asset->save(); return true; } else { throw new \Exception("Type mismatch for given asset with ID [" . $wsDocument->id . "] and existing asset with id [" . $asset->getId() . "]"); } }
function waitTillFinished($videoId, $thumbnail) { $finished = false; // initial delay $video = Asset::getById($videoId); $thumb = $video->getThumbnail($thumbnail); if ($thumb["status"] != "finished") { sleep(20); } while (!$finished) { \Pimcore::collectGarbage(); $video = Asset::getById($videoId); $thumb = $video->getThumbnail($thumbnail); if ($thumb["status"] == "finished") { $finished = true; \Logger::debug("video [" . $video->getId() . "] FINISHED"); } else { if ($thumb["status"] == "inprogress") { $progress = Asset\Video\Thumbnail\Processor::getProgress($thumb["processId"]); \Logger::debug("video [" . $video->getId() . "] in progress: " . number_format($progress, 0) . "%"); sleep(5); } else { // error \Logger::debug("video [" . $video->getId() . "] has status: '" . $thumb["status"] . "' -> skipping"); break; } } } }
public function getElement() { $data = $this->getData(); return Asset::getById($data['id']); }
/** * @param $dataArray * @param $idMapping * @return array */ private function rewriteIdsInDataEntries($dataArray, $idMapping) { $newDataArray = array(); if ($dataArray) { foreach ($dataArray as $dataArrayEntry) { if ($dataArrayEntry['data']) { $newData = array(); foreach ($dataArrayEntry['data'] as $dataEntry) { //rewrite objects if ($dataEntry['type'] == 'object' && $dataEntry['value']) { $id = $dataEntry['value']->getId(); if (array_key_exists("object", $idMapping) and array_key_exists($id, $idMapping["object"])) { $dataEntry['value'] = Object::getById($idMapping["object"][$id]); } } //rewrite assets if ($dataEntry['type'] == 'asset' && $dataEntry['value']) { $id = $dataEntry['value']->getId(); if (array_key_exists("asset", $idMapping) and array_key_exists($id, $idMapping["asset"])) { $dataEntry['value'] = Asset::getById($idMapping["asset"][$id]); } } //rewrite documents if ($dataEntry['type'] == 'document' && $dataEntry['value']) { $id = $dataEntry['value']->getId(); if (array_key_exists("document", $idMapping) and array_key_exists($id, $idMapping["document"])) { $dataEntry['value'] = Document::getById($idMapping["document"][$id]); } } $newData[] = $dataEntry; } $dataArrayEntry['data'] = $newData; } $newDataArray[] = $dataArrayEntry; } } return $newDataArray; }