/** * Import object from given array datas * * @param array $data The object datas to import * @param array $params The import parameters. * array( * module => false|true : the module to create object (required) * create => false|true : create missing objects (default : true) * update => false|true : update existing objects (default : true) * files => false|true : use files from PATH_TMP_FS (default : true) * ) * @param CMS_language $cms_language The CMS_langage to use * @param array $idsRelation : Reference : The relations between import datas ids and real imported ids * @param string $infos : Reference : The import infos returned * @return boolean : true on success, false on failure * @access public */ function fromArray($data, $params, $cms_language, &$idsRelation, &$infos) { if (!isset($params['module'])) { $infos .= 'Error : missing module codename for object importation ...' . "\n"; return false; } $module = CMS_modulesCatalog::getByCodename($params['module']); if ($module->hasError()) { $infos .= 'Error : invalid module for object importation : ' . $params['module'] . "\n"; return false; } if (!$this->getID() && CMS_poly_object_catalog::objectUuidExists($data['uuid'])) { //check imported uuid. If objects does not have an Id, the uuid must be unique or must be regenerated $uuid = io::uuid(); //store old uuid relation $idsRelation['objects-uuid'][$data['uuid']] = $uuid; $data['uuid'] = $uuid; } //set object uuid if not exists if (!$this->_objectValues["uuid"]) { $this->_objectValues["uuid"] = $data['uuid']; } if (isset($data['labels'])) { $label = new CMS_object_i18nm($this->getValue("labelID")); $label->setValues($data['labels']); $label->writeToPersistence(); $this->setValue("labelID", $label->getID()); } if (isset($data['descriptions'])) { $description = new CMS_object_i18nm($this->getValue("descriptionID")); $description->setValues($data['descriptions']); $description->writeToPersistence(); $this->setValue("descriptionID", $description->getID()); } if (isset($data['params']['resourceUsage'])) { $this->setValue("resourceUsage", $data['params']['resourceUsage']); } if (isset($data['params']['admineditable'])) { $this->setValue("admineditable", $data['params']['admineditable']); } if (isset($data['params']['indexable'])) { $this->setValue("indexable", $data['params']['indexable']); } if (isset($data['params']['multilanguage'])) { $this->setValue("multilanguage", $data['params']['multilanguage']); } if (isset($data['params']['composedLabel'])) { $this->setValue("composedLabel", $module->convertDefinitionString($data['params']['composedLabel'], false)); } if (isset($data['params']['previewURL'])) { $this->setValue("previewURL", $module->convertDefinitionString($data['params']['previewURL'], false)); } if (isset($data['params']['indexURL'])) { $this->setValue("indexURL", $module->convertDefinitionString($data['params']['indexURL'], false)); } if (isset($data['params']['resultsDefinition'])) { $this->setValue("resultsDefinition", $module->convertDefinitionString($data['params']['resultsDefinition'], false)); } //write object if (!$this->writeToPersistence()) { $infos .= 'Error : can not write object ...' . "\n"; return false; } //if current object id has changed from imported id, set relation if (isset($data['id']) && $data['id'] && $this->getID() != $data['id']) { $idsRelation['objects'][$data['id']] = $this->getID(); } //set this object into definition to convert array so it can be converted again at end of import process $idsRelation['definitionToConvert'][] = $this; $return = true; //object fields if (isset($data['fields'])) { foreach ($data['fields'] as $fieldDatas) { $importType = ''; if (isset($fieldDatas['type'])) { if (isset($fieldDatas['uuid']) && ($id = CMS_poly_object_catalog::fieldExists($params['module'], $fieldDatas['uuid']))) { //field already exist : load it if we can update it if (!isset($params['update']) || $params['update'] == true) { $field = new CMS_poly_object_field($id); $importType = ' (Update)'; } } else { //create new field if we can if (!isset($params['create']) || $params['create'] == true) { $field = new CMS_poly_object_field(); $importType = ' (Creation)'; } } if (isset($field)) { if ($field->fromArray($fieldDatas, $params, $cms_language, $idsRelation, $infos)) { $return &= true; $infos .= 'Field "' . $field->getLabel($cms_language) . '" successfully imported' . $importType . "\n"; } else { $return = false; $infos .= 'Error during import of field ...' . $importType . "\n"; } } } else { $return = false; $infos .= 'Error during import of field : missing type' . "\n"; } } } //object rss feeds if (isset($data['rss'])) { foreach ($data['rss'] as $rssDatas) { $importType = ''; if (isset($rssDatas['uuid']) && ($id = CMS_poly_object_catalog::rssExists($params['module'], $rssDatas['uuid']))) { //rss already exist : load it if we can update it if (!isset($params['update']) || $params['update'] == true) { $rss = new CMS_poly_rss_definitions($id); $importType = ' (Update)'; } } else { //create new rss if we can if (!isset($params['create']) || $params['create'] == true) { $rss = new CMS_poly_rss_definitions(); $importType = ' (Creation)'; } } if (isset($rss)) { if ($rss->fromArray($rssDatas, $params, $cms_language, $idsRelation, $infos)) { $return &= true; $infos .= 'RSS feed "' . $rss->getLabel($cms_language) . '" successfully imported' . $importType . "\n"; } else { $return = false; $infos .= 'Error during import of rss feed ...' . $importType . "\n"; } } } } //plugins wysiwyg if (isset($data['plugins'])) { foreach ($data['plugins'] as $pluginDatas) { $importType = ''; if (isset($pluginDatas['uuid']) && ($id = CMS_poly_object_catalog::pluginExists($params['module'], $pluginDatas['uuid']))) { //plugin already exist : load it if we can update it if (!isset($params['update']) || $params['update'] == true) { $plugin = new CMS_poly_plugin_definitions($id); $importType = ' (Update)'; } } else { //create new plugin if we can if (!isset($params['create']) || $params['create'] == true) { $plugin = new CMS_poly_plugin_definitions(); $importType = ' (Creation)'; } } if (isset($plugin)) { if ($plugin->fromArray($pluginDatas, $params, $cms_language, $idsRelation, $infos)) { $return &= true; $infos .= 'Plugin Wysiwyg "' . $plugin->getLabel($cms_language) . '" successfully imported' . $importType . "\n"; } else { $return = false; $infos .= 'Error during import of plugin wysiwyg ...' . $importType . "\n"; } } } } return $return; }