public function getUpdateInformationAction() { $id = $this->_getParam("id"); $type = $this->_getParam("type"); if ($type == "plugin") { $extensionPath = PIMCORE_PLUGINS_PATH . "/" . $id; } else { if ($type = "brick") { $extensionPath = PIMCORE_WEBSITE_PATH . "/var/areas/" . $id; } } $remoteConfig = array("token" => Pimcore_Liveconnect::getToken(), "id" => $id, "type" => $type, "revision" => trim(file_get_contents($extensionPath . "/.pimcore_extension_revision"))); $rawData = Pimcore_Tool::getHttpData("http://extensions.pimcore.org/update/getUpdateInformation.php", null, array("data" => base64_encode(Pimcore_Tool_Serialize::serialize($remoteConfig)))); if (!$rawData) { header('HTTP/1.1 403 Forbidden'); exit; } $steps = array(); $numberOfFiles = 0; $data = Zend_Json::decode($rawData); foreach ($data["revisions"] as $revision) { foreach ($revision["files"] as $file) { $steps[] = array("action" => $file["action"], "controller" => "download", "params" => array("id" => $id, "type" => $type, "path" => $file["path"], "revision" => $file["revision"])); $numberOfFiles++; } $steps[] = array("action" => "check-update-script", "controller" => "update", "params" => array("id" => $id, "type" => $type, "revision" => $revision["revision"])); } $this->_helper->json(array("steps" => $steps, "fileAmount" => $numberOfFiles)); }
protected function saveConfiguration($config) { if (!is_dir($this->getConfigDir())) { mkdir($this->getConfigDir()); } file_put_contents($this->getConfigFile(), Pimcore_Tool_Serialize::serialize($config)); chmod($this->getConfigFile(), 0766); }
/** * @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; }
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()); try { $this->db->insert("documents_elements", $element); } catch (Exception $e) { $this->db->update("documents_elements", $element, $this->db->quoteInto("documentId = ?", $this->model->getDocumentId()) . " AND " . $this->db->quoteInto("name = ?", $this->model->getName())); } }
/** * 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->validColumns)) { if (is_array($value) || is_object($value)) { $value = Pimcore_Tool_Serialize::serialize($value); } else { if (is_bool($value)) { $value = (int) $value; } } $data[$key] = $value; } } $this->db->update("schedule_tasks", $data, $this->db->quoteInto("id = ?", $this->model->getId())); }
/** * 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 Element_Interface) { $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); try { $this->db->insert("properties", $saveData); } catch (Exception $e) { $this->db->update("properties", $saveData, $this->db->quoteInto("name = ?", $this->model->getName()) . " AND " . $this->db->quoteInto("cid = ?", $this->model->getCid()) . " AND " . $this->db->quoteInto("ctype = ?", $this->model->getCtype())); } }
/** * @param User $user * @return void */ public function save($user = null) { if ($this->getElement() instanceof Element_Interface) { $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 User) { $this->setDeletedby($user->getName()); } // serialize data $this->element->_fulldump = true; $data = Pimcore_Tool_Serialize::serialize($this->getElement()); $this->getResource()->save(); if (!is_dir(PIMCORE_RECYCLEBIN_DIRECTORY)) { mkdir(PIMCORE_RECYCLEBIN_DIRECTORY); } file_put_contents($this->getStoreageFile(), $data); chmod($this->getStoreageFile(), 0766); }
public function downloadFileAction() { $id = $this->_getParam("id"); $type = $this->_getParam("type"); $path = $this->_getParam("path"); $revision = $this->_getParam("revision"); $remoteConfig = $this->_getAllParams(); $remoteConfig["token"] = Pimcore_Liveconnect::getToken(); $rawData = Pimcore_Tool::getHttpData("http://extensions.pimcore.org/download/downloadFile.php?data=" . base64_encode(Pimcore_Tool_Serialize::serialize($remoteConfig))); if (!$rawData) { header('HTTP/1.1 403 Forbidden'); exit; } $file = Zend_Json::decode($rawData); if ($type == "plugin") { $parentPath = PIMCORE_PLUGINS_PATH; } else { if ($type == "brick") { $parentPath = PIMCORE_WEBSITE_PATH . "/var/areas"; } } if (!is_dir($parentPath)) { mkdir($parentPath, 0755, true); } $fileDestPath = $parentPath . $path; if (!is_dir(dirname($fileDestPath))) { mkdir(dirname($fileDestPath), 0755, true); } file_put_contents($fileDestPath, base64_decode($file["content"])); chmod($fileDestPath, 0766); // write revision information $revisionFile = $parentPath . "/" . $id . "/.pimcore_extension_revision"; file_put_contents($revisionFile, $revision); chmod($revisionFile, 0766); $this->_helper->json(array("success" => true)); }
/** * This is just for compatibility, this method will be removed with the next major release * @depricated * @static * @param $config * @return Asset_Image_Thumbnail_Config */ public static function getByLegacyConfig($config) { $pipe = new Asset_Image_Thumbnail_Config(); $hash = md5(Pimcore_Tool_Serialize::serialize($config)); $pipe->setName("auto_" . $hash); if ($config["format"]) { $pipe->setFormat($config["format"]); } if ($config["quality"]) { $pipe->setQuality($config["quality"]); } /*if ($config["cropPercent"]) { $pipe->addItem("cropPercent", array( "width" => $config["cropWidth"], "height" => $config["cropHeight"], "y" => $config["cropTop"], "x" => $config["cropLeft"] )); }*/ if ($config["cover"]) { $pipe->addItem("cover", array("width" => $config["width"], "height" => $config["height"], "positioning" => "center")); } else { if ($config["contain"]) { $pipe->addItem("contain", array("width" => $config["width"], "height" => $config["height"])); } else { if ($config["frame"]) { $pipe->addItem("frame", array("width" => $config["width"], "height" => $config["height"])); } else { if ($config["aspectratio"]) { if ($config["height"] > 0 && $config["width"] > 0) { $pipe->addItem("contain", array("width" => $config["width"], "height" => $config["height"])); } else { if ($config["height"] > 0) { $pipe->addItem("scaleByHeight", array("height" => $config["height"])); } else { $pipe->addItem("scaleByWidth", array("width" => $config["width"])); } } } else { if (empty($config["width"]) && !empty($config["height"])) { $pipe->addItem("scaleByHeight", array("height" => $config["height"])); } else { if (!empty($config["width"]) && empty($config["height"])) { $pipe->addItem("scaleByWidth", array("width" => $config["width"])); } else { $pipe->addItem("resize", array("width" => $config["width"], "height" => $config["height"])); } } } } } } return $pipe; }
/** * @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)) { mkdir($objectBrickFolder); } $newClassDefinitions = array(); $classDefinitionsToDelete = array(); foreach ($this->classDefinitions as $cl) { if (!$cl['deleted']) { $newClassDefinitions[] = $cl; } else { $classDefinitionsToDelete[] = $cl; } } $this->classDefinitions = $newClassDefinitions; $serialized = Pimcore_Tool_Serialize::serialize($this); $serializedFilename = $objectBrickFolder . "/" . $this->getKey() . ".psf"; $this->cleanupOldFiles($serializedFilename); file_put_contents($serializedFilename, $serialized); chmod($serializedFilename, 0766); $extendClass = "Object_Objectbrick_Data_Abstract"; if ($this->getParentClass()) { $extendClass = $this->getParentClass(); } // create class $cd = '<?php '; $cd .= "\n\n"; $cd .= "class Object_Objectbrick_Data_" . 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_Class_Data */ $cd .= $def->getGetterCodeObjectbrick($this); $cd .= $def->getSetterCodeObjectbrick($this); } } $cd .= "}\n"; $cd .= "\n"; $fieldClassFolder = PIMCORE_CLASS_DIRECTORY . "/Object/Objectbrick/Data"; if (!is_dir($fieldClassFolder)) { mkdir($fieldClassFolder, 0766, true); } $fieldClassFile = $fieldClassFolder . "/" . ucfirst($this->getKey()) . ".php"; file_put_contents($fieldClassFile, $cd); chmod($fieldClassFile, 0766); $this->createContainerClasses(); $this->updateDatabase(); }
/** * @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_Interface) { Element_Service::loadAllFields($data); } $this->setSerialized(true); $data->_fulldump = true; $dataString = Pimcore_Tool_Serialize::serialize($this->getData()); unset($this->_fulldump); } else { $dataString = $data; } $this->id = $this->getResource()->save(); // check if directory exists $saveDir = dirname($this->getFilePath()); if (!is_dir($saveDir)) { mkdir($saveDir, 0766, true); } // 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_contents($this->getFilePath(), $dataString); } // only do this in the maintenance job, to improve the speed of mass imports //$this->cleanHistory(); }
/** * @see Object_Class_Data::getDataForResource * @param string $data * @param null|Object_Abstract $object * @return string */ public function getDataForResource($data, $object = null) { return Pimcore_Tool_Serialize::serialize($data); }
/** * @param Element_Interface $element * @return void */ public function setDataFromElement($element) { $this->data = null; $this->id = new Search_Backend_Data_Id($element); $this->fullPath = $element->getFullPath(); $this->creationDate = $element->getCreationDate(); $this->modificationDate = $element->getModificationDate(); $this->userModification = $element->getUserModification(); $this->userOwner = $element->getUserOwner(); $this->type = $element->getType(); if ($element instanceof Object_Concrete) { $this->subtype = $element->getO_className(); } else { $this->subtype = $this->type; } $properties = $element->getProperties(); if (is_array($properties)) { foreach ($properties as $nextProperty) { if ($nextProperty->getType() == 'text') { $this->properties .= $nextProperty->getData() . " "; } } } if ($element instanceof Document) { if ($element instanceof Document_Folder) { $this->data = $element->getKey(); $this->published = true; } else { if ($element instanceof Document_Link) { $this->published = $element->isPublished(); $this->data = $element->getName() . " " . $element->getTitle() . " " . $element->getHref(); } else { if ($element instanceof Document_PageSnippet) { $this->published = $element->isPublished(); $elements = $element->getElements(); if (is_array($elements)) { foreach ($elements as $tag) { if ($tag instanceof Document_Tag_Interface) { ob_start(); $this->data .= strip_tags($tag->frontend()) . " "; $this->data .= ob_get_clean(); } } } if ($element instanceof Document_Page) { $this->published = $element->isPublished(); $this->data .= " " . $element->getName() . " " . $element->getTitle() . " " . $element->getDescription() . " " . $element->getKeywords(); } } } } } else { if ($element instanceof Asset) { $this->data = $element->getFilename(); $this->published = true; } else { if ($element instanceof Object_Abstract) { if ($element instanceof Object_Concrete) { $getInheritedValues = Object_Abstract::doGetInheritedValues(); Object_Abstract::setGetInheritedValues(true); $this->published = $element->isPublished(); foreach ($element->getClass()->getFieldDefinitions() as $key => $value) { // Object_Class_Data_Fieldcollections is special because it doesn't support the csv export if ($value instanceof Object_Class_Data_Fieldcollections) { $getter = "get" . $value->getName(); $this->fieldcollectionData .= Pimcore_Tool_Serialize::serialize($value->getDataForEditmode($element->{$getter}(), $element)) . " "; } else { if ($value instanceof Object_Class_Data_Localizedfields) { $getter = "get" . $value->getName(); $this->localizedData .= Pimcore_Tool_Serialize::serialize($value->getDataForEditmode($element->{$getter}(), $element)) . " "; } else { $this->data .= $value->getForCsvExport($element) . " "; } } } Object_Abstract::setGetInheritedValues($getInheritedValues); } else { if ($element instanceof Object_Folder) { $this->data = $element->getKey(); $this->published = true; } } } else { Logger::crit("Search_Backend_Data received an unknown element!"); } } } }
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)) { mkdir($fieldCollectionFolder); } $serialized = Pimcore_Tool_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_contents($definitionFile, $serialized); chmod($definitionFile, 0766); $extendClass = "Object_Fieldcollection_Data_Abstract"; if ($this->getParentClass()) { $extendClass = $this->getParentClass(); } // create class file $cd = '<?php '; $cd .= "\n\n"; $cd .= "class Object_Fieldcollection_Data_" . 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_Class_Data */ $cd .= $def->getGetterCodeFieldcollection($this); $cd .= $def->getSetterCodeFieldcollection($this); // $cd .= '/**' . "\n"; // $cd .= '* @return ' . $def->getPhpdocType() . "\n"; // $cd .= '*/' . "\n"; // $cd .= "public function get" . ucfirst($key) . " () {\n"; // $cd .= "\t return " . '$this->' . $key . ";\n"; // $cd .= "}\n\n"; // // $cd .= '/**' . "\n"; // $cd .= '* @param ' . $def->getPhpdocType() . ' $' . $key . "\n"; // $cd .= "* @return void\n"; // $cd .= '*/' . "\n"; // $cd .= "public function set" . ucfirst($key) . " (" . '$' . $key . ") {\n"; // $cd .= "\t" . '$this->' . $key . " = " . '$' . $key . ";\n"; // $cd .= "}\n\n"; } } $cd .= "}\n"; $cd .= "\n"; $fieldClassFolder = PIMCORE_CLASS_DIRECTORY . "/Object/Fieldcollection/Data"; if (!is_dir($fieldClassFolder)) { mkdir($fieldClassFolder, 0766, true); } $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_contents($classFile, $cd); chmod($classFile, 0766); // update classes $classList = new Object_Class_List(); $classes = $classList->load(); if (is_array($classes)) { foreach ($classes as $class) { foreach ($class->getFieldDefinitions() as $fieldDef) { if ($fieldDef instanceof Object_Class_Data_Fieldcollections) { if (in_array($this->getKey(), $fieldDef->getAllowedTypes())) { $this->getResource()->createUpdateTable($class); break; } } } } } }
public function getImageThumbnailAction() { $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()); } } $format = strtolower($thumbnail->getFormat()); if ($format == "source") { $thumbnail->setFormat("PNG"); $format = "png"; } 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(Pimcore_Tool_Serialize::serialize($this->_getAllParams())); $thumbnail->setName("auto_" . $hash); } $this->getResponse()->setHeader("Content-Type", "image/" . $format, true); if ($this->_getParam("download")) { $this->getResponse()->setHeader("Content-Disposition", 'attachment; filename="' . $image->getFilename() . '"'); } readfile(PIMCORE_DOCUMENT_ROOT . $image->getThumbnail($thumbnail)); $this->removeViewRenderer(); }
public function getThumbnail($conf) { if ($this->image instanceof Asset) { $thumbConfig = $this->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(Pimcore_Tool_Serialize::serialize($thumbConfig->getItems())); $thumbConfig->setName("auto_" . $hash); } return $this->image->getThumbnail($thumbConfig); } return ""; }
public function getImageThumbnailAction() { $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()); } } $format = strtolower($thumbnail->getFormat()); if ($format == "source") { $thumbnail->setFormat("PNG"); $format = "png"; } 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(Pimcore_Tool_Serialize::serialize($this->_getAllParams())); $thumbnail->setName("auto_" . $hash); } $this->getResponse()->setHeader("Content-Type", "image/" . $format, true); if ($this->_getParam("download")) { $this->getResponse()->setHeader("Content-Disposition", 'attachment; filename="' . $image->getFilename() . '"'); } $thumbnailFile = PIMCORE_DOCUMENT_ROOT . $image->getThumbnail($thumbnail); $imageContent = file_get_contents($thumbnailFile); $fileExtension = Pimcore_File::getFileExtension($thumbnailFile); if (in_array($fileExtension, array("gif", "jpeg", "jpeg", "png"))) { header("Content-Type: image/" . $fileExtension); } else { header("Content-Type: " . $image->getMimetype()); } header("Content-Length: " . filesize($thumbnailFile)); echo $imageContent; exit; }
/** * @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->setSerialized(true); $data->_fulldump = true; $dataString = Pimcore_Tool_Serialize::serialize($this->getData()); unset($this->_fulldump); } else { $dataString = $data; } $this->id = $this->getResource()->save(); // check if directory exists $saveDir = dirname($this->getFilePath()); if (!is_dir($saveDir)) { mkdir($saveDir, 0766, true); } // 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_contents($this->getFilePath(), $dataString); } $this->cleanHistory(); }
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()); }
/** * converts object data to a simple string value or CSV Export * @abstract * @param Object_Abstract $object * @return string */ public function getForCsvExport($object) { $key = $this->getName(); $getter = "get" . ucfirst($key); if ($object->{$getter}() instanceof Object_Data_Link) { return base64_encode(Pimcore_Tool_Serialize::serialize($object->{$getter}())); } else { return null; } }
/** * Save changes to database, it's an good idea to use save() instead * * @return void */ public function update() { $class = get_object_vars($this->model); foreach ($class as $key => $value) { if (in_array($key, $this->validColumns)) { if (is_array($value) || is_object($value)) { $value = Pimcore_Tool_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())); // only for logging $setsql = array(); foreach ($data as $key => $value) { $setsql[] = "`" . $key . "` = '" . $value . "'"; } $this->logSql("UPDATE classes SET " . implode(",", $setsql) . " WHERE id = " . $this->db->quote($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_contents($definitionFile, Pimcore_Tool_Serialize::serialize($this->model->layoutDefinitions)); chmod($definitionFile, 0766); $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->dbexec("CREATE TABLE IF NOT EXISTS `" . $objectTable . "` (\r\n\t\t\t `oo_id` int(11) NOT NULL default '0',\r\n\t\t\t `oo_classId` int(11) default '" . $this->model->getId() . "',\r\n\t\t\t `oo_className` varchar(255) default '" . $this->model->getName() . "',\r\n\t\t\t PRIMARY KEY (`oo_id`)\r\n\t\t\t) DEFAULT CHARSET=utf8;"); $this->dbexec("CREATE TABLE IF NOT EXISTS `" . $objectDatastoreTable . "` (\r\n\t\t\t `oo_id` int(11) NOT NULL default '0',\r\n\t\t\t PRIMARY KEY (`oo_id`)\r\n\t\t\t) DEFAULT CHARSET=utf8;"); $this->dbexec("CREATE TABLE IF NOT EXISTS `" . $objectDatastoreTableRelation . "` (\r\n `src_id` int(11) NOT NULL DEFAULT '0',\r\n `dest_id` int(11) NOT NULL DEFAULT '0',\r\n `type` varchar(50) NOT NULL DEFAULT '',\r\n `fieldname` varchar(70) NOT NULL DEFAULT '0',\r\n `index` int(11) unsigned NOT NULL DEFAULT '0',\r\n `ownertype` enum('object','fieldcollection','localizedfield','objectbrick') NOT NULL DEFAULT 'object',\r\n `ownername` varchar(70) NOT NULL DEFAULT '',\r\n `position` varchar(11) NOT NULL DEFAULT '0',\r\n PRIMARY KEY (`src_id`,`dest_id`,`ownertype`,`ownername`,`fieldname`,`type`,`position`),\r\n KEY `index` (`index`),\r\n KEY `src_id` (`src_id`),\r\n KEY `dest_id` (`dest_id`),\r\n KEY `fieldname` (`fieldname`),\r\n KEY `position` (`position`),\r\n KEY `ownertype` (`ownertype`),\r\n KEY `type` (`type`),\r\n KEY `ownername` (`ownername`)\r\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; // add non existing columns in the table if (is_array($this->model->getFieldDefinitions()) && count($this->model->getFieldDefinitions())) { foreach ($this->model->getFieldDefinitions() as $key => $value) { // nullable & default value list($defaultvalue, $nullable) = $this->getDefaultValueAndNullableForField($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, $defaultvalue, $nullable); $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, $defaultvalue, $nullable); $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(), $defaultvalue, $nullable); $protectedColums[] = $key; } if (!is_array($value->getColumnType()) && $value->getColumnType() && !$value->isRelationType()) { $this->addModifyColumn($objectDatastoreTable, $key, $value->getColumnType(), $defaultvalue, $nullable); $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->dbexec('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->dbexec('CREATE OR REPLACE VIEW `' . $objectView . '` AS SELECT * FROM `' . $objectTable . '` JOIN `objects` ON `objects`.`o_id` = `' . $objectTable . '`.`oo_id`;'); } catch (Exception $e) { Logger::debug($e); } }
public function saveFolderAction() { $object = Object_Abstract::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)) { mkdir($configDir, 0755, true); } file_put_contents($configFile, Pimcore_Tool_Serialize::serialize($gridConfig)); chmod($configFile, 0766); $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")); }
/** * Write's an item to the cache // don't use the logger inside here * * @param array $config * @return void */ public static function storeToCache($data, $key, $tags = array(), $lifetime = null, $priority = null) { if (!self::$enabled) { return; } // don't put anything into the cache, when cache is cleared if (in_array("__CLEAR_ALL__", self::$clearedTagsStack)) { return; } // do not cache hardlink-wrappers if ($data instanceof Document_Hardlink_Wrapper_Interface) { return; } // $priority is currently just for sorting the items in self::addToSaveStack() // maybe it will be added to prioritize items for backends with volatile memories // get cache instance if ($cache = self::getInstance()) { if ($lifetime !== null) { $cache->setLifetime($lifetime); } if ($data instanceof Element_Interface) { // check for currupt data if ($data->getId() < 1) { return; } if (isset($data->_fulldump)) { unset($data->_fulldump); } // get dependencies for this element, array_values() because the tags from Element_Interface came with keys eg. array("object_123" => "object_123") $tags = array_values($data->getCacheTags($tags)); $type = get_class($data); Logger::debug("prepared " . $type . " " . $data->getFullPath() . " for data cache with tags: " . implode(",", $tags)); } // check for cleared tags, only item which are not cleared within the same session are stored to the cache if (is_array($tags)) { foreach ($tags as $t) { if (in_array($t, self::$clearedTagsStack)) { Logger::debug("Aborted caching for key: " . $key . " because it is in the clear stack"); return; } } } // serialize data, use custom serializer $data = Pimcore_Tool_Serialize::serialize($data); $key = self::$cachePrefix . $key; $success = $cache->save($data, $key, $tags); if ($success !== true) { Logger::error("Failed to add entry {$key} to the cache, item-size was " . formatBytes(strlen($data))); } Logger::debug("Added " . $key . " to cache"); } }
/** * Update data from object to the database * * @return void */ public function update() { try { $this->model->setModificationDate(time()); $asset = get_object_vars($this->model); foreach ($asset as $key => $value) { if (in_array($key, $this->validColumns)) { if (is_array($value)) { $value = Pimcore_Tool_Serialize::serialize($value); } $data[$key] = $value; } } // first try to insert a new record, this is because of the recyclebin restore try { $this->db->insert("assets", $data); } catch (Exception $e) { $this->db->update("assets", $data, $this->db->quoteInto("id = ?", $this->model->getId())); } } catch (Exception $e) { throw $e; } }
public function doExportJobsAction() { $exportSession = new Zend_Session_Namespace("element_export"); $exportName = "export_" . Zend_Session::getId(); $exportDir = PIMCORE_WEBSITE_PATH . "/var/tmp/" . $exportName; if (!$exportSession->elements) { $exportSession->type = $this->_getParam("type"); $exportSession->id = $this->_getParam("id"); $exportSession->includeRelations = (bool) $this->_getParam("includeRelations"); $exportSession->recursive = (bool) $this->_getParam("recursive"); $exportSession->counter = 0; $element = Element_Service::getElementById($exportSession->type, $exportSession->id); $exportSession->rootPath = $element->getPath(); $exportSession->rootType = Element_Service::getType($element); $exportSession->elements = array(Element_Service::getType($element) . "_" . $element->getId() => array("elementType" => Element_Service::getType($element), "element" => $element->getId(), "recursive" => $exportSession->recursive)); $exportSession->apiElements = array(); if (is_dir($exportDir)) { recursiveDelete($exportDir); } mkdir($exportDir, 0755, true); $this->_helper->json(array("more" => true, "totalElementsDone" => 0, "totalElementsFound" => 0)); } else { $data = array_pop($exportSession->elements); $element = Element_Service::getElementById($data["elementType"], $data["element"]); $recursive = $data["recursive"]; $exportService = new Element_Export_Service(); $apiElement = $exportService->getApiElement($element); $exportSession->foundRelations = $exportService->extractRelations($element, array_keys($exportSession->apiElements), $recursive, $exportSession->includeRelations); //make path relative to root if (Element_Service::getType($element) == $exportSession->rootType and $exportSession->rootPath == $element->getPath()) { $apiElement->path = ""; } else { if (Element_Service::getType($element) == $exportSession->rootType and strpos($element->getPath(), $exportSession->rootPath) === 0) { if ($exportSession->rootPath === "/") { $len = 1; } else { $len = strlen($exportSession->rootPath) - 1; } $apiElement->path = substr($element->getPath(), $len); } else { $apiElement->path = $element->getPath(); } } $path = $apiElement->path; //convert the Webservice _Out element to _In elements $outClass = get_class($apiElement); $inClass = str_replace("_Out", "_In", $outClass); $apiElementIn = new $inClass(); $objectVars = get_object_vars($apiElementIn); foreach ($objectVars as $var => $value) { if (property_exists(get_class($apiElement), $var)) { $apiElementIn->{$var} = $apiElement->{$var}; } } //remove parentId, add path $apiElementIn->parentId = null; $apiElement = $apiElementIn; $key = Element_Service::getType($element) . "_" . $element->getId(); $exportSession->apiElements[$key] = array("element" => $apiElement, "path" => $path); $exportFile = $exportDir . "/" . $exportSession->counter . "_" . $key; file_put_contents($exportFile, Pimcore_Tool_Serialize::serialize(array("element" => $apiElement, "path" => $path))); chmod($exportFile, 0766); $exportSession->elements = array_merge($exportSession->elements, $exportSession->foundRelations); if (count($exportSession->elements) == 0) { $exportArchive = $exportDir . ".zip"; if (is_file($exportArchive)) { unlink($exportArchive); } $zip = new ZipArchive(); $created = $zip->open($exportArchive, ZipArchive::CREATE); if ($created === TRUE) { $dh = opendir($exportDir); while ($file = readdir($dh)) { if ($file != '.' && $file != '..') { $fullFilePath = $exportDir . "/" . $file; if (is_file($fullFilePath)) { $zip->addFile($fullFilePath, str_replace($exportDir . "/", "", $fullFilePath)); } } } closedir($dh); $zip->close(); } } $exportSession->counter++; $this->_helper->json(array("more" => count($exportSession->elements) != 0, "totalElementsDone" => count($exportSession->apiElements), "totalElementsFound" => count($exportSession->foundRelations))); } }
public function verifyUploadAction() { $client = Pimcore_Tool::getHttpClient(); $client->setParameterPost("data", base64_encode(Pimcore_Tool_Serialize::serialize(array("id" => $this->_getParam("id"), "type" => $this->_getParam("type"), "token" => Pimcore_Liveconnect::getToken())))); $client->setUri("http://extensions.pimcore.org/share/verifyUpload.php"); $response = $client->request(Zend_Http_Client::POST); $this->_helper->json(array("success" => true)); }
/** * 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->validColumns)) { if (is_array($value) || is_object($value)) { $value = Pimcore_Tool_Serialize::serialize($value); } $data[$key] = $value; } } $this->db->update("sites", $data, $this->db->quoteInto("id = ?", $this->model->getId())); $this->model->clearDependedCache(); }
/** * @param User $user * @return void */ public function save($user = null) { if ($this->getElement() instanceof Document) { $this->setType("document"); } else { if ($this->getElement() instanceof Asset) { $this->setType("asset"); } else { if ($this->getElement() instanceof Object_Abstract) { $this->setType("object"); } } } $this->setSubtype($this->getElement()->getType()); $this->setPath($this->getElement()->getFullPath()); $this->setDate(time()); $this->loadChilds($this->getElement()); if ($user instanceof User) { $this->setDeletedby($user->getUsername()); } // serialize data $this->element->_fulldump = true; $data = Pimcore_Tool_Serialize::serialize($this->getElement()); $this->getResource()->save(); if (!is_dir(PIMCORE_RECYCLEBIN_DIRECTORY)) { mkdir(PIMCORE_RECYCLEBIN_DIRECTORY); } file_put_contents($this->getStoreageFile(), $data); chmod($this->getStoreageFile(), 0766); }
/** * @return bool */ public function save() { file_put_contents($this->getJobFile(), Pimcore_Tool_Serialize::serialize($this)); return true; }