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));
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 /**
  * @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;
 }
Exemplo n.º 4
0
 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()));
     }
 }
Exemplo n.º 5
0
 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;
 }
Exemplo n.º 6
0
 /**
  * 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()));
 }
Exemplo n.º 7
0
 /**
  * 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()));
     }
 }
Exemplo n.º 8
0
 /**
  * @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));
 }
Exemplo n.º 10
0
 /**
  * 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;
     }
 }
Exemplo n.º 11
0
 /**
  * @param array $customSettings
  * @return void
  */
 public function setCustomSettings($customSettings)
 {
     if (is_string($customSettings)) {
         $customSettings = Pimcore_Tool_Serialize::unserialize($customSettings);
     }
     $this->customSettings = $customSettings;
 }
Exemplo n.º 12
0
 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));
 }
Exemplo n.º 13
0
 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"));
 }
Exemplo n.º 14
0
 /**
  * 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;
 }
Exemplo n.º 15
0
 /**
  * @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();
         }
     }
 }
Exemplo n.º 16
0
 /**
  * @param mixed $domains
  * @return void
  */
 public function setDomains($domains)
 {
     if (is_string($domains)) {
         $domains = Pimcore_Tool_Serialize::unserialize($domains);
     }
     $this->domains = $domains;
 }
Exemplo n.º 17
0
 /**
  * @return bool
  */
 public function save()
 {
     file_put_contents($this->getJobFile(), Pimcore_Tool_Serialize::serialize($this));
     return true;
 }
Exemplo n.º 18
0
 /**
  * @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);
 }
Exemplo n.º 19
0
 /**
  * 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);
     }
 }
Exemplo n.º 20
0
 /**
  * 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;
     }
 }
Exemplo n.º 21
0
 /**
  * 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");
     }
 }
Exemplo n.º 22
0
 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));
 }
Exemplo n.º 23
0
 /**
  * @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();
 }
Exemplo n.º 24
0
 /**
  * @see Object_Class_Data::getDataFromResource
  * @param string $data
  * @return string
  */
 public function getDataFromResource($data)
 {
     return Pimcore_Tool_Serialize::unserialize($data);
 }
Exemplo n.º 25
0
 /**
  * @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!");
             }
         }
     }
 }
Exemplo n.º 26
0
 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());
 }
Exemplo n.º 27
0
 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;
 }
Exemplo n.º 28
0
 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;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 29
0
 /**
  * @see Document_Tag_Interface::setDataFromResource
  * @param mixed $data
  * @return void
  */
 public function setDataFromResource($data)
 {
     $this->indices = Pimcore_Tool_Serialize::unserialize($data);
 }
Exemplo n.º 30
0
 /**
  * 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;
 }