/** * Import module objects from given array datas * * @param array $data The module datas to import * @param array $params The import parameters. * array( * module => false|true : the module to create categories (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 */ static function fromArray($data, $params, $cms_language, &$idsRelation, &$infos) { if (!isset($params['module'])) { $infos .= 'Error : missing module codename for objects importation ...' . "\n"; return false; } $module = CMS_modulesCatalog::getByCodename($params['module']); if ($module->hasError()) { $infos .= 'Error : invalid module for objects importation : ' . $params['module'] . "\n"; return false; } $return = true; //first create missing objects to get relation ids foreach ($data as $objectDatas) { if (!isset($objectDatas['uuid']) || !CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid'])) { //create new object if we can if (!isset($params['create']) || $params['create'] == true) { //create object $object = new CMS_poly_object_definition(); //set module $object->setValue('module', $params['module']); //set uuid $object->setUuid($objectDatas['uuid']); //write object to persistence to get relations ids $object->writeToPersistence(); //set id translation if (isset($objectDatas['id']) && $objectDatas['id']) { // && $object->getID() != $objectDatas['id']) { // Fix for bug #3157 : in some cases the imported object will have the same id has the newly created, // we still need the relation table otherwise it will fail to link to the new object $idsRelation['objects'][$objectDatas['id']] = $object->getID(); } //set uuid translation if (isset($objectDatas['uuid']) && $objectDatas['uuid'] && $object->getValue('uuid') != $objectDatas['uuid']) { $idsRelation['objects-uuid'][$objectDatas['uuid']] = $object->getValue('uuid'); } } } elseif (isset($objectDatas['uuid']) && isset($objectDatas['id'])) { //get relation between imported object id and local id $id = CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid']); if (io::isPositiveInteger($id)) { $idsRelation['objects'][$objectDatas['id']] = $id; } } } //then import objects datas foreach ($data as $objectDatas) { $importType = ''; if (isset($objectDatas['uuid']) && ($id = CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid']))) { //object already exist : load it if we can update it if (!isset($params['update']) || $params['update'] == true) { $object = CMS_poly_object_catalog::getObjectDefinition($id); $importType = ' (Update)'; //set id translation $idsRelation['objects'][$objectDatas['id']] = $id; } } else { //check for translated id if (isset($objectDatas['id']) && isset($idsRelation['objects'][$objectDatas['id']])) { //object exists with a translated id $objectDatas['id'] = $idsRelation['objects'][$objectDatas['id']]; //load translated object $object = CMS_poly_object_catalog::getObjectDefinition($objectDatas['id']); $importType = ' (Creation)'; } //check for translated uuid if (isset($objectDatas['uuid']) && isset($idsRelation['objects-uuid'][$objectDatas['uuid']])) { //object exists with a translated uuid $objectDatas['uuid'] = $idsRelation['objects-uuid'][$objectDatas['uuid']]; //load translated object if ($id = CMS_poly_object_catalog::objectExists($params['module'], $objectDatas['uuid'])) { $object = CMS_poly_object_catalog::getObjectDefinition($id); $importType = ' (Creation)'; } } } if (isset($object)) { if ($object->fromArray($objectDatas, $params, $cms_language, $idsRelation, $infos)) { $return &= true; $infos .= 'Object "' . $object->getLabel($cms_language) . '" successfully imported' . $importType . "\n"; } else { $return = false; $infos .= 'Error during import of object ' . $objectDatas['id'] . $importType . "\n"; } } } return $return; }
//Multilanguage $object->setValue("multilanguage", $_POST["multilanguage"]); //IndexURL $object->setValue("indexable", $_POST["indexable"]); if ($_POST["indexable"] && !$_POST["indexURL"]) { $cms_message .= $cms_language->getMessage(MESSAGE_FORM_ERROR_MANDATORY_FIELDS); } $indexURLValue = $polymod->convertDefinitionString($_POST["indexURL"], false); $URLErrors = $object->setValue("indexURL", $indexURLValue); if ($URLErrors !== true) { $cms_message .= "\n" . $cms_language->getMessage(MESSAGE_FORM_ERROR_MALFORMED_FIELD, array($cms_language->getMessage(MESSAGE_PAGE_OBJECT_INDEXATION_LINK_TO, false, MOD_POLYMOD_CODENAME) . ' : ' . $definitionErrors)); } $object->setValue("module", $moduleCodename); if (!$cms_message && $_POST["cms_action"] == "validate") { //save the data $object->writeToPersistence(); header("Location: modules_admin.php?moduleCodename=" . $moduleCodename . "&object=" . $object->getID() . "&cms_message_id=" . MESSAGE_ACTION_OPERATION_DONE . "&" . session_name() . "=" . session_id()); exit; } break; } $dialog = new CMS_dialog(); $content = ''; $dialog->setTitle($cms_language->getMessage(MESSAGE_PAGE_TITLE_APPLICATIONS) . " :: " . $cms_language->getMessage(MESSAGE_PAGE_TITLE), 'picto_modules.gif'); $dialog->setBacklink("modules_admin.php?moduleCodename=" . $moduleCodename . "&object=" . $object->getID()); if ($cms_message) { $dialog->setActionMessage($cms_message); } if (method_exists($dialog, 'addStopTab')) { $dialog->addStopTab(); $stopTab = ' onkeydown="return catchTab(this,event)"';