/** * * @param $tlID the ID of the Transport Layer * @param $dalID * @param $source_input an XML structure of the given source inputs * @param $givenImportSetName the given import set name (String) * @param $givenInputPol an XML structure with the given input policy * @param $mappingPage The name of the mapping article * @param $givenConflictPol Boolean: overwrite=true, preserve=false * @param $runBot run the bot??? * * @return $result an XML structure */ function smwf_ti_connectTL($tlID, $dalID, $source_input, $givenImportSetName, $givenInputPol, $mappingPage, $givenConflictPol = true, $runBot, $termImportName = null, $updatePolicy = "", $edit = false, $createOnly = false) { global $smwgDIIP, $wgOut; require_once $smwgDIIP . '/specials/TermImport/SMW_WIL.php'; require_once $smwgDIIP . '/specials/TermImport/SMW_XMLParser.php'; $wil = new WIL(); $tlModules = $wil->getTLModules(); //TODO Errorhandling!!! if (!$tlID) { // Error,keine TLID angegeben!!! } $res = $wil->connectTL($tlID, $tlModules); $dalModules = $wil->getDALModules(); //return if no dalID is given if (!$dalID) { $tlModules = str_replace("<?xml version=\"1.0\"?>", "", $tlModules); $dalModules = str_replace("<?xml version=\"1.0\"?>", "", $dalModules); return '<result>' . $tlModules . $dalModules . '</result>'; } $res = $wil->connectDAL($dalID, $dalModules); $source = $wil->getSourceSpecification(); // return if no source is given if ((!$source_input || $source_input == '') && $res) { $tlModules = str_replace("<?xml version=\"1.0\"?>", "", $tlModules); $dalModules = str_replace("<?xml version=\"1.0\"?>", "", $dalModules); $source = str_replace("<?xml version=\"1.0\"?>", "", $source); return '<result>' . $tlModules . $dalModules . $source . '</result>'; } if (isset($source_input)) { $source_xml = new SimpleXMLElement($source_input); $source_xml_alt = new SimpleXMLElement($source); foreach ($source_xml->children() as $second_gen) { $tag = $second_gen->getName(); $value = (string) $second_gen; $result = $source_xml_alt->xpath($tag); //Change the old tag $source_xml_alt->{$tag} = $value; } //get the xml-string $source_result = $source_xml_alt->asXML(); } $importSets = $wil->getImportSets($source_result); $p = new XMLParser($importSets); $result = $p->parse(); if ($result == TRUE && $givenImportSetName && $givenImportSetName != '' && $givenImportSetName != 'ALL') { $p->removeAllParentElements('NAME', $givenImportSetName); } if ($result == TRUE && $givenImportSetName && $givenImportSetName == 'ALL') { $importSets = '<?xml version="1.0"?>' . '<IMPORTSETS XMLNS="http://www.ontoprise.de/smwplus#">' . '</IMPORTSETS>'; } else { $importSets = $p->serialize(); } $properties = $wil->getProperties($source_result, $importSets); if (!$givenInputPol || $givenInputPol == '') { // no input policy defined, create an empty one for getting the term-information $givenInputPol = '<?xml version="1.0"?>' . "\n" . '<InputPolicy xmlns="http://www.ontoprise.de/smwplus#">' . "\n" . '<terms>' . "\n" . ' <regex></regex>' . "\n" . ' <term></term>' . "\n" . '</terms>' . "\n" . '<properties>' . "\n" . ' <property>articleName</property>' . "\n" . '</properties>' . "\n" . '</InputPolicy>' . "\n"; } $terms = $wil->getTermList($source_result, $importSets, $givenInputPol); if ($runBot == 0) { // prepare XML strings for return... $xmlResult = '<result>' . $tlModules . $dalModules . $source_result . $importSets . $properties . $terms . '</result>'; $xmlResult = '<?xml version="1.0"?>' . str_replace('<?xml version="1.0"?>', "", $xmlResult); return $xmlResult; } elseif ($runBot == 1) { //do the Import! $title = Title::newFromText($mappingPage); if (!$title->exists()) { return '<?xml version="1.0"?> <ReturnValue xmlns="http://www.ontoprise.de/smwplus#"> <value>falseMap</value> <message>' . wfMsg('smw_ti_nomappingpage') . '</message> </ReturnValue >'; } $moduleConfig = '<?xml version="1.0"?>' . "\n" . '<ModuleConfiguration xmlns="http://www.ontoprise.de/smwplus#">' . "\n" . ' <TLModules>' . "\n" . ' <Module>' . "\n" . ' <id>' . $tlID . '</id>' . "\n" . ' </Module>' . "\n" . ' </TLModules >' . "\n" . ' <DALModules>' . "\n" . ' <Module>' . "\n" . ' <id>' . $dalID . '</id>' . "\n" . ' </Module>' . "\n" . ' </DALModules >' . "\n" . '</ModuleConfiguration>'; $mappingPolicy = '<?xml version="1.0"?>' . "\n" . '<MappingPolicy xmlns="http://www.ontoprise.de/smwplus#">' . "\n" . ' <page>' . $mappingPage . '</page>' . "\n" . '</MappingPolicy >'; if ($givenConflictPol && $givenConflictPol != '') { $conflictPolicy = '<?xml version="1.0"?>' . "\n" . '<ConflictPolicy xmlns="http://www.ontoprise.de/smwplus#">' . "\n" . ' <overwriteExistingTerms>' . $givenConflictPol . '</overwriteExistingTerms>' . "\n" . '</ConflictPolicy >'; } else { //Error!no conflict policy given... is it possible with <select>?!? } //todo: error handling if ($updatePolicy == 0 || $updatePolicy == "") { $updatePolicy = "<once/>"; } else { $updatePolicy = "<maxAge value=\"" . $updatePolicy . "\"/>"; } $updatePolicy = '<?xml version="1.0"?>' . "\n" . '<UpdatePolicy xmlns="http://www.ontoprise.de/smwplus#">' . "\n" . $updatePolicy . '</UpdatePolicy>'; $articleCreated = smwf_ti_createTIArticle($moduleConfig, $source_result, $mappingPolicy, $conflictPolicy, $givenInputPol, $importSets, $termImportName, $updatePolicy, $edit); if ($articleCreated !== true) { return $articleCreated; } else { if ($createOnly != "false") { return '<?xml version="1.0"?> <ReturnValue xmlns="http://www.ontoprise.de/smwplus#"> <value>articleCreated</value> <message>' . $termImportName . '</message> </ReturnValue >'; } } $terms = $wil->importTerms($moduleConfig, $source_result, $importSets, $givenInputPol, $mappingPolicy, $conflictPolicy, $termImportName); if ($terms == false) { //error while running bot } else { return $terms; } } else { // error, $runBot neither 0 nor 1 } return null; }
function smwf_ti_update($tiArticleName) { global $smwgDIIP; require_once $smwgDIIP . "/specials/TermImport/SMW_WIL.php"; $xmlString = smwf_om_GetWikiText('TermImport:' . $tiArticleName); $start = strpos($xmlString, "<ImportSettings>"); $end = strpos($xmlString, "</ImportSettings>") + 17 - $start; $xmlString = substr($xmlString, $start, $end); $simpleXMLElement = new SimpleXMLElement($xmlString); $moduleConfig = $simpleXMLElement->xpath("//ModuleConfiguration"); $moduleConfig = trim($moduleConfig[0]->asXML()); $dataSource = $simpleXMLElement->xpath("//DataSource"); $dataSource = trim($dataSource[0]->asXML()); $mappingPolicy = $simpleXMLElement->xpath("//MappingPolicy"); $mappingPolicy = trim($mappingPolicy[0]->asXML()); $conflictPolicy = $simpleXMLElement->xpath("//ConflictPolicy"); $conflictPolicy = trim($conflictPolicy[0]->asXML()); $inputPolicy = $simpleXMLElement->xpath("//InputPolicy"); $inputPolicy = trim($inputPolicy[0]->asXML()); $importSets = $simpleXMLElement->xpath("//ImportSets"); $importSets = trim($importSets[0]->asXML()); $wil = new WIL(); $terms = $wil->importTerms($moduleConfig, $dataSource, $importSets, $inputPolicy, $mappingPolicy, $conflictPolicy, $tiArticleName, true); if ($terms != wfMsg('smw_ti_import_successful')) { return $terms; } else { return "success"; } }
/** * Checks if Term Imports need to be updated and triggers them */ private function updateTermImports() { $log = SGAGardeningIssuesAccess::getGardeningIssuesAccess(); global $smwgDIIP; require_once $smwgDIIP . "/specials/TermImport/SMW_WIL.php"; $necessaryTermImports = $this->getNecessaryTermImports(); $this->setNumberOfTasks(1); $this->addSubTask(count($necessaryTermImports)); foreach ($necessaryTermImports as $termImportName => $xmlString) { echo "\nProcessing term import: " . $termImportName . "\n"; $simpleXMLElement = new SimpleXMLElement($xmlString); $moduleConfig = $simpleXMLElement->xpath("//ModuleConfiguration"); $moduleConfig = trim($moduleConfig[0]->asXML()); $dataSource = $simpleXMLElement->xpath("//DataSource"); $dataSource = trim($dataSource[0]->asXML()); $mappingPolicy = $simpleXMLElement->xpath("//MappingPolicy"); $mappingPolicy = trim($mappingPolicy[0]->asXML()); $conflictPolicy = $simpleXMLElement->xpath("//ConflictPolicy"); $conflictPolicy = trim($conflictPolicy[0]->asXML()); $inputPolicy = $simpleXMLElement->xpath("//InputPolicy"); $inputPolicy = trim($inputPolicy[0]->asXML()); $importSets = $simpleXMLElement->xpath("//ImportSets"); $importSets = trim($importSets[0]->asXML()); $wil = new WIL(); $terms = $wil->importTerms($moduleConfig, $dataSource, $importSets, $inputPolicy, $mappingPolicy, $conflictPolicy, $termImportName, false); $title = Title::newFromText("TermImport:" . $termImportName); if ($terms != wfMsg('smw_ti_import_successful')) { $log->addGardeningIssueAboutArticle($this->id, SMW_GARDISSUE_UPDATE_FAILURE, $title); } else { $log->addGardeningIssueAboutArticle($this->id, SMW_GARDISSUE_UPDATE_SUCCESS, $title); } $this->worked(1); } }