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(); } }
protected function execute(InputInterface $input, OutputInterface $output) { // disable versioning Version::disable(); // get all thumbnails $thumbnails = []; $list = new Asset\Video\Thumbnail\Config\Listing(); $items = $list->load(); foreach ($items as $item) { $thumbnails[] = $item->getName(); } $allowedThumbs = array(); if ($input->getOption("thumbnails")) { $allowedThumbs = explode(",", $input->getOption("thumbnails")); } // get only images $conditions = array("type = 'video'"); 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); $videos = $list->load(); foreach ($videos as $video) { foreach ($thumbnails as $thumbnail) { if (empty($allowedThumbs) && !$input->getOption("system") || in_array($thumbnail, $allowedThumbs)) { $this->output->writeln("generating thumbnail for video: " . $video->getFullpath() . " | " . $video->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage())); $video->getThumbnail($thumbnail); $this->waitTillFinished($video->getId(), $thumbnail); } } if ($input->getOption("system")) { $this->output->writeln("generating thumbnail for video: " . $video->getFullpath() . " | " . $video->getId() . " | Thumbnail: System Preview : " . formatBytes(memory_get_usage())); $thumbnail = Asset\Video\Thumbnail\Config::getPreviewConfig(); $video->getThumbnail($thumbnail); $this->waitTillFinished($video->getId(), $thumbnail); } } } }
$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(); foreach ($images as $image) { foreach ($thumbnails as $thumbnail) { if (empty($allowedThumbs) && !$opts->getOption("system") || in_array($thumbnail, $allowedThumbs)) { if ($opts->getOption("force")) { $image->clearThumbnail($thumbnail); } echo "generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()) . " \n"; echo "generated thumbnail: " . $image->getThumbnail($thumbnail) . "\n"; } }
public function gridProxyAction() { if ($this->getParam("data")) { if ($this->getParam("xaction") == "update") { //TODO probably not needed } } else { $db = \Pimcore\Resource::get(); // get list of objects $folder = Asset::getById($this->getParam("folderId")); $start = 0; $limit = 20; $orderKey = "id"; $order = "ASC"; if ($this->getParam("limit")) { $limit = $this->getParam("limit"); } if ($this->getParam("start")) { $start = $this->getParam("start"); } if ($this->getParam("dir")) { $order = $this->getParam("dir"); } if ($this->getParam("sort")) { $orderKey = $this->getParam("sort"); if ($orderKey == "fullpath") { $orderKey = array("path", "filename"); } } $conditionFilters = array(); if ($this->getParam("only_direct_children") == "true") { $conditionFilters[] = "parentId = " . $folder->getId(); } else { $conditionFilters[] = "path LIKE '" . ($folder->getFullPath() == "/" ? "/%'" : $folder->getFullPath() . "/%'"); } $conditionFilters[] = "type != 'folder'"; $filterJson = $this->getParam("filter"); if ($filterJson) { $filters = \Zend_Json::decode($filterJson); foreach ($filters as $filter) { $operator = "="; if ($filter["type"] == "string") { $operator = "LIKE"; } else { if ($filter["type"] == "numeric") { if ($filter["comparison"] == "lt") { $operator = "<"; } else { if ($filter["comparison"] == "gt") { $operator = ">"; } else { if ($filter["comparison"] == "eq") { $operator = "="; } } } } else { if ($filter["type"] == "date") { if ($filter["comparison"] == "lt") { $operator = "<"; } else { if ($filter["comparison"] == "gt") { $operator = ">"; } else { if ($filter["comparison"] == "eq") { $operator = "="; } } } $filter["value"] = strtotime($filter["value"]); } else { if ($filter["type"] == "list") { $operator = "="; } else { if ($filter["type"] == "boolean") { $operator = "="; $filter["value"] = (int) $filter["value"]; } } } } } // system field $value = $filter["value"]; if ($operator == "LIKE") { $value = "%" . $value . "%"; } $field = "`" . $filter["field"] . "` "; if ($filter["field"] == "fullpath") { $field = "CONCAT(path,filename)"; } $conditionFilters[] = $field . $operator . " " . $db->quote($value); } } $list = new Asset\Listing(); $condition = implode(" AND ", $conditionFilters); $list->setCondition($condition); $list->setLimit($limit); $list->setOffset($start); $list->setOrder($order); $list->setOrderKey($orderKey); $list->load(); $assets = array(); foreach ($list->getAssets() as $asset) { /** @var $asset Asset */ $filename = PIMCORE_ASSET_DIRECTORY . "/" . $asset->getFullPath(); $size = filesize($filename); $assets[] = array("id" => $asset->getid(), "type" => $asset->getType(), "fullpath" => $asset->getFullPath(), "creationDate" => $asset->getCreationDate(), "modificationDate" => $asset->getModificationDate(), "size" => formatBytes($size), "idPath" => $data["idPath"] = Element\Service::getIdPath($asset)); } $this->_helper->json(array("data" => $assets, "success" => true, "total" => $list->getTotalCount())); } }