コード例 #1
0
ファイル: Item.php プロジェクト: ngocanh/pimcore
 public function restore()
 {
     $raw = file_get_contents($this->getStoreageFile());
     $element = Pimcore_Tool_Serialize::unserialize($raw);
     // check for element with the same name
     if ($element instanceof Document) {
         $indentElement = Document::getByPath($element->getFullpath());
         if ($indentElement) {
             $element->setKey($element->getKey() . "_restore");
         }
     } else {
         if ($element instanceof Asset) {
             $indentElement = Asset::getByPath($element->getFullpath());
             if ($indentElement) {
                 $element->setFilename($element->getFilename() . "_restore");
             }
         } else {
             if ($element instanceof Object_Abstract) {
                 $indentElement = Object_Abstract::getByPath($element->getFullpath());
                 if ($indentElement) {
                     $element->setKey($element->getKey() . "_restore");
                 }
             }
         }
     }
     $this->restoreChilds($element);
     $this->delete();
 }
コード例 #2
0
ファイル: Tree.php プロジェクト: shanky0110/pimcore-custom
 /**
  * Moves a file/directory
  *
  * @param string $sourcePath
  * @param string $destinationPath
  * @return void
  */
 public function move($sourcePath, $destinationPath)
 {
     $nameParts = explode("/", $sourcePath);
     $nameParts[count($nameParts) - 1] = Pimcore_File::getValidFilename($nameParts[count($nameParts) - 1]);
     $sourcePath = implode("/", $nameParts);
     $nameParts = explode("/", $destinationPath);
     $nameParts[count($nameParts) - 1] = Pimcore_File::getValidFilename($nameParts[count($nameParts) - 1]);
     $destinationPath = implode("/", $nameParts);
     try {
         if (dirname($sourcePath) == dirname($destinationPath)) {
             try {
                 $destinationNode = $this->getNodeForPath($destinationPath);
                 // If we got here, it means the destination exists, and needs to be overwritten
                 $destinationNode->delete();
             } catch (Sabre_DAV_Exception_FileNotFound $e) {
                 // If we got here, it means the destination node does not yet exist
                 Logger::warning("Sabre_DAV_Exception_FileNotFound");
             }
             $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());
         }
     } catch (Exception $e) {
         Logger::error($e);
     }
     $asset->save();
 }
コード例 #3
0
ファイル: Folder.php プロジェクト: shanky0110/pimcore-custom
 /**
  * Returns a children by the filename
  *
  * @param string $asset
  * @return array
  */
 function getChild($name)
 {
     $nameParts = explode("/", $name);
     $name = Pimcore_File::getValidFilename($nameParts[count($nameParts) - 1]);
     //$name = implode("/",$nameParts);
     if (is_string($name)) {
         $parentPath = $this->asset->getFullPath();
         if ($parentPath == "/") {
             $parentPath = "";
         }
         if (!($asset = Asset::getByPath($parentPath . "/" . $name))) {
             throw new Sabre_DAV_Exception_FileNotFound('File not found: ' . $name);
         }
     } else {
         if ($name instanceof Asset) {
             $asset = $name;
         }
     }
     if ($asset instanceof Asset) {
         if ($asset->getType() == "folder") {
             return new Asset_WebDAV_Folder($asset);
         } else {
             return new Asset_WebDAV_File($asset);
         }
     }
     throw new Sabre_DAV_Exception_FileNotFound('File not found: ' . $name);
 }
コード例 #4
0
ファイル: Image.php プロジェクト: jv10/pimpon
 public static function decode($value)
 {
     if ($value['type'] === self::TYPE) {
         return Asset::getByPath($value['data']);
     }
     return null;
 }
コード例 #5
0
ファイル: Property.php プロジェクト: ngocanh/pimcore
 /**
  * Takes data from editmode and convert it to internal objects
  *
  * @param mixed $data
  * @return void
  */
 public function setDataFromEditmode($data)
 {
     // IMPORTANT: if you use this method be sure that the type of the property is already set
     if ($this->type == "document") {
         $this->data = Document::getByPath($data);
     } else {
         if ($this->type == "asset") {
             $this->data = Asset::getByPath($data);
         } else {
             if ($this->type == "object") {
                 $this->data = Object_Abstract::getByPath($data);
             } else {
                 if ($this->type == "date") {
                     $this->data = new Zend_Date($data);
                 } else {
                     if ($this->type == "bool") {
                         $this->data = false;
                         if (!empty($data)) {
                             $this->data = true;
                         }
                     } else {
                         // plain text
                         $this->data = $data;
                     }
                 }
             }
         }
     }
 }
