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(); }
/** * @static * @param Document $doc * @return Document */ public static function upperCastDocument(Document $doc) { $to_class = "Document_Hardlink_Wrapper_" . ucfirst($doc->getType()); $old_serialized_prefix = "O:" . strlen(get_class($doc)); $old_serialized_prefix .= ":\"" . get_class($doc) . "\":"; $old_serialized_object = Pimcore_Tool_Serialize::serialize($doc); $new_serialized_object = 'O:' . strlen($to_class) . ':"' . $to_class . '":'; $new_serialized_object .= substr($old_serialized_object, strlen($old_serialized_prefix)); $document = Pimcore_Tool_Serialize::unserialize($new_serialized_object); return $document; }
protected function getCurrentConfiguration() { if (is_file($this->getConfigFile())) { $conf = Pimcore_Tool_Serialize::unserialize(file_get_contents($this->getConfigFile())); if ($conf["positions"]) { return $conf; } } // if no configuration exists, return the base config return array("positions" => array(array("pimcore.layout.portlets.modificationStatistic", "pimcore.layout.portlets.modifiedAssets"), array("pimcore.layout.portlets.modifiedObjects", "pimcore.layout.portlets.modifiedDocuments"))); }
public function load() { $fields = array(); $objectBricksFolder = PIMCORE_CLASS_DIRECTORY . "/objectbricks"; if (is_dir($objectBricksFolder)) { $files = scandir($objectBricksFolder); foreach ($files as $file) { $file = $objectBricksFolder . "/" . $file; if (is_file($file)) { $fieldData = file_get_contents($file); $fields[] = Pimcore_Tool_Serialize::unserialize($fieldData); } } } return $fields; }
/** * @param $serializedFilename * @return void */ private function cleanupOldFiles($serializedFilename) { $this->oldClassDefinitions = array(); if (file_exists($serializedFilename)) { $prevSerialized = file_get_contents($serializedFilename); } $oldObject = Pimcore_Tool_Serialize::unserialize($prevSerialized); if (!empty($oldObject->classDefinitions)) { foreach ($oldObject->classDefinitions as $cl) { $this->oldClassDefinitions[$cl['classname']] = $cl['classname']; $class = Object_Class::getById($cl['classname']); $path = $this->getContainerClassFolder($class->getName()); @unlink($path . "/" . ucfirst($cl['fieldname'] . ".php")); foreach ($class->getFieldDefinitions() as $fieldDef) { if ($fieldDef instanceof Object_Class_Data_Objectbricks) { $allowedTypes = $fieldDef->getAllowedTypes(); $idx = array_search($this->getKey(), $allowedTypes); if ($idx !== false) { array_splice($allowedTypes, $idx, 1); } $fieldDef->setAllowedTypes($allowedTypes); } } $class->save(); } } }
public static function getByKey($key) { $fieldCollectionFolder = PIMCORE_CLASS_DIRECTORY . "/fieldcollections"; $fieldFile = $fieldCollectionFolder . "/" . $key . ".psf"; if (is_file($fieldFile)) { $fcData = file_get_contents($fieldFile); $fc = Pimcore_Tool_Serialize::unserialize($fcData); return $fc; } throw new Exception("Field-Collection with key: " . $key . " does not exist."); }
/** * @param mixed $domains * @return void */ public function setDomains($domains) { if (is_string($domains)) { $domains = Pimcore_Tool_Serialize::unserialize($domains); } $this->domains = $domains; }
/** * @see Object_Class_Data::getDataFromResource * @param string $data * @return string */ public function getDataFromResource($data) { return Pimcore_Tool_Serialize::unserialize($data); }
/** * @see Document_Tag_Interface::setDataFromResource * @param mixed $data * @return void */ public function setDataFromResource($data) { if (strlen($data) > 2) { $data = Pimcore_Tool_Serialize::unserialize($data); } $this->id = $data["id"]; $this->alt = $data["alt"]; $this->cropPercent = $data["cropPercent"]; $this->cropWidth = $data["cropWidth"]; $this->cropHeight = $data["cropHeight"]; $this->cropTop = $data["cropTop"]; $this->cropLeft = $data["cropLeft"]; try { $this->image = Asset_Image::getById($this->id); } catch (Exception $e) { } }
/** * Object * * @return mixed */ public function loadData() { if (!is_file($this->getFilePath()) or !is_readable($this->getFilePath())) { Logger::err("Version: cannot read version data from file system."); $this->delete(); return; } $data = file_get_contents($this->getFilePath()); if ($this->getSerialized()) { $data = Pimcore_Tool_Serialize::unserialize($data); } $data = Element_Service::renewReferences($data); $this->setData($data); return $data; }
/** * 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 = Pimcore_Tool_Serialize::unserialize(base64_decode($importValue)); Logger::log("table data"); Logger::log($value); if (is_array($value)) { return $value; } else { return null; } }
/** * @see Document_Tag_Interface::setDataFromResource * @param mixed $data * @return void */ public function setDataFromResource($data) { if ($data = Pimcore_Tool_Serialize::unserialize($data)) { $this->setDataFromEditmode($data); } }
/** * @param array $customSettings * @return void */ public function setCustomSettings($customSettings) { if (is_string($customSettings)) { $customSettings = Pimcore_Tool_Serialize::unserialize($customSettings); } $this->customSettings = $customSettings; }
public function doImportJobsAction() { $importSession = new Zend_Session_Namespace("element_import"); if (!$importSession->elementCounter) { $importSession->elementCounter = 0; } if (!$importSession->idMapping) { $importSession->idMapping = array(); } $this->removeViewRenderer(); $importDir = PIMCORE_TEMPORARY_DIRECTORY . "/import_" . Zend_Session::getId(); $file = $this->_getParam("file"); $task = $this->_getParam("task"); $parentId = $this->_getParam("parentId"); $type = $this->_getParam("type"); $overwrite = $this->_getParam("overwrite"); if ($overwrite == 1) { $overwrite = true; } else { $overwrite = false; } $importService = new Element_Import_Service($this->getUser()); if ($type == "document") { $rootElement = Document::getById($parentId); } else { if ($type == "object") { $rootElement = Object_Abstract::getById($parentId); } else { if ($type == "asset") { $rootElement = Asset::getById($parentId); } } } if (!$rootElement) { throw new Exception("Invalid root element for import"); } $importData = file_get_contents($importDir . "/" . $file); $apiData = Pimcore_Tool_Serialize::unserialize($importData); //first run - just save elements so that they are there if ($task == "create") { $apiElement = $apiData["element"]; $path = $apiData["path"]; $element = $importService->create($rootElement, $file, $path, $apiElement, $overwrite, $importSession->elementCounter); //set actual ID //store id mapping $importSession->idMapping[Element_Service::getType($element)][$apiElement->id] = $element->getId(); $importSession->elementCounter++; $importFile = $importDir . "/" . $file; file_put_contents($importFile, Pimcore_Tool_Serialize::serialize($apiData)); chmod($importFile, 0766); } else { if ($task == "resolveRelations") { $apiElement = $apiData["element"]; $type = $this->findElementType($apiElement); $importService->correctElementIdRelations($apiElement, $type, $importSession->idMapping); //correct relations if ($apiElement instanceof Webservice_Data_Object_Concrete) { $importService->correctObjectRelations($apiElement, $importSession->idMapping); } else { if ($apiElement instanceof Webservice_Data_Document_PageSnippet) { $importService->correctDocumentRelations($apiElement, $importSession->idMapping); } else { if ($apiElement instanceof Webservice_Data_Document_Link and $apiElement->internal) { $apiElement->target = $importSession->idMapping[$apiElement->internalType][$apiElement->target]; } } } $importFile = $importDir . "/" . $file; file_put_contents($importFile, Pimcore_Tool_Serialize::serialize($apiData)); chmod($importFile, 0766); } else { if ($task == "update") { $apiElement = $apiData["element"]; try { $this->updateImportElement($apiElement, $importService); } catch (Exception $e) { $type = $this->findElementType($apiElement); $parent = Element_Service::getElementById($type, $apiElement->parentId); $apiElement->key = $this->getImportCopyName($parent->getFullPath(), $apiElement->key, $apiElement->id, $type); //try again with different key $this->updateImportElement($apiElement, $importService); } } else { if ($task == "cleanup") { recursiveDelete($importDir); } } } } $this->_helper->json(array("success" => true)); //p_r($importService->getImportInfo()); }
/** * fills object field data values from CSV Import String * @param string $importValue * @return Object_Class_Data_Link */ public function getFromCsvImport($importValue) { $value = Pimcore_Tool_Serialize::unserialize(base64_decode($importValue)); if ($value instanceof Object_Data_Link) { return $value; } else { return null; } }
public function gridGetColumnConfigAction() { if ($this->_getParam("id")) { $class = Object_Class::getById($this->_getParam("id")); } else { if ($this->_getParam("name")) { $class = Object_Class::getByName($this->_getParam("name")); } } $gridType = "search"; if ($this->_getParam("gridtype")) { $gridType = $this->_getParam("gridtype"); } $fields = $class->getFieldDefinitions(); $types = array(); if ($this->_getParam("types")) { $types = explode(",", $this->_getParam("types")); } // grid config $gridConfig = array(); if ($this->_getParam("objectId")) { $configFiles["configFileClassUser"] = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $this->_getParam("objectId") . "_" . $class->getId() . "-user_" . $this->getUser()->getId() . ".psf"; $configFiles["configFileUser"] = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $this->_getParam("objectId") . "-user_" . $this->getUser()->getId() . ".psf"; // this is for backward compatibility (not based on user) $configFiles["configFileClassCompatible"] = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $this->_getParam("objectId") . "_" . $class->getId() . ".psf"; $configFiles["configFileCompatible"] = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $this->_getParam("objectId") . ".psf"; foreach ($configFiles as $configFile) { if (is_file($configFile)) { $gridConfig = Pimcore_Tool_Serialize::unserialize(file_get_contents($configFile)); break; } } } $localizedFields = array(); $objectbrickFields = array(); foreach ($fields as $key => $field) { if ($field instanceof Object_Class_Data_Localizedfields) { $localizedFields[] = $field; } else { if ($field instanceof Object_Class_Data_Objectbricks) { $objectbrickFields[] = $field; } } } $availableFields = array(); $systemColumns = array("id", "fullpath", "published", "creationDate", "modificationDate", "filename", "classname"); if (empty($gridConfig)) { $count = 0; if (!$this->_getParam("no_system_columns")) { foreach ($systemColumns as $sc) { $vis = $class->getPropertyVisibility(); $key = $sc; if ($key == "fullpath") { $key = "path"; } if (empty($types) && ($vis[$gridType][$key] || $gridType == "all")) { $availableFields[] = array("key" => $sc, "type" => "system", "label" => $sc, "position" => $count); $count++; } } } $includeBricks = !$this->_getParam("no_brick_columns"); foreach ($fields as $key => $field) { if ($field instanceof Object_Class_Data_Localizedfields) { foreach ($field->getFieldDefinitions() as $fd) { if (empty($types) || in_array($fd->getFieldType(), $types)) { $fd->setNoteditable(true); $fieldConfig = $this->getFieldGridConfig($fd, $gridType, $count); if (!empty($fieldConfig)) { $availableFields[] = $fieldConfig; $count++; } } } } else { if ($field instanceof Object_Class_Data_Objectbricks && $includeBricks) { if (in_array($field->getFieldType(), $types)) { $fieldConfig = $this->getFieldGridConfig($field, $gridType, $count); if (!empty($fieldConfig)) { $availableFields[] = $fieldConfig; $count++; } } else { $allowedTypes = $field->getAllowedTypes(); if (!empty($allowedTypes)) { foreach ($allowedTypes as $t) { $brickClass = Object_Objectbrick_Definition::getByKey($t); $brickFields = $brickClass->getFieldDefinitions(); if (!empty($brickFields)) { foreach ($brickFields as $bf) { $fieldConfig = $this->getFieldGridConfig($bf, $gridType, $count, false, $t . "~"); if (!empty($fieldConfig)) { $availableFields[] = $fieldConfig; $count++; } } } } } } } else { if (empty($types) || in_array($field->getFieldType(), $types)) { $fieldConfig = $this->getFieldGridConfig($field, $gridType, $count, !empty($types)); if (!empty($fieldConfig)) { $availableFields[] = $fieldConfig; $count++; } } } } } } else { $savedColumns = $gridConfig['columns']; foreach ($savedColumns as $key => $sc) { if (!$sc['hidden']) { if (in_array($key, $systemColumns)) { $availableFields[] = array("key" => $key, "type" => "system", "label" => $key, "position" => $sc['position']); } else { $keyParts = explode("~", $key); if (count($keyParts) > 1) { $brick = $keyParts[0]; $key = $keyParts[1]; $brickClass = Object_Objectbrick_Definition::getByKey($brick); $fd = $brickClass->getFieldDefinition($key); if (!empty($fd)) { $fieldConfig = $this->getFieldGridConfig($fd, $gridType, $sc['position'], true, $brick . "~"); if (!empty($fieldConfig)) { $availableFields[] = $fieldConfig; } } } else { $fd = $class->getFieldDefinition($key); //if not found, look for localized fields if (empty($fd)) { foreach ($localizedFields as $lf) { $fd = $lf->getFieldDefinition($key); if (!empty($fd)) { break; } } } if (!empty($fd)) { $fieldConfig = $this->getFieldGridConfig($fd, $gridType, $sc['position'], true); if (!empty($fieldConfig)) { $availableFields[] = $fieldConfig; } } } } } } } usort($availableFields, function ($a, $b) { if ($a["position"] == $b["position"]) { return 0; } return $a["position"] < $b["position"] ? -1 : 1; }); $language = $this->getLanguage(); if (!empty($gridConfig) && !empty($gridConfig['language'])) { $language = $gridConfig['language']; } $this->_helper->json(array("sortinfo" => $gridConfig['sortinfo'], "language" => $language, "availableFields" => $availableFields)); }
/** * Save object to database * * @return mixed */ protected function getLayoutData() { $file = PIMCORE_CLASS_DIRECTORY . "/definition_" . $this->model->getId() . ".psf"; if (is_file($file)) { return Pimcore_Tool_Serialize::unserialize(file_get_contents($file)); } return; }
/** * @see Document_Tag_Interface::setDataFromResource * @param mixed $data * @return void */ public function setDataFromResource($data) { if (!empty($data)) { $data = Pimcore_Tool_Serialize::unserialize($data); } $this->id = $data["id"]; $this->type = $data["type"]; $this->subtype = $data["subtype"]; $this->setElement(); }
/** * @static * @param $processId * @return int */ public static function getProgress($processId) { $instance = new self(); $instance->setProcessId($processId); if (is_file($instance->getJobFile())) { $instance = Pimcore_Tool_Serialize::unserialize(file_get_contents($instance->getJobFile())); } return $instance->getStatus(); }
/** * Returns the content of the requested cache entry * @param string $key * @return mixed */ public static function load($key, $doNotTestCacheValidity = false) { if (!self::$enabled) { Logger::debug("Key " . $key . " doesn't exist in cache (deactivated)"); return; } if ($cache = self::getInstance()) { $key = self::$cachePrefix . $key; $data = $cache->load($key, $doNotTestCacheValidity); // unserialize data, use custom serializer $data = Pimcore_Tool_Serialize::unserialize($data); if ($data) { Logger::debug("Successfully get data for key " . $key . " from cache"); } else { Logger::debug("Key " . $key . " doesn't exist in cache"); } return $data; } return; }
public static function getByKey($key) { $fc = null; $cacheKey = "fieldcollection_" . $key; try { $fc = Zend_Registry::get($cacheKey); if (!$fc) { throw new Exception("FieldCollection in registry is not valid"); } } catch (Exception $e) { $fieldCollectionFolder = PIMCORE_CLASS_DIRECTORY . "/fieldcollections"; $fieldFile = $fieldCollectionFolder . "/" . $key . ".psf"; if (is_file($fieldFile)) { $fcData = file_get_contents($fieldFile); $fc = Pimcore_Tool_Serialize::unserialize($fcData); Zend_Registry::set($cacheKey, $fc); } } if ($fc) { return $fc; } throw new Exception("Field-Collection with key: " . $key . " does not exist."); }
/** * @see Document_Tag_Interface::setDataFromResource * @param mixed $data * @return void */ public function setDataFromResource($data) { $this->indices = Pimcore_Tool_Serialize::unserialize($data); }
/** * Takes data from resource and convert it to internal objects * * @param mixed $data * @return void */ public function setDataFromResource($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::getById(intval($data)); } else { if ($this->type == "asset") { $this->data = Asset::getById(intval($data)); } else { if ($this->type == "object") { $this->data = Object_Abstract::getById(intval($data)); } else { if ($this->type == "date") { $this->data = Pimcore_Tool_Serialize::unserialize($data); } else { if ($this->type == "bool") { $this->data = false; if (!empty($data)) { $this->data = true; } } else { // plain text $this->data = $data; } } } } } }