/** * @param $log */ public static function saveDeleteLog($log) { // cleanup old entries $tmpLog = array(); foreach ($log as $path => $data) { if ($data["timestamp"] > time() - 30) { // remove 30 seconds old entries $tmpLog[$path] = $data; } } \Pimcore\File::put(Asset\WebDAV\Service::getDeleteLogFile(), serialize($tmpLog)); }
/** * @throws DAV\Exception\Forbidden * @throws \Exception */ function delete() { if ($this->asset->isAllowed("delete")) { Asset\Service::loadAllFields($this->asset); $this->asset->delete(); // add the asset to the delete history, this is used so come over problems with programs like photoshop (delete, create instead of replace => move) // for details see Asset\WebDAV\Tree::move() $log = Asset\WebDAV\Service::getDeleteLog(); $this->asset->_fulldump = true; $log[$this->asset->getFullpath()] = array("id" => $this->asset->getId(), "timestamp" => time(), "data" => \Pimcore\Tool\Serialize::serialize($this->asset)); unset($this->asset->_fulldump); Asset\WebDAV\Service::saveDeleteLog($log); } else { throw new DAV\Exception\Forbidden(); } }
/** * 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); } }