/** * 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 setValuesToDocument(Document\Link $link) { // data if ($this->getParam("data")) { $data = \Zend_Json::decode($this->getParam("data")); if (!empty($data["path"])) { if ($document = Document::getByPath($data["path"])) { $data["linktype"] = "internal"; $data["internalType"] = "document"; $data["internal"] = $document->getId(); } elseif ($asset = Asset::getByPath($data["path"])) { $data["linktype"] = "internal"; $data["internalType"] = "asset"; $data["internal"] = $asset->getId(); } else { $data["linktype"] = "direct"; $data["direct"] = $data["path"]; } } else { // clear content of link $data["linktype"] = "internal"; $data["direct"] = ""; $data["internalType"] = null; $data["internal"] = null; } unset($data["path"]); $link->setValues($data); } $this->addPropertiesToDocument($link); }
public function getAssetTypesAction() { $assetTypes = Asset::getTypes(); $typeItems = []; foreach ($assetTypes as $assetType) { $typeItems[] = ["text" => $assetType]; } $this->_helper->json($typeItems); }
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; }
protected function update() { $this->clearThumbnails(); if ($this->getDataChanged()) { $tmpFile = $this->getTemporaryFile(); try { $pageCount = $this->readPageCount($tmpFile); if ($pageCount !== null && $pageCount > 0) { $this->setCustomSetting("document_page_count", $pageCount); } } catch (\Exception $e) { } unlink($tmpFile); } parent::update(); }
/** * @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); }
/** * Moves a file/directory * * @param string $sourcePath * @param string $destinationPath * @return void */ public function move($sourcePath, $destinationPath) { $nameParts = explode("/", $sourcePath); $nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]); $sourcePath = implode("/", $nameParts); $nameParts = explode("/", $destinationPath); $nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]); $destinationPath = implode("/", $nameParts); try { if (dirname($sourcePath) == dirname($destinationPath)) { $asset = null; if ($asset = Asset::getByPath("/" . $destinationPath)) { // If we got here, this means the destination exists, and needs to be overwritten $sourceAsset = Asset::getByPath("/" . $sourcePath); $asset->setData($sourceAsset->getData()); $sourceAsset->delete(); } // see: Asset\WebDAV\File::delete() why this is necessary $log = Asset\WebDAV\Service::getDeleteLog(); if (!$asset && array_key_exists("/" . $destinationPath, $log)) { $asset = \Pimcore\Tool\Serialize::unserialize($log["/" . $destinationPath]["data"]); if ($asset) { $sourceAsset = Asset::getByPath("/" . $sourcePath); $asset->setData($sourceAsset->getData()); $sourceAsset->delete(); } } if (!$asset) { $asset = Asset::getByPath("/" . $sourcePath); } $asset->setFilename(basename($destinationPath)); } else { $asset = Asset::getByPath("/" . $sourcePath); $parent = Asset::getByPath("/" . dirname($destinationPath)); $asset->setPath($parent->getFullPath() . "/"); $asset->setParentId($parent->getId()); } $user = \Pimcore\Tool\Admin::getCurrentUser(); $asset->setUserModification($user->getId()); $asset->save(); } catch (\Exception $e) { \Logger::error($e); } }
/** * @return void */ protected function update() { // only do this if the file exists and contains data if ($this->getDataChanged() || !$this->getCustomSetting("imageDimensionsCalculated")) { try { // save the current data into a tmp file to calculate the dimensions, otherwise updates wouldn't be updated // because the file is written in parent::update(); $tmpFile = $this->getTemporaryFile(); $dimensions = $this->getDimensions($tmpFile, true); unlink($tmpFile); if ($dimensions && $dimensions["width"]) { $this->setCustomSetting("imageWidth", $dimensions["width"]); $this->setCustomSetting("imageHeight", $dimensions["height"]); } } catch (\Exception $e) { Logger::error("Problem getting the dimensions of the image with ID " . $this->getId()); } // this is to be downward compatible so that the controller can check if the dimensions are already calculated // and also to just do the calculation once, because the calculation can fail, an then the controller tries to // calculate the dimensions on every request an also will create a version, ... $this->setCustomSetting("imageDimensionsCalculated", true); } parent::update(); $this->clearThumbnails(); // now directly create "system" thumbnails (eg. for the tree, ...) if ($this->getDataChanged()) { try { $path = $this->getThumbnail(Image\Thumbnail\Config::getPreviewConfig())->getFileSystemPath(); // set the modification time of the thumbnail to the same time from the asset // so that the thumbnail check doesn't fail in Asset\Image\Thumbnail\Processor::process(); // we need the @ in front of touch because of some stream wrapper (eg. s3) which don't support touch() @touch($path, $this->getModificationDate()); } catch (\Exception $e) { Logger::error("Problem while creating system-thumbnails for image " . $this->getRealFullPath()); Logger::error($e); } } }
/** * @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); }
/** * @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 $importValue * @return mixed|null|Asset|Document|Element\ElementInterface */ public function getFromCsvImport($importValue) { $value = null; $values = explode(":", $importValue); if (count($values) == 2) { $type = $values[0]; $path = $values[1]; $value = Element\Service::getElementByPath($type, $path); } else { //fallback for old export files if ($el = Asset::getByPath($importValue)) { $value = $el; } else { if ($el = Document::getByPath($importValue)) { $value = $el; } else { if ($el = Object::getByPath($importValue)) { $value = $el; } } } } return $value; }
/** * Get size of file in bytes * * @return integer */ function getSize() { return filesize($this->asset->getFileSystemPath()); }
/** * */ 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]); } }
/** Returns the total number of assets matching the given condition * GET http://[YOUR-DOMAIN]/webservice/rest/asset-count?apikey=[API-KEY]&condition=type%3D%27folder%27 * * Parameters: * - condition * - group by key */ public function assetCountAction() { $this->checkUserPermission("assets"); $condition = urldecode($this->getParam("condition")); $groupBy = $this->getParam("groupBy"); $params = array(); if (!empty($condition)) { $params["condition"] = $condition; } if (!empty($groupBy)) { $params["groupBy"] = $groupBy; } $count = Asset::getTotalCount($params); $this->encoder->encode(array("success" => true, "data" => array("totalCount" => $count))); }
/** * @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; }
private function getSubAssetIds(\Pimcore\Model\Asset $asset) { $childsList = new Pimcore\Model\Asset\Listing(); $condition = "path LIKE ?"; if (!$this->getUser()->isAdmin()) { $userIds = $this->getUser()->getRoles(); $userIds[] = $this->getUser()->getId(); $condition .= " AND (\n (SELECT `view` FROM users_workspaces_asset WHERE userId IN (\" . implode(',', {$userIds}) . \") and LOCATE(CONCAT(path,filename),cpath)=1 ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n OR\n (SELECT `view` FROM users_workspaces_asset WHERE userId IN (\" . implode(',', {$userIds}) . \") and LOCATE(cpath,CONCAT(path,filename))=1 ORDER BY LENGTH(cpath) DESC LIMIT 1)=1\n )"; } $childsList->setCondition($condition, $asset->getRealFullPath() . '/%'); return $childsList->loadIdList(); }
$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();
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; } } } }
/** * @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"); } } } }
/** * @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; }
public function portletModifiedAssetsAction() { $list = Asset::getList(["limit" => 10, "order" => "DESC", "orderKey" => "modificationDate"]); $response = []; $response["assets"] = []; foreach ($list as $doc) { $response["assets"][] = ["id" => $doc->getId(), "type" => $doc->getType(), "path" => $doc->getRealFullPath(), "date" => $doc->getModificationDate(), "condition" => "userModification = '" . $this->getUser()->getId() . "'"]; } $this->_helper->json($response); }
/** * */ 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(); } } } } }
/** * @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() . "]"); } }
/** * @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"); } } }
public function getElement() { $data = $this->getData(); return Asset::getById($data['id']); }
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; }