コード例 #6
0
ファイル: Config.php プロジェクト: ngocanh/pimcore
 /**
  * @static
  * @return mixed|Zend_Config
  */
 public static function getWebsiteConfig()
 {
     try {
         $config = Zend_Registry::get("pimcore_config_website");
     } catch (Exception $e) {
         $cacheKey = "website_config";
         if (!($config = Pimcore_Model_Cache::load($cacheKey))) {
             $websiteSettingFile = PIMCORE_CONFIGURATION_DIRECTORY . "/website.xml";
             $settingsArray = array();
             if (is_file($websiteSettingFile)) {
                 $rawConfig = new Zend_Config_Xml($websiteSettingFile);
                 $arrayData = $rawConfig->toArray();
                 foreach ($arrayData as $key => $value) {
                     $s = null;
                     if ($value["type"] == "document") {
                         $s = Document::getByPath($value["data"]);
                     } else {
                         if ($value["type"] == "asset") {
                             $s = Asset::getByPath($value["data"]);
                         } else {
                             if ($value["type"] == "object") {
                                 $s = Object_Abstract::getByPath($value["data"]);
                             } else {
                                 if ($value["type"] == "bool") {
                                     $s = (bool) $value["data"];
                                 } else {
                                     if ($value["type"] == "text") {
                                         $s = (string) $value["data"];
                                     }
                                 }
                             }
                         }
                     }
                     if ($s) {
                         $settingsArray[$key] = $s;
                     }
                 }
             }
             $config = new Zend_Config($settingsArray, true);
             Pimcore_Model_Cache::save($config, $cacheKey, array("websiteconfig", "system", "config"), null, 998);
         }
         self::setWebsiteConfig($config);
     }
     return $config;
 }
コード例 #7
0
ファイル: LinkController.php プロジェクト: ngocanh/pimcore
 protected function setValuesToDocument(Document_Link $link)
 {
     // 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();
         } else {
             if ($asset = Asset::getByPath($data["path"])) {
                 $data["linktype"] = "internal";
                 $data["internalType"] = "asset";
                 $data["internal"] = $asset->getId();
             } else {
                 $data["linktype"] = "direct";
                 $data["direct"] = $data["path"];
             }
         }
     }
     unset($data["path"]);
     $link->setValues($data);
     $this->addPropertiesToDocument($link);
 }
コード例 #8
0
ファイル: Service.php プロジェクト: ngocanh/pimcore
 /**
  * @static
  * @param  string $type
  * @param  string $path
  * @return Element_Interface
  */
 public static function getElementByPath($type, $path)
 {
     if ($type == "asset") {
         $element = Asset::getByPath($path);
     } else {
         if ($type == "object") {
             $element = Object_Abstract::getByPath($path);
         } else {
             if ($type == "document") {
                 $element = Document::getByPath($path);
             }
         }
     }
     return $element;
 }
コード例 #9
0
 public function copyAction()
 {
     $success = false;
     $sourceId = intval($this->_getParam("sourceId"));
     $source = Asset::getById($sourceId);
     $session = new Zend_Session_Namespace("pimcore_copy");
     $targetId = intval($this->_getParam("targetId"));
     if ($this->_getParam("targetParentId")) {
         $sourceParent = Asset::getById($this->_getParam("sourceParentId"));
         // this is because the key can get the prefix "_copy" if the target does already exists
         if ($session->{$this->_getParam("transactionId")}["parentId"]) {
             $targetParent = Asset::getById($session->{$this->_getParam("transactionId")}["parentId"]);
         } else {
             $targetParent = Asset::getById($this->_getParam("targetParentId"));
         }
         $targetPath = preg_replace("@^" . $sourceParent->getFullPath() . "@", $targetParent . "/", $source->getPath());
         $target = Asset::getByPath($targetPath);
     } else {
         $target = Asset::getById($targetId);
     }
     if ($target->isAllowed("create")) {
         $source = Asset::getById($sourceId);
         if ($source != null) {
             if ($this->_getParam("type") == "child") {
                 $newAsset = $this->_assetService->copyAsChild($target, $source);
                 // this is because the key can get the prefix "_copy" if the target does already exists
                 if ($this->_getParam("saveParentId")) {
                     $session->{$this->_getParam("transactionId")}["parentId"] = $newAsset->getId();
                 }
             } else {
                 if ($this->_getParam("type") == "replace") {
                     $this->_assetService->copyContents($target, $source);
                 }
             }
             $success = true;
         } else {
             Logger::debug("prevended copy/paste because asset with same path+key already exists in this location");
         }
     } else {
         Logger::error("could not execute copy/paste because of missing permissions on target [ " . $targetId . " ]");
         $this->_helper->json(array("error" => false, "message" => "missing_permission"));
     }
     $this->_helper->json(array("success" => $success));
 }
