/** * */ public function save() { $data = $this->model->getDataForResource(); if (is_array($data) or is_object($data)) { $data = \Pimcore\Tool\Serialize::serialize($data); } $element = array("data" => $data, "documentId" => $this->model->getDocumentId(), "name" => $this->model->getName(), "type" => $this->model->getType()); $this->db->insertOrUpdate("documents_elements", $element); }
/** * @static * @param Document $doc * @return Document */ public static function upperCastDocument(Document $doc) { $to_class = "Pimcore\\Model\\Document\\Hardlink\\Wrapper\\" . ucfirst($doc->getType()); $old_serialized_prefix = "O:" . strlen(get_class($doc)); $old_serialized_prefix .= ":\"" . get_class($doc) . "\":"; // unset eventually existing children, because of performance reasons when serializing the document $doc->setChilds(null); $old_serialized_object = Serialize::serialize($doc); $new_serialized_object = 'O:' . strlen($to_class) . ':"' . $to_class . '":'; $new_serialized_object .= substr($old_serialized_object, strlen($old_serialized_prefix)); $document = Serialize::unserialize($new_serialized_object); return $document; }
/** * Save changes to database, it's an good idea to use save() instead * * @return void */ public function update() { $site = get_object_vars($this->model); foreach ($site as $key => $value) { if (in_array($key, $this->getValidTableColumns("schedule_tasks"))) { if (is_array($value) || is_object($value)) { $value = \Pimcore\Tool\Serialize::serialize($value); } elseif (is_bool($value)) { $value = (int) $value; } $data[$key] = $value; } } $this->db->update("schedule_tasks", $data, $this->db->quoteInto("id = ?", $this->model->getId())); }
/** * @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(); } }
/** * Save object to database * * @return void */ public function save() { $data = $this->model->getData(); if ($this->model->getType() == "object" || $this->model->getType() == "asset" || $this->model->getType() == "document") { if ($data instanceof Model\Element\ElementInterface) { $data = $data->getId(); } else { $data = null; } } if (is_array($data) || is_object($data)) { $data = \Pimcore\Tool\Serialize::serialize($data); } $saveData = array("cid" => $this->model->getCid(), "ctype" => $this->model->getCtype(), "cpath" => $this->model->getCpath(), "name" => $this->model->getName(), "type" => $this->model->getType(), "inheritable" => (int) $this->model->getInheritable(), "data" => $data); $this->db->insertOrUpdate("properties", $saveData); }
/** * @throws \Exception */ public function update() { try { $type = get_object_vars($this->model); foreach ($type as $key => $value) { if (in_array($key, $this->getValidTableColumns("targeting_personas"))) { if (is_array($value) || is_object($value)) { $value = Serialize::serialize($value); } if (is_bool($value)) { $value = (int) $value; } $data[$key] = $value; } } $this->db->update("targeting_personas", $data, $this->db->quoteInto("id = ?", $this->model->getId())); } catch (\Exception $e) { throw $e; } }
/** * @throws \Exception */ public function update() { try { $type = get_object_vars($this->model); foreach ($type as $key => $value) { if (in_array($key, $this->getValidTableColumns(self::TABLE_NAME_RELATIONS))) { if (is_bool($value)) { $value = (int) $value; } if (is_array($value) || is_object($value)) { $value = \Pimcore\Tool\Serialize::serialize($value); } $data[$key] = $value; } } $this->db->insertOrUpdate(self::TABLE_NAME_RELATIONS, $data); return $this->model; } catch (\Exception $e) { throw $e; } }
/** * @return void */ public function save() { // check if versioning is disabled for this process if (self::$disabled) { return; } if (!$this->date) { $this->setDate(time()); } $data = $this->getData(); // if necessary convert the data to save it to filesystem if (is_object($data) or is_array($data)) { // this is because of lazy loaded element inside documents and objects (eg: multihref, objects, fieldcollections, ...) if ($data instanceof Element\ElementInterface) { Element\Service::loadAllFields($data); } $this->setSerialized(true); $data->_fulldump = true; $dataString = Serialize::serialize($data); // revert all changed made by __sleep() if (method_exists($data, "__wakeup")) { $data->__wakeup(); } unset($data->_fulldump); } else { $dataString = $data; } $this->id = $this->getDao()->save(); // check if directory exists $saveDir = dirname($this->getFilePath()); if (!is_dir($saveDir)) { File::mkdir($saveDir); } // save data to filesystem if (!is_writable(dirname($this->getFilePath())) || is_file($this->getFilePath()) && !is_writable($this->getFilePath())) { throw new \Exception("Cannot save version for element " . $this->getCid() . " with type " . $this->getCtype() . " because the file " . $this->getFilePath() . " is not writeable."); } else { File::put($this->getFilePath(), $dataString); // assets are kina special because they can contain massive amount of binary data which isn't serialized, we append it to the data file if ($data instanceof Asset && $data->getType() != "folder") { // append binary data to version file $handle = fopen($this->getBinaryFilePath(), "w+"); $src = $data->getStream(); stream_copy_to_stream($src, $handle); fclose($handle); } } }
/** * @see Object\ClassDefinition\Data::getDataForResource * @param string $data * @param null|Model\Object\AbstractObject $object * @return string */ public function getDataForResource($data, $object = null) { return Serialize::serialize($data); }
/** * converts object data to a simple string value or CSV Export * @abstract * @param Model\Object\AbstractObject $object * @return string */ public function getForCsvExport($object) { $data = $this->getDataFromObjectParam($object); if ($data instanceof Object\Data\Hotspotimage) { return base64_encode(Serialize::serialize($data)); } else { return null; } }
/** * Update data from object to the database * * @throws \Exception */ public function update() { try { $this->model->setModificationDate(time()); $asset = get_object_vars($this->model); foreach ($asset as $key => $value) { if (in_array($key, $this->getValidTableColumns("assets"))) { if (is_array($value)) { $value = \Pimcore\Tool\Serialize::serialize($value); } $data[$key] = $value; } } // metadata $this->db->delete("assets_metadata", "cid = " . $this->model->getId()); $metadata = $this->model->getMetadata(); $data["hasMetaData"] = 0; if (!empty($metadata)) { foreach ($metadata as $metadataItem) { $metadataItem["cid"] = $this->model->getId(); unset($metadataItem['config']); if ($metadataItem["data"] instanceof Model\Element\ElementInterface) { $metadataItem["data"] = $metadataItem["data"]->getId(); } if (strlen($metadataItem["data"]) > 0) { $this->db->insert("assets_metadata", $metadataItem); $data["hasMetaData"] = 1; } } } $this->db->insertOrUpdate("assets", $data); // tree_locks $this->db->delete("tree_locks", "id = " . $this->model->getId() . " AND type = 'asset'"); if ($this->model->getLocked()) { $this->db->insert("tree_locks", array("id" => $this->model->getId(), "type" => "asset", "locked" => $this->model->getLocked())); } } catch (\Exception $e) { throw $e; } }
/** * @throws \Exception * @return void */ public function save() { if (!$this->getKey()) { throw new \Exception("A object-brick needs a key to be saved!"); } $objectBrickFolder = PIMCORE_CLASS_DIRECTORY . "/objectbricks"; // create folder if not exist if (!is_dir($objectBrickFolder)) { File::mkdir($objectBrickFolder); } $newClassDefinitions = array(); $classDefinitionsToDelete = array(); foreach ($this->classDefinitions as $cl) { if (!$cl['deleted']) { $newClassDefinitions[] = $cl; } else { $classDefinitionsToDelete[] = $cl; } } $this->classDefinitions = $newClassDefinitions; $serialized = Serialize::serialize($this); $serializedFilename = $objectBrickFolder . "/" . $this->getKey() . ".psf"; $this->cleanupOldFiles($serializedFilename); File::put($serializedFilename, $serialized); $extendClass = "Object\\Objectbrick\\Data\\AbstractData"; if ($this->getParentClass()) { $extendClass = $this->getParentClass(); $extendClass = "\\" . ltrim($extendClass, "\\"); } // create class $cd = '<?php '; $cd .= "\n\n"; $cd .= "/** Generated at " . date('c') . " */"; $cd .= "\n\n"; $cd .= "/**\n"; if ($_SERVER["REMOTE_ADDR"]) { $cd .= "* IP: " . $_SERVER["REMOTE_ADDR"] . "\n"; } $cd .= "*/\n"; $cd .= "\n\n"; $cd .= "namespace Pimcore\\Model\\Object\\Objectbrick\\Data;"; $cd .= "\n\n"; $cd .= "use Pimcore\\Model\\Object;"; $cd .= "\n\n"; $cd .= "class " . ucfirst($this->getKey()) . " extends " . $extendClass . " {"; $cd .= "\n\n"; $cd .= 'public $type = "' . $this->getKey() . "\";\n"; if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) { foreach ($this->getFieldDefinitions() as $key => $def) { $cd .= "public \$" . $key . ";\n"; } } $cd .= "\n\n"; if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) { foreach ($this->getFieldDefinitions() as $key => $def) { /** * @var $def Object\ClassDefinition\Data */ $cd .= $def->getGetterCodeObjectbrick($this); $cd .= $def->getSetterCodeObjectbrick($this); } } $cd .= "}\n"; $cd .= "\n"; $fieldClassFolder = PIMCORE_CLASS_DIRECTORY . "/Object/Objectbrick/Data"; if (!is_dir($fieldClassFolder)) { File::mkdir($fieldClassFolder); } $fieldClassFile = $fieldClassFolder . "/" . ucfirst($this->getKey()) . ".php"; File::put($fieldClassFile, $cd); $this->createContainerClasses(); $this->updateDatabase(); }
/** * converts object data to a simple string value or CSV Export * @abstract * @param Object\AbstractObject $object * @param array $params * @return string */ public function getForCsvExport($object, $params = array()) { $data = $this->getDataFromObjectParam($object); if (is_array($data)) { return base64_encode(Serialize::serialize($data)); } else { return null; } }
/** * @param null $thumbnailName * @return mixed */ public function getThumbnail($thumbnailName = null) { if (!$this->getImage()) { return ""; } $crop = null; if (is_array($this->getCrop())) { $crop = $this->getCrop(); } $thumbConfig = $this->getImage()->getThumbnailConfig($thumbnailName); if (!$thumbConfig && $crop) { $thumbConfig = new Asset\Image\Thumbnail\Config(); } if ($crop) { $thumbConfig->addItemAt(0, "cropPercent", array("width" => $crop["cropWidth"], "height" => $crop["cropHeight"], "y" => $crop["cropTop"], "x" => $crop["cropLeft"])); $hash = md5(\Pimcore\Tool\Serialize::serialize($thumbConfig->getItems())); $thumbConfig->setName($thumbConfig->getName() . "_auto_" . $hash); } return $this->getImage()->getThumbnail($thumbConfig); }
/** * @throws \Exception * @throws \Zend_Db_Adapter_Exception */ public function update() { $class = get_object_vars($this->model); $data = array(); foreach ($class as $key => $value) { if (in_array($key, $this->getValidTableColumns("classes"))) { if (is_array($value) || is_object($value)) { $value = Serialize::serialize($value); } else { if (is_bool($value)) { $value = (int) $value; } } $data[$key] = $value; } } $this->db->update("classes", $data, $this->db->quoteInto("id = ?", $this->model->getId())); // save definition as a serialized file $definitionFile = PIMCORE_CLASS_DIRECTORY . "/definition_" . $this->model->getId() . ".psf"; if (!is_writable(dirname($definitionFile)) || is_file($definitionFile) && !is_writable($definitionFile)) { throw new \Exception("Cannot write definition file in: " . $definitionFile . " please check write permission on this directory."); } File::put($definitionFile, Serialize::serialize($this->model->layoutDefinitions)); $objectTable = "object_query_" . $this->model->getId(); $objectDatastoreTable = "object_store_" . $this->model->getId(); $objectDatastoreTableRelation = "object_relations_" . $this->model->getId(); $objectView = "object_" . $this->model->getId(); // create object table if not exists $protectedColums = array("oo_id", "oo_classId", "oo_className"); $protectedDatastoreColumns = array("oo_id"); $this->db->query("CREATE TABLE IF NOT EXISTS `" . $objectTable . "` (\n\t\t\t `oo_id` int(11) NOT NULL default '0',\n\t\t\t `oo_classId` int(11) default '" . $this->model->getId() . "',\n\t\t\t `oo_className` varchar(255) default '" . $this->model->getName() . "',\n\t\t\t PRIMARY KEY (`oo_id`)\n\t\t\t) DEFAULT CHARSET=utf8;"); // update default value of classname columns $this->db->query('ALTER TABLE `' . $objectTable . "` ALTER COLUMN `oo_className` SET DEFAULT '" . $this->model->getName() . "';"); $this->db->query("CREATE TABLE IF NOT EXISTS `" . $objectDatastoreTable . "` (\n\t\t\t `oo_id` int(11) NOT NULL default '0',\n\t\t\t PRIMARY KEY (`oo_id`)\n\t\t\t) DEFAULT CHARSET=utf8;"); $this->db->query("CREATE TABLE IF NOT EXISTS `" . $objectDatastoreTableRelation . "` (\n `src_id` int(11) NOT NULL DEFAULT '0',\n `dest_id` int(11) NOT NULL DEFAULT '0',\n `type` varchar(50) NOT NULL DEFAULT '',\n `fieldname` varchar(70) NOT NULL DEFAULT '0',\n `index` int(11) unsigned NOT NULL DEFAULT '0',\n `ownertype` enum('object','fieldcollection','localizedfield','objectbrick') NOT NULL DEFAULT 'object',\n `ownername` varchar(70) NOT NULL DEFAULT '',\n `position` varchar(70) NOT NULL DEFAULT '0',\n PRIMARY KEY (`src_id`,`dest_id`,`ownertype`,`ownername`,`fieldname`,`type`,`position`),\n KEY `index` (`index`),\n KEY `src_id` (`src_id`),\n KEY `dest_id` (`dest_id`),\n KEY `fieldname` (`fieldname`),\n KEY `position` (`position`),\n KEY `ownertype` (`ownertype`),\n KEY `type` (`type`),\n KEY `ownername` (`ownername`)\n ) DEFAULT CHARSET=utf8;"); $existingColumns = $this->getValidTableColumns($objectTable, false); // no caching of table definition $existingDatastoreColumns = $this->getValidTableColumns($objectDatastoreTable, false); // no caching of table definition $columnsToRemove = $existingColumns; $datastoreColumnsToRemove = $existingDatastoreColumns; Object\ClassDefinition\Service::updateTableDefinitions($this->tableDefinitions, array($objectTable, $objectDatastoreTable)); // add non existing columns in the table if (is_array($this->model->getFieldDefinitions()) && count($this->model->getFieldDefinitions())) { foreach ($this->model->getFieldDefinitions() as $key => $value) { // if a datafield requires more than one column in the query table if (is_array($value->getQueryColumnType())) { foreach ($value->getQueryColumnType() as $fkey => $fvalue) { $this->addModifyColumn($objectTable, $key . "__" . $fkey, $fvalue, "", "NULL"); $protectedColums[] = $key . "__" . $fkey; } } // if a datafield requires more than one column in the datastore table => only for non-relation types if (!$value->isRelationType() && is_array($value->getColumnType())) { foreach ($value->getColumnType() as $fkey => $fvalue) { $this->addModifyColumn($objectDatastoreTable, $key . "__" . $fkey, $fvalue, "", "NULL"); $protectedDatastoreColumns[] = $key . "__" . $fkey; } } // everything else // if (!is_array($value->getQueryColumnType()) && !is_array($value->getColumnType())) { if (!is_array($value->getQueryColumnType()) && $value->getQueryColumnType()) { $this->addModifyColumn($objectTable, $key, $value->getQueryColumnType(), "", "NULL"); $protectedColums[] = $key; } if (!is_array($value->getColumnType()) && $value->getColumnType() && !$value->isRelationType()) { $this->addModifyColumn($objectDatastoreTable, $key, $value->getColumnType(), "", "NULL"); $protectedDatastoreColumns[] = $key; } // } // add indices $this->addIndexToField($value, $objectTable); $this->addIndexToField($value, $objectDatastoreTable); } } // remove unused columns in the table $this->removeUnusedColumns($objectTable, $columnsToRemove, $protectedColums); $this->removeUnusedColumns($objectDatastoreTable, $datastoreColumnsToRemove, $protectedDatastoreColumns, true); // create view try { //$this->db->query('CREATE OR REPLACE VIEW `' . $objectView . '` AS SELECT * FROM `objects` left JOIN `' . $objectTable . '` ON `objects`.`o_id` = `' . $objectTable . '`.`oo_id` WHERE `objects`.`o_classId` = ' . $this->model->getId() . ';'); $this->db->query('CREATE OR REPLACE VIEW `' . $objectView . '` AS SELECT * FROM `' . $objectTable . '` JOIN `objects` ON `objects`.`o_id` = `' . $objectTable . '`.`oo_id`;'); } catch (\Exception $e) { \Logger::debug($e); } $this->tableDefinitions = null; }
/** * @param User $user * @return void */ public function save($user = null) { if ($this->getElement() instanceof Element\ElementInterface) { $this->setType(Element\Service::getElementType($this->getElement())); } $this->setSubtype($this->getElement()->getType()); $this->setPath($this->getElement()->getFullPath()); $this->setDate(time()); $this->loadChilds($this->getElement()); if ($user instanceof Model\User) { $this->setDeletedby($user->getName()); } // serialize data Element\Service::loadAllFields($this->element); $this->element->_fulldump = true; $data = Serialize::serialize($this->getElement()); $this->getResource()->save(); if (!is_dir(PIMCORE_RECYCLEBIN_DIRECTORY)) { File::mkdir(PIMCORE_RECYCLEBIN_DIRECTORY); } File::put($this->getStoreageFile(), $data); $saveBinaryData = function ($element, $rec, $scope) { // assets are kina special because they can contain massive amount of binary data which isn't serialized, we create separate files for them if ($element instanceof Asset) { if ($element->getType() != "folder") { $handle = fopen($scope->getStorageFileBinary($element), "w+"); $src = $element->getStream(); stream_copy_to_stream($src, $handle); fclose($handle); } $children = $element->getChilds(); foreach ($children as $child) { $rec($child, $rec, $scope); } } }; $saveBinaryData($this->getElement(), $saveBinaryData, $this); @chmod($this->getStoreageFile(), File::getDefaultMode()); }
public function getImageThumbnailAction() { $fileinfo = $this->getParam("fileinfo"); $image = Asset\Image::getById(intval($this->getParam("id"))); $thumbnail = null; if ($this->getParam("thumbnail")) { $thumbnail = $image->getThumbnailConfig($this->getParam("thumbnail")); } if (!$thumbnail) { if ($this->getParam("config")) { $thumbnail = $image->getThumbnailConfig(\Zend_Json::decode($this->getParam("config"))); } else { $thumbnail = $image->getThumbnailConfig($this->getAllParams()); } } else { // no high-res images in admin mode (editmode) // this is mostly because of the document's image editable, which doesn't know anything about the thumbnail // configuration, so the dimensions would be incorrect (double the size) $thumbnail->setHighResolution(1); } $format = strtolower($thumbnail->getFormat()); if ($format == "source" || $format == "print") { $thumbnail->setFormat("PNG"); $format = "png"; } if ($this->getParam("treepreview")) { $thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig(); } if ($this->getParam("cropPercent")) { $thumbnail->addItemAt(0, "cropPercent", array("width" => $this->getParam("cropWidth"), "height" => $this->getParam("cropHeight"), "y" => $this->getParam("cropTop"), "x" => $this->getParam("cropLeft"))); $hash = md5(Tool\Serialize::serialize($this->getAllParams())); $thumbnail->setName($thumbnail->getName() . "_auto_" . $hash); } if ($this->getParam("download")) { $downloadFilename = str_replace("." . File::getFileExtension($image->getFilename()), "." . $thumbnail->getFormat(), $image->getFilename()); $downloadFilename = strtolower($downloadFilename); header('Content-Disposition: attachment; filename="' . $downloadFilename . '"'); } $thumbnail = $image->getThumbnail($thumbnail); if ($fileinfo) { $this->_helper->json(array("width" => $thumbnail->getWidth(), "height" => $thumbnail->getHeight())); } $thumbnailFile = PIMCORE_DOCUMENT_ROOT . $thumbnail; $fileExtension = File::getFileExtension($thumbnailFile); if (in_array($fileExtension, array("gif", "jpeg", "jpeg", "png", "pjpeg"))) { header("Content-Type: image/" . $fileExtension, true); } else { header("Content-Type: " . $image->getMimetype(), true); } header("Content-Length: " . filesize($thumbnailFile), true); $this->sendThumbnailCacheHeaders(); while (@ob_end_flush()) { } flush(); readfile($thumbnailFile); exit; }
/** * @throws \Exception */ public function update() { try { $type = get_object_vars($this->model); foreach ($type as $key => $value) { if (in_array($key, $this->getValidTableColumns(self::TABLE_NAME_TRANSLATOR))) { if (is_bool($value)) { $value = (int) $value; } if (is_array($value) || is_object($value)) { $value = \Pimcore\Tool\Serialize::serialize($value); } $data[$key] = $value; } } $this->db->update(self::TABLE_NAME_TRANSLATOR, $data, $this->db->quoteInto("id = ?", $this->model->getId())); } catch (\Exception $e) { throw $e; } }
/** * Rewrites id from source to target, $rewriteConfig contains * array( * "document" => array( * SOURCE_ID => TARGET_ID, * SOURCE_ID => TARGET_ID * ), * "object" => array(...), * "asset" => array(...) * ) * @param $document * @param $rewriteConfig * @return Document */ public static function rewriteIds($document, $rewriteConfig, $params = array()) { // rewriting elements only for snippets and pages if ($document instanceof Document\PageSnippet) { if (array_key_exists("enableInheritance", $params) && $params["enableInheritance"]) { $elements = $document->getElements(); $changedElements = array(); $contentMaster = $document->getContentMasterDocument(); if ($contentMaster instanceof Document\PageSnippet) { $contentMasterElements = $contentMaster->getElements(); foreach ($contentMasterElements as $contentMasterElement) { if (method_exists($contentMasterElement, "rewriteIds")) { $element = clone $contentMasterElement; $element->rewriteIds($rewriteConfig); if (Serialize::serialize($element) != Serialize::serialize($contentMasterElement)) { $changedElements[] = $element; } } } } if (count($changedElements) > 0) { $elements = $changedElements; } } else { $elements = $document->getElements(); foreach ($elements as &$element) { if (method_exists($element, "rewriteIds")) { $element->rewriteIds($rewriteConfig); } } } $document->setElements($elements); } else { if ($document instanceof Document\Hardlink) { if (array_key_exists("document", $rewriteConfig) && $document->getSourceId() && array_key_exists((int) $document->getSourceId(), $rewriteConfig["document"])) { $document->setSourceId($rewriteConfig["document"][(int) $document->getSourceId()]); } } else { if ($document instanceof Document\Link) { if (array_key_exists("document", $rewriteConfig) && $document->getLinktype() == "internal" && $document->getInternalType() == "document" && array_key_exists((int) $document->getInternal(), $rewriteConfig["document"])) { $document->setInternal($rewriteConfig["document"][(int) $document->getInternal()]); } } } } // rewriting properties $properties = $document->getProperties(); foreach ($properties as &$property) { $property->rewriteIds($rewriteConfig); } $document->setProperties($properties); return $document; }
/** * @throws \Exception * @throws \Zend_Db_Adapter_Exception */ public function update() { $class = get_object_vars($this->model); $data = array(); foreach ($class as $key => $value) { if (in_array($key, $this->getValidTableColumns("custom_layouts"))) { if (is_array($value) || is_object($value)) { $value = Serialize::serialize($value); } else { if (is_bool($value)) { $value = (int) $value; } } $data[$key] = $value; } } $this->db->update("custom_layouts", $data, $this->db->quoteInto("id = ?", $this->model->getId())); // save definition as a serialized file $definitionFile = PIMCORE_CUSTOMLAYOUT_DIRECTORY . "/custom_definition_" . $this->model->getId() . ".psf"; if (!is_writable(dirname($definitionFile)) || is_file($definitionFile) && !is_writable($definitionFile)) { throw new \Exception("Cannot write definition file in: " . $definitionFile . " please check write permission on this directory."); } File::put($definitionFile, Serialize::serialize($this->model->layoutDefinitions)); }
/** * @throws \Exception */ public function save() { if (!$this->getKey()) { throw new \Exception("A field-collection needs a key to be saved!"); } $fieldCollectionFolder = PIMCORE_CLASS_DIRECTORY . "/fieldcollections"; // create folder if not exist if (!is_dir($fieldCollectionFolder)) { File::mkdir($fieldCollectionFolder); } $serialized = Serialize::serialize($this); $definitionFile = $fieldCollectionFolder . "/" . $this->getKey() . ".psf"; if (!is_writable(dirname($definitionFile)) || is_file($definitionFile) && !is_writable($definitionFile)) { throw new \Exception("Cannot write definition file in: " . $definitionFile . " please check write permission on this directory."); } File::put($definitionFile, $serialized); $extendClass = "Object\\Fieldcollection\\Data\\AbstractData"; if ($this->getParentClass()) { $extendClass = $this->getParentClass(); $extendClass = "\\" . ltrim($extendClass, "\\"); } // create class file $cd = '<?php '; $cd .= "\n\n"; $cd .= "/** Generated at " . date('c') . " */"; $cd .= "\n\n"; $cd .= "/**\n"; if ($_SERVER["REMOTE_ADDR"]) { $cd .= "* IP: " . $_SERVER["REMOTE_ADDR"] . "\n"; } $cd .= "*/\n"; $cd .= "\n\n"; $cd .= "namespace Pimcore\\Model\\Object\\Fieldcollection\\Data;"; $cd .= "\n\n"; $cd .= "use Pimcore\\Model\\Object;"; $cd .= "\n\n"; $cd .= "class " . ucfirst($this->getKey()) . " extends " . $extendClass . " {"; $cd .= "\n\n"; $cd .= 'public $type = "' . $this->getKey() . "\";\n"; if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) { foreach ($this->getFieldDefinitions() as $key => $def) { $cd .= "public \$" . $key . ";\n"; } } $cd .= "\n\n"; if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) { $relationTypes = array(); foreach ($this->getFieldDefinitions() as $key => $def) { /** * @var $def Object\ClassDefinition\Data */ $cd .= $def->getGetterCodeFieldcollection($this); $cd .= $def->getSetterCodeFieldcollection($this); } } $cd .= "}\n"; $cd .= "\n"; $fieldClassFolder = PIMCORE_CLASS_DIRECTORY . "/Object/Fieldcollection/Data"; if (!is_dir($fieldClassFolder)) { File::mkdir($fieldClassFolder); } $classFile = $fieldClassFolder . "/" . ucfirst($this->getKey()) . ".php"; if (!is_writable(dirname($classFile)) || is_file($classFile) && !is_writable($classFile)) { throw new \Exception("Cannot write definition file in: " . $classFile . " please check write permission on this directory."); } File::put($classFile, $cd); // update classes $classList = new Object\ClassDefinition\Listing(); $classes = $classList->load(); if (is_array($classes)) { foreach ($classes as $class) { foreach ($class->getFieldDefinitions() as $fieldDef) { if ($fieldDef instanceof Object\ClassDefinition\Data\Fieldcollections) { if (in_array($this->getKey(), $fieldDef->getAllowedTypes())) { $this->getResource()->createUpdateTable($class); break; } } } } } }
public function saveFolderAction() { $object = Object::getById($this->getParam("id")); $classId = $this->getParam("class_id"); // general settings $general = \Zend_Json::decode($this->getParam("general")); $object->setValues($general); $object->setUserModification($this->getUser()->getId()); $object = $this->assignPropertiesFromEditmode($object); if ($object->isAllowed("publish")) { try { // grid config $gridConfig = \Zend_Json::decode($this->getParam("gridconfig")); if ($classId) { $configFile = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $object->getId() . "_" . $classId . "-user_" . $this->getUser()->getId() . ".psf"; } else { $configFile = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $object->getId() . "-user_" . $this->getUser()->getId() . ".psf"; } $configDir = dirname($configFile); if (!is_dir($configDir)) { File::mkdir($configDir); } File::put($configFile, Tool\Serialize::serialize($gridConfig)); $object->save(); $this->_helper->json(array("success" => true)); } catch (\Exception $e) { $this->_helper->json(array("success" => false, "message" => $e->getMessage())); } } $this->_helper->json(array("success" => false, "message" => "missing_permission")); }
public function getImageThumbnailAction() { $fileinfo = $this->getParam("fileinfo"); $image = Asset\Image::getById(intval($this->getParam("id"))); $thumbnail = null; if ($this->getParam("thumbnail")) { $thumbnail = $image->getThumbnailConfig($this->getParam("thumbnail")); } if (!$thumbnail) { if ($this->getParam("config")) { $thumbnail = $image->getThumbnailConfig(\Zend_Json::decode($this->getParam("config"))); } else { $thumbnail = $image->getThumbnailConfig($this->getAllParams()); } } else { // no high-res images in admin mode (editmode) // this is mostly because of the document's image editable, which doesn't know anything about the thumbnail // configuration, so the dimensions would be incorrect (double the size) $thumbnail->setHighResolution(1); } $format = strtolower($thumbnail->getFormat()); if ($format == "source" || $format == "print") { $thumbnail->setFormat("PNG"); } if ($this->getParam("treepreview")) { $thumbnail = Asset\Image\Thumbnail\Config::getPreviewConfig(); } if ($this->getParam("cropPercent")) { $thumbnail->addItemAt(0, "cropPercent", ["width" => $this->getParam("cropWidth"), "height" => $this->getParam("cropHeight"), "y" => $this->getParam("cropTop"), "x" => $this->getParam("cropLeft")]); $hash = md5(Tool\Serialize::serialize($this->getAllParams())); $thumbnail->setName($thumbnail->getName() . "_auto_" . $hash); } $thumbnail = $image->getThumbnail($thumbnail); if ($fileinfo) { $this->_helper->json(["width" => $thumbnail->getWidth(), "height" => $thumbnail->getHeight()]); } $thumbnailFile = $thumbnail->getFileSystemPath(); header("Content-Type: " . $thumbnail->getMimeType(), true); header("Access-Control-Allow-Origin: *"); // for Aviary.Feather (Adobe Creative SDK) header("Content-Length: " . filesize($thumbnailFile), true); $this->sendThumbnailCacheHeaders(); while (@ob_end_flush()) { } flush(); readfile($thumbnailFile); exit; }
/** * @see Object\ClassDefinition\Data::getDataForResource * @param string $data * @param null|Model\Object\AbstractObject $object * @param mixed $params * @return string */ public function getDataForResource($data, $object = null, $params = []) { $result = []; if (is_array($data)) { foreach ($data as $blockElements) { $resultElement = []; /** * @var $blockElement Object\Data\BlockElement */ foreach ($blockElements as $elementName => $blockElement) { /** @var $fd Object\ClassDefinition\Data */ $fd = $this->getFielddefinition($elementName); if (!$fd) { // class definition seems to have changed \Logger::warn("class definition seems to have changed, element name: " . $elementName); continue; } $elementData = $blockElement->getData(); $dataForResource = $fd->marshal($elementData, $object, ["raw" => true]); $blockElement->setData($dataForResource); // do not serialize the block element itself $resultElement[$elementName] = ["name" => $blockElement->getName(), "type" => $blockElement->getType(), "data" => $blockElement->getData()]; } $result[] = $resultElement; } } $result = Serialize::serialize($result); return $result; }
/** * Save changes to database, it's an good idea to use save() instead * * @return void */ public function update() { $ts = time(); $this->model->setModificationDate($ts); $site = get_object_vars($this->model); foreach ($site as $key => $value) { if (in_array($key, $this->getValidTableColumns("sites"))) { if (is_array($value) || is_object($value)) { $value = \Pimcore\Tool\Serialize::serialize($value); } if (is_bool($value)) { $value = (int) $value; } $data[$key] = $value; } } $this->db->update("sites", $data, $this->db->quoteInto("id = ?", $this->model->getId())); $this->model->clearDependentCache(); }
/** * @param $key */ public function deleteDashboard($key) { $this->loadFile(); unset($this->dashboards[$key]); File::put($this->getConfigFile(), Serialize::serialize($this->dashboards)); }
/** * @throws \Exception */ public function update() { try { $ts = time(); $this->model->setModificationDate($ts); $type = get_object_vars($this->model); foreach ($type as $key => $value) { if (in_array($key, $this->getValidTableColumns(self::TABLE_NAME_KEYS))) { if (is_bool($value)) { $value = (int) $value; } if (is_array($value) || is_object($value)) { if ($this->model->getType() == 'select') { $value = \Zend_Json::encode($value); } else { $value = \Pimcore\Tool\Serialize::serialize($value); } } $data[$key] = $value; } } $this->db->update(self::TABLE_NAME_KEYS, $data, $this->db->quoteInto("id = ?", $this->model->getId())); return $this->model; } catch (\Exception $e) { throw $e; } }
/** * @param $conf * @return Asset\Image\Thumbnail|string */ public function getThumbnail($conf) { $image = $this->getImage(); if ($image instanceof Asset) { $thumbConfig = $image->getThumbnailConfig($conf); if ($thumbConfig && $this->cropPercent) { $thumbConfig->addItemAt(0, "cropPercent", array("width" => $this->cropWidth, "height" => $this->cropHeight, "y" => $this->cropTop, "x" => $this->cropLeft)); $hash = md5(Serialize::serialize($thumbConfig->getItems())); $thumbConfig->setName($thumbConfig->getName() . "_auto_" . $hash); } return $image->getThumbnail($thumbConfig); } return ""; }
/** * This is just for compatibility, this method will be removed with the next major release * @depricated * @static * @param $config * @return self */ public static function getByLegacyConfig($config) { $pipe = new self(); if (isset($config["format"])) { $pipe->setFormat($config["format"]); } if (isset($config["quality"])) { $pipe->setQuality($config["quality"]); } if (isset($config["cover"])) { $pipe->addItem("cover", ["width" => $config["width"], "height" => $config["height"], "positioning" => "center"]); } elseif (isset($config["contain"])) { $pipe->addItem("contain", ["width" => $config["width"], "height" => $config["height"]]); } elseif (isset($config["frame"])) { $pipe->addItem("frame", ["width" => $config["width"], "height" => $config["height"]]); } elseif (isset($config["aspectratio"]) && $config["aspectratio"]) { if (isset($config["height"]) && isset($config["width"]) && $config["height"] > 0 && $config["width"] > 0) { $pipe->addItem("contain", ["width" => $config["width"], "height" => $config["height"]]); } elseif (isset($config["height"]) && $config["height"] > 0) { $pipe->addItem("scaleByHeight", ["height" => $config["height"]]); } else { $pipe->addItem("scaleByWidth", ["width" => $config["width"]]); } } else { if (!isset($config["width"]) && isset($config["height"])) { $pipe->addItem("scaleByHeight", ["height" => $config["height"]]); } elseif (isset($config["width"]) && !isset($config["height"])) { $pipe->addItem("scaleByWidth", ["width" => $config["width"]]); } elseif (isset($config["width"]) && isset($config["height"])) { $pipe->addItem("resize", ["width" => $config["width"], "height" => $config["height"]]); } } if (isset($config["highResolution"])) { $pipe->setHighResolution($config["highResolution"]); } $hash = md5(Serialize::serialize($pipe)); $pipe->setName("auto_" . $hash); return $pipe; }
/** * @throws \Exception */ public function update() { try { $typeSpecificTable = null; $validColumnsTypeSpecific = []; if (in_array($this->model->getType(), ["email", "hardlink", "link", "page", "snippet"])) { $typeSpecificTable = "documents_" . $this->model->getType(); $validColumnsTypeSpecific = $this->getValidTableColumns($typeSpecificTable); } $this->model->setModificationDate(time()); $document = get_object_vars($this->model); $dataDocument = []; $dataTypeSpecific = []; foreach ($document as $key => $value) { // check if the getter exists $getter = "get" . ucfirst($key); if (!method_exists($this->model, $getter)) { continue; } // get the value from the getter if (in_array($key, $this->getValidTableColumns("documents")) || in_array($key, $validColumnsTypeSpecific)) { $value = $this->model->{$getter}(); } else { continue; } if (is_bool($value)) { $value = (int) $value; } if (is_array($value)) { $value = Serialize::serialize($value); } if (in_array($key, $this->getValidTableColumns("documents"))) { $dataDocument[$key] = $value; } if (in_array($key, $validColumnsTypeSpecific)) { $dataTypeSpecific[$key] = $value; } } // use the real document path, just for the case that a documents gets saved in the frontend // and the page is within a site. see also: PIMCORE-2684 $dataDocument["path"] = $this->model->getRealPath(); // update the values in the database $this->db->insertOrUpdate("documents", $dataDocument); if ($typeSpecificTable) { $this->db->insertOrUpdate($typeSpecificTable, $dataTypeSpecific); } $this->updateLocks(); } catch (\Exception $e) { throw $e; } }