/** * Try to load definition by name * * @param $name * @return AbstractModel|null */ protected function loadDefinition($name) { try { return Definition::getByKey($name); } catch (\Exception $e) { // noop } }
/** * */ public function createUpdateTable() { $table = $this->getTableName(); $context = $this->model->getContext(); if ($context && $context["containerType"] == "fieldcollection") { $this->db->query("CREATE TABLE IF NOT EXISTS `" . $table . "` (\n `ooo_id` int(11) NOT NULL default '0',\n `index` INT(11) NOT NULL DEFAULT '0',\n `fieldname` VARCHAR(190) NOT NULL DEFAULT '',\n `language` varchar(10) NOT NULL DEFAULT '',\n PRIMARY KEY (`ooo_id`, `language`, `index`, `fieldname`),\n INDEX `ooo_id` (`ooo_id`),\n INDEX `index` (`index`),\n INDEX `fieldname` (`fieldname`),\n INDEX `language` (`language`)\n ) DEFAULT CHARSET=utf8mb4;"); } else { $this->db->query("CREATE TABLE IF NOT EXISTS `" . $table . "` (\n `ooo_id` int(11) NOT NULL default '0',\n `language` varchar(10) NOT NULL DEFAULT '',\n PRIMARY KEY (`ooo_id`,`language`),\n INDEX `ooo_id` (`ooo_id`),\n INDEX `language` (`language`)\n ) DEFAULT CHARSET=utf8mb4;"); } $existingColumns = $this->getValidTableColumns($table, false); // no caching of table definition $columnsToRemove = $existingColumns; Object\ClassDefinition\Service::updateTableDefinitions($this->tableDefinitions, [$table]); if ($context && $context["containerType"] == "fieldcollection") { $protectedColumns = ["ooo_id", "language", "index", "fieldname"]; $containerKey = $context["containerKey"]; $container = Object\Fieldcollection\Definition::getByKey($containerKey); } else { $protectedColumns = ["ooo_id", "language"]; $container = $this->model->getClass(); } foreach ($container->getFielddefinition("localizedfields")->getFielddefinitions() as $value) { if ($value->getColumnType()) { $key = $value->getName(); if (is_array($value->getColumnType())) { // if a datafield requires more than one field foreach ($value->getColumnType() as $fkey => $fvalue) { $this->addModifyColumn($table, $key . "__" . $fkey, $fvalue, "", "NULL"); $protectedColumns[] = $key . "__" . $fkey; } } else { if ($value->getColumnType()) { $this->addModifyColumn($table, $key, $value->getColumnType(), "", "NULL"); $protectedColumns[] = $key; } } $this->addIndexToField($value, $table); } } $this->removeUnusedColumns($table, $columnsToRemove, $protectedColumns); $validLanguages = Tool::getValidLanguages(); if ($container instanceof Object\ClassDefinition) { foreach ($validLanguages as &$language) { $queryTable = $this->getQueryTableName(); $queryTable .= "_" . $language; $this->db->query("CREATE TABLE IF NOT EXISTS `" . $queryTable . "` (\n `ooo_id` int(11) NOT NULL default '0',\n `language` varchar(10) NOT NULL DEFAULT '',\n PRIMARY KEY (`ooo_id`,`language`),\n INDEX `ooo_id` (`ooo_id`),\n INDEX `language` (`language`)\n ) DEFAULT CHARSET=utf8mb4;"); // create object table if not exists $protectedColumns = ["ooo_id", "language"]; $existingColumns = $this->getValidTableColumns($queryTable, false); // no caching of table definition $columnsToRemove = $existingColumns; Object\ClassDefinition\Service::updateTableDefinitions($this->tableDefinitions, [$queryTable]); $fieldDefinitions = $this->model->getClass()->getFielddefinition("localizedfields")->getFielddefinitions(); // add non existing columns in the table if (is_array($fieldDefinitions) && count($fieldDefinitions)) { foreach ($fieldDefinitions as $value) { if ($value->getQueryColumnType()) { $key = $value->getName(); // 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($queryTable, $key . "__" . $fkey, $fvalue, "", "NULL"); $protectedColumns[] = $key . "__" . $fkey; } } // everything else if (!is_array($value->getQueryColumnType()) && $value->getQueryColumnType()) { $this->addModifyColumn($queryTable, $key, $value->getQueryColumnType(), "", "NULL"); $protectedColumns[] = $key; } // add indices $this->addIndexToField($value, $queryTable); } } } // remove unused columns in the table $this->removeUnusedColumns($queryTable, $columnsToRemove, $protectedColumns); } $this->createLocalizedViews(); } $this->tableDefinitions = null; }
/** * @param $type * @param null $fieldname * @throws \Exception */ public function addFieldCollection($type, $fieldname = null) { if (empty($type)) { throw new \Exception("No fieldcollectiontype given"); } Object\Fieldcollection\Definition::getByKey($type); $this->fieldCollectionConfigs[] = array("type" => $type, "fieldname" => $fieldname); }
/** * @return mixed */ public function getDefinition() { $definition = Model\Object\Fieldcollection\Definition::getByKey($this->getType()); return $definition; }
/** end point for the field collection definition * GET http://[YOUR-DOMAIN]/webservice/rest/field-collection/id/abt1?apikey=[API-KEY] * returns the class definition for the given class * */ public function fieldCollectionAction() { $this->checkUserPermission("classes"); try { $fc = Object\Fieldcollection\Definition::getByKey($this->getParam("id")); $this->_helper->json(array("success" => true, "data" => $fc)); } catch (\Exception $e) { \Logger::error($e); $this->encoder->encode(array("success" => false, "msg" => (string) $e)); } $this->encoder->encode(array("success" => false)); }
public function getNicePathAction() { $source = \Zend_Json::decode($this->getParam("source")); if ($source["type"] != "object") { throw new \Exception("currently only objects as source elements are supported"); } $result = []; $id = $source["id"]; $source = Object\Concrete::getById($id); if ($this->getParam("context")) { $context = \Zend_Json::decode($this->getParam("context")); } else { $context = []; } $ownerType = $context["containerType"]; $fieldname = $context["fieldname"]; if ($ownerType == "object") { $fd = $source->getClass()->getFieldDefinition($fieldname); } elseif ($ownerType == "localizedfield") { $fd = $source->getClass()->getFieldDefinition("localizedfields")->getFieldDefinition($fieldname); } elseif ($ownerType == "objectbrick") { $fdBrick = Object\Objectbrick\Definition::getByKey($context["containerKey"]); $fd = $fdBrick->getFieldDefinition($fieldname); } elseif ($ownerType == "fieldcollection") { $containerKey = $context["containerKey"]; $fdCollection = Object\Fieldcollection\Definition::getByKey($containerKey); if ($context["subContainerType"] == "localizedfield") { $fdLocalizedFields = $fdCollection->getFieldDefinition("localizedfields"); $fd = $fdLocalizedFields->getFieldDefinition($fieldname); } else { $fd = $fdCollection->getFieldDefinition($fieldname); } } if (method_exists($fd, "getPathFormatterClass")) { $formatterClass = $fd->getPathFormatterClass(); if (Pimcore\Tool::classExists($formatterClass)) { $targets = \Zend_Json::decode($this->getParam("targets")); $result = call_user_func($formatterClass . "::formatPath", $result, $source, $targets, ["fd" => $fd, "context" => $context]); } else { Logger::error("Formatter Class does not exist: " . $formatterClass); } } $this->_helper->json(["success" => true, "data" => $result]); }
public function removeFieldcollection($name) { try { $fc = Object\Fieldcollection\Definition::getByKey($name); if ($fc) { $fc->delete(); } } catch (\Exception $e) { return false; } return true; }
/** * @param Object\Concrete $object */ public function delete(Object\Concrete $object) { // empty or create all relevant tables $fieldDef = $object->getClass()->getFieldDefinition($this->model->getFieldname()); foreach ($fieldDef->getAllowedTypes() as $type) { try { $definition = Object\Fieldcollection\Definition::getByKey($type); } catch (\Exception $e) { continue; } $tableName = $definition->getTableName($object->getClass()); try { $this->db->delete($tableName, $this->db->quoteInto("o_id = ?", $object->getId()) . " AND " . $this->db->quoteInto("fieldname = ?", $this->model->getFieldname())); } catch (\Exception $e) { // create definition if it does not exist $definition->createUpdateTable($object->getClass()); } } // empty relation table $this->db->delete("object_relations_" . $object->getClassId(), "ownertype = 'fieldcollection' AND " . $this->db->quoteInto("ownername = ?", $this->model->getFieldname()) . " AND " . $this->db->quoteInto("src_id = ?", $object->getId())); }
/** * @param $name * @param $value * @param null $language * @return void */ public function setLocalizedValue($name, $value, $language = null) { if (self::$strictMode) { if (!$language || !in_array($language, Tool::getValidLanguages())) { throw new \Exception("Language " . $language . " not accepted in strict mode"); } } $language = $this->getLanguage($language); if (!$this->languageExists($language)) { $this->items[$language] = []; } $contextInfo = $this->getContext(); if ($contextInfo && $contextInfo["containerType"] == "block") { $classId = $contextInfo["classId"]; $containerDefinition = ClassDefinition::getById($classId); $blockDefinition = $containerDefinition->getFieldDefinition($contextInfo["fieldname"]); $fieldDefinition = $blockDefinition->getFieldDefinition("localizedfields"); } else { if ($contextInfo && $contextInfo["containerType"] == "fieldcollection") { $containerKey = $contextInfo["containerKey"]; $containerDefinition = Fieldcollection\Definition::getByKey($containerKey); } else { $containerDefinition = $this->getObject()->getClass(); } $localizedFieldDefinition = $containerDefinition->getFieldDefinition("localizedfields"); $fieldDefinition = $localizedFieldDefinition->getFieldDefinition($name); } if (method_exists($fieldDefinition, "preSetData")) { $value = $fieldDefinition->preSetData($this, $value, ["language" => $language, "name" => $name]); } $this->items[$language][$name] = $value; return $this; }
/** * @param $name * @param null $language * @return */ public function getLocalizedValue($name, $language = null, $ignoreFallbackLanguage = false) { $data = null; $language = $this->getLanguage($language); $context = $this->getContext(); if ($context && $context["containerType"] == "fieldcollection") { $containerKey = $context["containerKey"]; $container = Model\Object\Fieldcollection\Definition::getByKey($containerKey); } else { $container = $this->getObject()->getClass(); } $fieldDefinition = $container->getFieldDefinition("localizedfields")->getFieldDefinition($name); if ($fieldDefinition instanceof Model\Object\ClassDefinition\Data\CalculatedValue) { $valueData = new Model\Object\Data\CalculatedValue($fieldDefinition->getName()); $valueData->setContextualData("localizedfield", "localizedfields", null, $language); $data = Service::getCalculatedFieldValue($this->getObject(), $valueData); return $data; } if ($this->languageExists($language)) { if (array_key_exists($name, $this->items[$language])) { $data = $this->items[$language][$name]; } } // check for inherited value $doGetInheritedValues = AbstractObject::doGetInheritedValues(); if ($fieldDefinition->isEmpty($data) && $doGetInheritedValues) { $object = $this->getObject(); $class = $object->getClass(); $allowInherit = $class->getAllowInherit(); if ($allowInherit) { if ($object->getParent() instanceof AbstractObject) { $parent = $object->getParent(); while ($parent && $parent->getType() == "folder") { $parent = $parent->getParent(); } if ($parent && ($parent->getType() == "object" || $parent->getType() == "variant")) { if ($parent->getClassId() == $object->getClassId()) { $method = "getLocalizedfields"; if (method_exists($parent, $method)) { $localizedFields = $parent->getLocalizedFields(); if ($localizedFields instanceof Localizedfield) { if ($localizedFields->object->getId() != $this->object->getId()) { $data = $localizedFields->getLocalizedValue($name, $language, true); } } } } } } } } // check for fallback value if ($fieldDefinition->isEmpty($data) && !$ignoreFallbackLanguage && self::doGetFallbackValues()) { foreach (Tool::getFallbackLanguagesFor($language) as $l) { if ($this->languageExists($l)) { if (array_key_exists($name, $this->items[$l])) { if ($data = $this->getLocalizedValue($name, $l)) { break; } } } } } if ($fieldDefinition && method_exists($fieldDefinition, "preGetData")) { $data = $fieldDefinition->preGetData($this, ["data" => $data, "language" => $language, "name" => $name]); } return $data; }
/** * @param Object\Concrete $object */ public function delete(Object\Concrete $object) { // empty or create all relevant tables $fieldDef = $object->getClass()->getFieldDefinition($this->model->getFieldname()); foreach ($fieldDef->getAllowedTypes() as $type) { try { /** @var $definition Definition */ $definition = Object\Fieldcollection\Definition::getByKey($type); } catch (\Exception $e) { continue; } $tableName = $definition->getTableName($object->getClass()); try { $this->db->delete($tableName, $this->db->quoteInto("o_id = ?", $object->getId()) . " AND " . $this->db->quoteInto("fieldname = ?", $this->model->getFieldname())); } catch (\Exception $e) { // create definition if it does not exist $definition->createUpdateTable($object->getClass()); } if ($definition->getFieldDefinition("localizedfields")) { $tableName = $definition->getLocalizedTableName($object->getClass()); try { $this->db->delete($tableName, $this->db->quoteInto("ooo_id = ?", $object->getId()) . " AND " . $this->db->quoteInto("fieldname = ?", $this->model->getFieldname())); } catch (\Exception $e) { \Logger::error($e); } } $childDefinitions = $definition->getFielddefinitions(); if (is_array($childDefinitions)) { foreach ($childDefinitions as $fd) { if (method_exists($fd, "delete")) { $fd->delete($object, ["context" => ["containerType" => "fieldcollection", "containerKey" => $type, "fieldname" => $this->model->getFieldname()]]); } } } } // empty relation table $this->db->delete("object_relations_" . $object->getClassId(), "(ownertype = 'fieldcollection' AND " . $this->db->quoteInto("ownername = ?", $this->model->getFieldname()) . " AND " . $this->db->quoteInto("src_id = ?", $object->getId()) . ")" . " OR (ownertype = 'localizedfield' AND " . $this->db->quoteInto("ownername LIKE ?", "/fieldcollection~" . $this->model->getFieldname() . "/%") . ")"); }
/** * This method is called in Object|Class::save() and is used to create the database table for the localized data * @return void */ public function classSaved($class) { if (is_array($this->allowedTypes)) { foreach ($this->allowedTypes as $allowedType) { $definition = Object\Fieldcollection\Definition::getByKey($allowedType); if ($definition) { $fieldDefinition = $definition->getFieldDefinitions(); foreach ($fieldDefinition as $fd) { if (method_exists($fd, "classSaved")) { $fd->classSaved($class); } } } } } }
public function performFieldcollectionModificationCheck(Object\Concrete $object, $originalModificationDate, $data) { $modificationDate = $this->getParam("modificationDate"); if ($modificationDate != $originalModificationDate) { $fielddefinitions = $object->getClass()->getFieldDefinitions(); foreach ($fielddefinitions as $fd) { if ($fd instanceof Object\ClassDefinition\Data\Fieldcollections) { if (isset($data[$fd->getName()])) { $allowedTypes = $fd->getAllowedTypes(); foreach ($allowedTypes as $type) { /** @var $fdDef Object\Fieldcollection\Definition */ $fdDef = Object\Fieldcollection\Definition::getByKey($type); $childDefinitions = $fdDef->getFieldDefinitions(); foreach ($childDefinitions as $childDef) { if ($childDef instanceof Object\ClassDefinition\Data\Localizedfields) { $this->_helper->json(["success" => false, "message" => "Could be that someone messed around with the fieldcollection in the meantime. Please reload and try again"]); } } } } } } } }
/** * This method is called in Object|Class::save() and is used to create the database table for the localized data * @return void */ public function classSaved($class, $params = []) { if (is_array($this->allowedTypes)) { foreach ($this->allowedTypes as $allowedType) { $definition = Object\Fieldcollection\Definition::getByKey($allowedType); if ($definition) { $fieldDefinition = $definition->getFieldDefinitions(); foreach ($fieldDefinition as $fd) { if (method_exists($fd, "classSaved")) { if (!$fd instanceof Localizedfields) { // defer creation $fd->classSaved($class); } } } } } } }
/** * install function * @return string $message statusmessage to display in frontend */ public static function install() { //Cart \Pimcore\Resource::get()->query("CREATE TABLE `plugin_onlineshop_cart` (\n `id` int(20) NOT NULL AUTO_INCREMENT,\n `userid` int(20) NOT NULL,\n `name` varchar(250) COLLATE utf8_bin DEFAULT NULL,\n `creationDateTimestamp` int(10) NOT NULL,\n `modificationDateTimestamp` int(10) NOT NULL,\n PRIMARY KEY (`id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"); //CartCheckoutData \Pimcore\Resource::get()->query("CREATE TABLE `plugin_onlineshop_cartcheckoutdata` (\n `cartId` int(20) NOT NULL,\n `key` varchar(150) COLLATE utf8_bin NOT NULL,\n `data` longtext,\n PRIMARY KEY (`cartId`,`key`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"); //CartItem \Pimcore\Resource::get()->query("CREATE TABLE `plugin_onlineshop_cartitem` (\n `productId` int(20) NOT NULL,\n `cartId` int(20) NOT NULL,\n `count` int(20) NOT NULL,\n `itemKey` varchar(100) COLLATE utf8_bin NOT NULL,\n `parentItemKey` varchar(100) COLLATE utf8_bin NOT NULL DEFAULT '0',\n `comment` LONGTEXT ASCII,\n `addedDateTimestamp` int(10) NOT NULL,\n `sortIndex` INT(10) UNSIGNED NULL DEFAULT '0',\n PRIMARY KEY (`itemKey`,`cartId`,`parentItemKey`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;"); // Voucher Service // Statistics \Pimcore\Resource::get()->query("CREATE TABLE `plugins_onlineshop_vouchertoolkit_statistics` (\n `id` BIGINT(20) NOT NULL AUTO_INCREMENT,\n `voucherSeriesId` BIGINT(20) NOT NULL,\n `date` DATE NOT NULL,\n PRIMARY KEY (`id`)\n )\n COLLATE='utf8_general_ci'\n ENGINE=InnoDB ;"); // Tokens \Pimcore\Resource::get()->query("CREATE TABLE `plugins_onlineshop_vouchertoolkit_tokens` (\n `id` BIGINT(20) NOT NULL AUTO_INCREMENT,\n `voucherSeriesId` BIGINT(20) NULL DEFAULT NULL,\n `token` VARCHAR(250) NULL DEFAULT NULL COLLATE 'latin1_bin',\n `length` INT(11) NULL DEFAULT NULL,\n `type` VARCHAR(50) NULL DEFAULT NULL,\n `usages` BIGINT(20) NULL DEFAULT '0',\n `timestamp` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,\n PRIMARY KEY (`id`),\n UNIQUE INDEX `token` (`token`)\n )\n COLLATE='utf8_general_ci'\n ENGINE=InnoDB;"); // Reservations \Pimcore\Resource::get()->query("CREATE TABLE `plugins_onlineshop_vouchertoolkit_reservations` (\n `id` BIGINT(20) NOT NULL AUTO_INCREMENT,\n `token` VARCHAR(250) NOT NULL,\n `cart_id` VARCHAR(250) NOT NULL,\n `timestamp` DATETIME NOT NULL,\n PRIMARY KEY (`id`),\n INDEX `token` (`token`)\n )\n COLLATE='utf8_general_ci'\n ENGINE=InnoDB\n ;"); // Add FieldCollections $sourceFiles = scandir(PIMCORE_PLUGINS_PATH . '/OnlineShop/install/fieldcollection_sources'); foreach ($sourceFiles as $filename) { if (!is_dir($filename)) { preg_match('/_(.*)_/', $filename, $matches); $key = $matches[1]; try { $fieldCollection = \Pimcore\Model\Object\Fieldcollection\Definition::getByKey($key); } catch (Exception $e) { $fieldCollection = new \Pimcore\Model\Object\Fieldcollection\Definition(); $fieldCollection->setKey($key); } $data = file_get_contents(PIMCORE_PLUGINS_PATH . '/OnlineShop/install/fieldcollection_sources/' . $filename); $success = \Pimcore\Model\Object\ClassDefinition\Service::importFieldCollectionFromJson($fieldCollection, $data); if (!$success) { Logger::err("Could not import {$key} FieldCollection."); } } } // Add classes self::createClass("FilterDefinition", PIMCORE_PLUGINS_PATH . '/OnlineShop/install/class_source/class_FilterDefinition_export.json'); self::createClass("OnlineShopOrderItem", PIMCORE_PLUGINS_PATH . '/OnlineShop/install/class_source/class_OnlineShopOrderItem_export.json'); self::createClass("OnlineShopVoucherSeries", PIMCORE_PLUGINS_PATH . '/OnlineShop/install/class_source/class_OnlineShopVoucherSeries_export.json'); self::createClass("OnlineShopVoucherToken", PIMCORE_PLUGINS_PATH . '/OnlineShop/install/class_source/class_OnlineShopVoucherToken_export.json'); self::createClass("OnlineShopOrder", PIMCORE_PLUGINS_PATH . '/OnlineShop/install/class_source/class_OnlineShopOrder_export.json'); self::createClass("OfferToolOfferItem", PIMCORE_PLUGINS_PATH . '/OnlineShop/install/class_source/class_OfferToolOfferItem_export.json'); self::createClass("OfferToolOffer", PIMCORE_PLUGINS_PATH . '/OnlineShop/install/class_source/class_OfferToolOffer_export.json'); self::createClass("OfferToolCustomProduct", PIMCORE_PLUGINS_PATH . '/OnlineShop/install/class_source/class_OfferToolCustomProduct_export.json'); //copy config file if (!is_file(PIMCORE_WEBSITE_PATH . "/var/plugins/OnlineShop/OnlineShopConfig.xml")) { copy(PIMCORE_PLUGINS_PATH . "/OnlineShop/config/OnlineShopConfig_sample.xml", PIMCORE_WEBSITE_PATH . "/var/plugins/OnlineShop/OnlineShopConfig.xml"); copy(PIMCORE_PLUGINS_PATH . "/OnlineShop/config/.htaccess", PIMCORE_WEBSITE_PATH . "/var/plugins/OnlineShop/.htaccess"); } self::setConfig("/website/var/plugins/OnlineShop/OnlineShopConfig.xml"); // execute installations from subsystems $reflection = new ReflectionClass(__CLASS__); $methods = $reflection->getMethods(ReflectionMethod::IS_STATIC); foreach ($methods as $method) { /* @var ReflectionMethod $method */ if (preg_match('#^install[A-Z]#', $method->name)) { $func = $method->name; $success = self::$func(); } } // import admin-translations \Pimcore\Model\Translation\Admin::importTranslationsFromFile(PIMCORE_PLUGINS_PATH . '/OnlineShop/install/admin-translations/init.csv', true); // create status message if (self::isInstalled()) { $statusMessage = "installed"; // $translate->_("plugin_objectassetfolderrelation_installed_successfully"); } else { $statusMessage = "not installed"; // $translate->_("plugin_objectassetfolderrelation_could_not_install"); } return $statusMessage; }
/** * See http://www.pimcore.org/issues/browse/PIMCORE-2358 * Add option to export/import all class definitions/brick definitions etc. at once */ public function bulkCommitAction() { $filename = $this->getParam("filename"); $data = json_decode($this->getParam("data"), true); $json = @file_get_contents($filename); $json = json_decode($json, true); $type = $data["type"]; $name = $data["name"]; $list = $json[$type]; foreach ($list as $item) { unset($item["creationDate"]); unset($item["modificationDate"]); unset($item["userOwner"]); unset($item["userModification"]); unset($item["id"]); if ($type == "class" && $item["name"] == $name) { $class = Object\ClassDefinition::getByName($name); if (!$class) { $class = new Object\ClassDefinition(); $class->setName($name); } $success = Object\ClassDefinition\Service::importClassDefinitionFromJson($class, json_encode($item), true); $this->_helper->json(["success" => $success !== false]); } elseif ($type == "objectbrick" && $item["key"] == $name) { try { $brick = Object\Objectbrick\Definition::getByKey($name); } catch (\Exception $e) { $brick = new Object\Objectbrick\Definition(); $brick->setKey($name); } $success = Object\ClassDefinition\Service::importObjectBrickFromJson($brick, json_encode($item), true); $this->_helper->json(["success" => $success !== false]); } elseif ($type == "fieldcollection" && $item["key"] == $name) { try { $fieldCollection = Object\Fieldcollection\Definition::getByKey($name); } catch (\Exception $e) { $fieldCollection = new Object\Fieldcollection\Definition(); $fieldCollection->setKey($name); } $success = Object\ClassDefinition\Service::importFieldCollectionFromJson($fieldCollection, json_encode($item), true); $this->_helper->json(["success" => $success !== false]); } elseif ($type == "customlayout") { $layoutData = unserialize($data["name"]); $className = $layoutData["className"]; $layoutName = $layoutData["name"]; if ($item["name"] == $layoutName && $item["className"] == $className) { $class = Object\ClassDefinition::getByName($className); if (!$class) { throw new \Exception("Class does not exist"); } $classId = $class->getId(); $layoutList = new Object\ClassDefinition\CustomLayout\Listing(); $db = \Pimcore\Db::get(); $layoutList->setCondition("name = " . $db->quote($layoutName) . " AND classId = " . $classId); $layoutList = $layoutList->load(); $layoutDefinition = null; if ($layoutList) { $layoutDefinition = $layoutList[0]; } if (!$layoutDefinition) { $layoutDefinition = new Object\ClassDefinition\CustomLayout(); $layoutDefinition->setName($layoutName); $layoutDefinition->setClassId($classId); } try { $layoutDefinition->setDescription($item["description"]); $layoutDef = Object\ClassDefinition\Service::generateLayoutTreeFromArray($item["layoutDefinitions"], true); $layoutDefinition->setLayoutDefinitions($layoutDef); $layoutDefinition->save(); } catch (\Exception $e) { Logger::error($e->getMessage()); $this->_helper->json(["success" => false, "message" => $e->getMessage()]); } } } } $this->_helper->json(["success" => true]); }