importFieldCollectionFromJson() публичный статический Метод

public static importFieldCollectionFromJson ( $fieldCollection, $json, $throwException = false ) : boolean
$fieldCollection
$json
Результат boolean
Пример #1
0
 public function createFieldCollection($name, $jsonPath = null)
 {
     try {
         $fieldCollection = Object\Fieldcollection\Definition::getByKey($name);
     } catch (\Exception $e) {
         if ($jsonPath == null) {
             $jsonPath = PIMCORE_PLUGINS_PATH . "/CoreShop/install/fieldcollection-{$name}.json";
         }
         $fieldCollection = new Object\Fieldcollection\Definition();
         $fieldCollection->setKey($name);
         $json = file_get_contents($jsonPath);
         $result = Plugin::getEventManager()->trigger('install.fieldcollection.preCreate', $this, array("fieldcollectionName" => $name, "json" => $json), function ($v) {
             return !preg_match('/[^,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t]/', preg_replace('/"(\\.|[^"\\\\])*"/', '', $v));
         });
         if ($result->stopped()) {
             $resultJson = $result->last();
             if ($resultJson) {
                 $json = $resultJson;
             }
         }
         Object\ClassDefinition\Service::importFieldCollectionFromJson($fieldCollection, $json, true);
     }
     return $fieldCollection;
 }
Пример #2
0
 /**
  * Process import
  *
  * @param AbstractModel $definition
  * @param string $json
  * @return bool
  */
 protected function import(AbstractModel $definition, $json)
 {
     return Service::importFieldCollectionFromJson($definition, $json);
 }
Пример #3
0
 /**
  *  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;
 }
Пример #4
-1
 /**
  * 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]);
 }