コード例 #10
0
$arrayData = $rawConfig->toArray();
$data = array();
foreach ($arrayData as $key => $value) {
    $setting = new WebsiteSetting();
    $setting->setName($key);
    $type = $value["type"];
    $setting->setType($type);
    $data = $value["data"];
    if ($type == "bool") {
        $data = (bool) $data;
    } else {
        if ($type == "document") {
            $data = Document::getByPath($value["data"]);
        } else {
            if ($type == "asset") {
                $data = Asset::getByPath($value["data"]);
            } else {
                if ($type == "object") {
                    $data = Object_Abstract::getByPath($value["data"]);
                }
            }
        }
    }
    if ($data instanceof Element_Interface) {
        $data = $data->getId();
    }
    $setting->setData($data);
    $siteId = $value["siteId"] > 0 ? (int) $value["siteId"] : null;
    $setting->setSiteId($siteId);
    $setting->save();
}
コード例 #11
0
ファイル: Asset.php プロジェクト: ngocanh/pimcore
 public function correctPath()
 {
     // set path
     if ($this->getId() != 1) {
         // not for the root node
         $parent = Asset::getById($this->getParentId());
         if ($parent) {
             $this->setPath(str_replace("//", "/", $parent->getFullPath() . "/"));
         } else {
             // parent document doesn't exist anymore, so delete this document
             //$this->delete();
             // parent document doesn't exist anymore, set the parent to to root
             $this->setParentId(1);
             $this->setPath("/");
         }
     }
     $duplicate = Asset::getByPath($this->getFullPath());
     if ($duplicate instanceof Asset and $duplicate->getId() != $this->getId()) {
         throw new Exception("Duplicate full path [ " . $this->getFullPath() . " ] - cannot create asset");
     }
 }
コード例 #12
0
ファイル: Link.php プロジェクト: ngocanh/pimcore
 /**
  * @see Document_Tag_Interface::setDataFromEditmode
  * @param mixed $data
  * @return void
  */
 public function setDataFromEditmode($data)
 {
     if ($doc = Document::getByPath($data["path"])) {
         if ($doc instanceof Document) {
             $data["internal"] = true;
             $data["internalId"] = $doc->getId();
             $data["internalType"] = "document";
         }
     }
     if (!$data["internal"]) {
         if ($asset = Asset::getByPath($data["path"])) {
             if ($asset instanceof Asset) {
                 $data["internal"] = true;
                 $data["internalId"] = $asset->getId();
                 $data["internalType"] = "asset";
             }
         }
     }
     $this->data = $data;
 }
コード例 #13
0
ファイル: Link.php プロジェクト: shanky0110/pimcore-custom
 public function setPath($path)
 {
     if (!empty($path)) {
         if ($document = Document::getByPath($path)) {
             $this->linktype = "internal";
             $this->internalType = "document";
             $this->internal = $document->getId();
         } else {
             if ($asset = Asset::getByPath($path)) {
                 $this->linktype = "internal";
                 $this->internalType = "asset";
                 $this->internal = $asset->getId();
             } else {
                 $this->linktype = "direct";
                 $this->direct = $path;
             }
         }
     }
 }
コード例 #14
0
ファイル: Href.php プロジェクト: ngocanh/pimcore
 /**
  * fills object field data values from CSV Import String
  * @abstract
  * @param string $importValue
  * @param Object_Abstract $abstract
  * @return Object_Class_Data
  */
 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_Abstract::getByPath($importValue)) {
                     $value = $el;
                 }
             }
         }
     }
     return $value;
 }
コード例 #15
0
ファイル: Service.php プロジェクト: shanky0110/pimcore-custom
 /**
  * Returns a uniqe key for the document in the $target-Path (recursive)
  * @param Element_Interface $element
  */
 protected function getSaveCopyName($element, $key, $path)
 {
     if ($element instanceof Object_Abstract) {
         $equal = Object_Abstract::getByPath($path . "/" . $key);
     } else {
         if ($element instanceof Document) {
             $equal = Document::getByPath($path . "/" . $key);
         } else {
             if ($element instanceof Asset) {
                 $equal = Asset::getByPath($path . "/" . $key);
             }
         }
     }
     if ($equal) {
         $key .= "_WScopy";
         return $this->getSaveCopyName($element, $key, $path);
     }
     return $key;
 }
コード例 #16
0
ファイル: Image.php プロジェクト: ngocanh/pimcore
 /**
  * fills object field data values from CSV Import String
  * @abstract
  * @param string $importValue
  * @param Object_Abstract $abstract
  * @return Object_Class_Data
  */
 public function getFromCsvImport($importValue)
 {
     $value = null;
     if ($el = Asset::getByPath($importValue)) {
         $value = $el;
     } else {
         $value = null;
     }
     return $value;
 }
コード例 #17
0
ファイル: Multihref.php プロジェクト: ngocanh/pimcore
 /**
  * fills object field data values from CSV Import String
  * @abstract
  * @param string $importValue
  * @param Object_Abstract $abstract
  * @return Object_Class_Data
  */
 public function getFromCsvImport($importValue)
 {
     $values = explode(",", $importValue);
     $value = array();
     foreach ($values as $element) {
         $tokens = explode(":", $element);
         if (count($tokens) == 2) {
             $type = $tokens[0];
             $path = $tokens[1];
             $value[] = Element_Service::getElementByPath($type, $path);
         } else {
             //fallback for old export files
             if ($el = Asset::getByPath($element)) {
                 $value[] = $el;
             } else {
                 if ($el = Document::getByPath($element)) {
                     $value[] = $el;
                 } else {
                     if ($el = Object_Abstract::getByPath($element)) {
                         $value[] = $el;
                     }
                 }
             }
         }
     }
     return $value;
 }