public function maintenanceupload() { $list = new Asset_List(); $list->setCondition("type = 'video' AND customSettings NOT LIKE '%youtube%'"); $assets = $list->load(); foreach ($assets as $asset) { self::upload($asset); } }
/** * @static * @param array $types * @return void */ public static function assets($types = null) { if (empty($types)) { $types = array("folder", "image", "text", "audio", "video", "document", "archive", "unknown"); } $list = new Asset_List(); $list->setCondition("type IN ('" . implode("','", $types) . "')"); self::loadToCache($list); }
public function downloadAsZipAction() { $asset = Asset::getById($this->_getParam("id")); if ($asset->isAllowed("view")) { $archive_name = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/download.zip"; if (is_file($archive_name)) { unlink($archive_name); } $archive_folder = $asset->getFileSystemPath(); $zip = new ZipArchive(); if ($zip->open($archive_name, ZipArchive::CREATE) === TRUE) { $assetList = new Asset_List(); $assetList->setCondition("path LIKE ?", $asset->getFullPath() . "/%"); $assetList->setOrderKey("LENGTH(path)", false); $assetList->setOrder("ASC"); foreach ($assetList->load() as $a) { if ($a->isAllowed("view")) { if (!$a instanceof Asset_Folder) { $zip->addFile($a->getFileSystemPath(), substr($a->getFullPath(), 1)); } } } $zip->close(); } $this->getResponse()->setHeader("Content-Type", "application/zip", true); $this->getResponse()->setHeader("Content-Disposition", 'attachment; filename="' . $asset->getFilename() . '.zip"'); echo file_get_contents($archive_name); unlink($archive_name); } $this->removeViewRenderer(); }
/** * @return array */ public function getChilds() { if ($this->childs === null) { $list = new Asset_List(); $list->setCondition("parentId = ?", $this->getId()); $list->setOrderKey("filename"); $list->setOrder("asc"); $this->childs = $list->load(); } return $this->childs; }
public function testCopyAndDeleteAsset() { $assetList = new Asset_List(); $assetList->setCondition("`filename` like '%_data%' and `type` = 'folder'"); $assets = $assetList->load(); $parent = $assets[0]; $this->assertTrue($parent instanceof Asset_Folder); //remove childs if there are some if ($parent->hasChilds()) { foreach ($parent->getChilds() as $child) { $child->delete(); } } $assetList = new Asset_List(); $assetList->setCondition("`filename` like '%_data%' and `type` != 'folder'"); $assets = $assetList->load(); $image = $assets[0]; $this->assertTrue($image instanceof Asset_Image); $this->assertFalse($parent->hasChilds()); $service = new Asset_Service(User::getById(1)); //copy as child $service->copyAsChild($parent, $parent); $this->assertTrue($parent->hasChilds()); $this->assertTrue(count($parent->getChilds()) == 1); $childs = $parent->getChilds(); $this->assertTrue(Test_Tool::assetsAreEqual($parent, $childs[0], true)); //copy as child no. 2 $service->copyAsChild($parent, $image); $this->assertTrue($parent->hasChilds()); $this->assertTrue(count($parent->getChilds()) == 2); //copy recursivley $rootNode = Asset::getById(1); $copy = $service->copyRecursive($rootNode, $parent); $this->assertTrue($copy->hasChilds()); $this->assertTrue(count($copy->getChilds()) == 2); $this->assertTrue(Test_Tool::assetsAreEqual($parent, $copy, true)); //create unequal assets $asset1 = Asset_Image::create(1, array("filename" => uniqid() . rand(10, 99) . ".jpg", "data" => file_get_contents(TESTS_PATH . "/resources/assets/images/image1" . ".jpg"), "userOwner" => 1)); $asset2 = Asset_Image::create(1, array("filename" => uniqid() . rand(10, 99) . ".jpg", "data" => file_get_contents(TESTS_PATH . "/resources/assets/images/image2" . ".jpg"), "userOwner" => 1)); $this->assertFalse(Test_Tool::assetsAreEqual($asset1, $asset2, true)); //copy contents $asset1 = $service->copyContents($asset1, $asset2); $this->assertTrue(Test_Tool::assetsAreEqual($asset1, $asset2, true)); //todo copy contents must fail if types differ //delete recusively $shouldBeDeleted[] = $copy->getId(); $childs = $copy->getChilds(); foreach ($childs as $child) { $shouldBeDeleted[] = $child->getId(); } $copy->delete(); foreach ($shouldBeDeleted as $id) { $o = Asset::getById($id); $this->assertFalse($o instanceof Asset); } }
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_List(); $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) || in_array($thumbnail, $allowedThumbs)) { echo "generating thumbnail for image: " . $image->getFullpath() . " | " . $image->getId() . " | Thumbnail: " . $thumbnail . " : " . formatBytes(memory_get_usage()) . " \n"; $image->getThumbnail($thumbnail); } } } Pimcore::collectGarbage();
public function copyInfoAction() { $transactionId = time(); $pasteJobs = array(); $session = new Zend_Session_Namespace("pimcore_copy"); $session->{$transactionId} = array(); if ($this->_getParam("type") == "recursive") { $asset = Asset::getById($this->_getParam("sourceId")); // first of all the new parent $pasteJobs[] = array(array("url" => "/admin/asset/copy", "params" => array("sourceId" => $this->_getParam("sourceId"), "targetId" => $this->_getParam("targetId"), "type" => "child", "transactionId" => $transactionId, "saveParentId" => true))); if ($asset->hasChilds()) { // get amount of childs $list = new Asset_List(); $list->setCondition("path LIKE '" . $asset->getFullPath() . "/%'"); $list->setOrderKey("LENGTH(path)", false); $list->setOrder("ASC"); $childIds = $list->loadIdList(); if (count($childIds) > 0) { foreach ($childIds as $id) { $pasteJobs[] = array(array("url" => "/admin/asset/copy", "params" => array("sourceId" => $id, "targetParentId" => $this->_getParam("targetId"), "sourceParentId" => $this->_getParam("sourceId"), "type" => "child", "transactionId" => $transactionId))); } } } } else { if ($this->_getParam("type") == "child" || $this->_getParam("type") == "replace") { // the object itself is the last one $pasteJobs[] = array(array("url" => "/admin/asset/copy", "params" => array("sourceId" => $this->_getParam("sourceId"), "targetId" => $this->_getParam("targetId"), "type" => $this->_getParam("type"), "transactionId" => $transactionId))); } } $this->_helper->json(array("pastejobs" => $pasteJobs)); }