[Mapbender-commits] r10315 - trunk/mapbender/tools
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Nov 5 04:42:09 PST 2019
Author: armin11
Date: 2019-11-05 04:42:08 -0800 (Tue, 05 Nov 2019)
New Revision: 10315
Modified:
trunk/mapbender/tools/mod_qualifyPersistedMetadataXml.php
Log:
Fix metadata qualification - alter dateStamp to one day after old dateStamp - otherwise they would not be harvested, if no other things changed!
Modified: trunk/mapbender/tools/mod_qualifyPersistedMetadataXml.php
===================================================================
--- trunk/mapbender/tools/mod_qualifyPersistedMetadataXml.php 2019-11-04 08:34:31 UTC (rev 10314)
+++ trunk/mapbender/tools/mod_qualifyPersistedMetadataXml.php 2019-11-05 12:42:08 UTC (rev 10315)
@@ -13,12 +13,10 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
require_once(dirname(__FILE__) . "/../core/globalSettings.php");
require_once(dirname(__FILE__) . "/../http/classes/class_iso19139.php");
require_once(dirname(__FILE__) . "/../http/classes/class_Uuid.php");
-
$startTimeForAll = microtime(true);
$metadataClass = new Iso19139();
$injectRegistryUuid = false;
@@ -49,7 +47,7 @@
$metadataXml = fread($h, filesize($metadataDir."/".$file));
$metadataObject = $metadataClass->createMapbenderMetadataFromXML($metadataXml);
logMessages("fileIdentifier: ".$metadataObject->fileIdentifier);
- logMessages("type: ".$metadataObject->hierarchyLevel);
+ //logMessages("type: ".$metadataObject->hierarchyLevel);
if (in_array('inspireidentifiziert', $metadataObject->keywords) && !in_array('Regional', $metadataObject->keywords) && $metadataObject->hierarchyLevel == 'dataset') {
//echo $metadataObject->title."<br>";
//echo $metadataDir."/".$file." has keyword inspireidentifiziert!<br>";
@@ -62,7 +60,7 @@
$keywordsArray[$newKeywordsIndex]->thesaurusPubDate = "2019-05-22";
$e = new mb_exception("test3");*/
}
-logMessages("Actual keywords: ".json_encode($metadataObject->keywords));
+ //logMessages("Actual keywords: ".json_encode($metadataObject->keywords));
if ($injectRegistryUuid && !in_array($uuid, $metadataObject->keywords)) { //add mapbender registry keyword
$newKeywordsIndex++;
$keywordsArray[$newKeywordsIndex]->keyword = $uuid;
@@ -101,16 +99,9 @@
logMessages("time to alter all xml: ".$timeToBuildAll);
}
-//function to inject keywords into metadata xml
-//keywords to add -
-//keywordsArray[0]->keyword = "test";
-//keywordsArray[0]->thesaurusTitle = "testThesaurus";
-//keywordsArray[0]->thesaurusPubDate = "2019-05-22";
-
function addKeywords($metadataXml, $keywordsArray) {
- //parse XML part
- //echo $metadataXml;
- //die();
+ //logMessages("function addKeywords");
+ //parse XML part
//do parsing with dom, cause we want to alter the xml which have been parsed afterwards
$metadataDomObject = new DOMDocument();
libxml_use_internal_errors(true);
@@ -118,13 +109,13 @@
$metadataDomObject->loadXML($metadataXml);
if ($metadataDomObject === false) {
foreach(libxml_get_errors() as $error) {
- logMessages("php/mod_qualifyPersistedMetadataXml.php:".$error->message);
+ logMessages("php/mod_qualifyPersistedMetadataXml.php: ".$error->message);
}
throw new Exception("php/mod_qualifyPersistedMetadataXml.php:".'Cannot parse metadata with dom!');
}
}
catch (Exception $e) {
- logMessages("php/mod_qualifyPersistedMetadataXml.php:".$e->getMessage());
+ logMessages("php/mod_qualifyPersistedMetadataXml.php: ".$e->getMessage());
}
if ($metadataDomObject !== false) {
//importing namespaces
@@ -139,18 +130,13 @@
$xpath->registerNamespace("gts", "http://www.isotc211.org/2005/gts");
//$xpath->registerNamespace("srv", "http://www.isotc211.org/2005/srv");
$xpath->registerNamespace("xlink", "http://www.w3.org/1999/xlink");
-
//inspire specific keywords
//https://webgate.ec.europa.eu/fpfis/wikis/display/InspireMIG/Spatial+scope+code+list
-
//problem: gmx namespace does not exists !!!!! - have to be declared before!!!!!!
-
/*$keywordXMLSnippet = '<?xml version="1.0" encoding="UTF-8"?><gmd:descriptiveKeywords xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink"><gmd:MD_Keywords><gmd:keyword><gmx:Anchor xlink:href="http://inspire.ec.europa.eu/metadata-codelist/SpatialScope/national">Regional</gmx:Anchor></gmd:keyword><gmd:thesaurusName><gmd:CI_Citation><gmd:title><gmx:Anchor xlink:href="http://inspire.ec.europa.eu/metadata-codelist/SpatialScope">Spatial scope</gmx:Anchor></gmd:title><gmd:date><gmd:CI_Date><gmd:date><gco:Date>2019-05-22</gco:Date></gmd:date><gmd:dateType><gmd:CI_DateTypeCode codeList="http://standards.iso.org/iso/19139/resources/gmxCodelists.xml#CI_DateTypeCode" codeListValue="publication">publication</gmd:CI_DateTypeCode></gmd:dateType></gmd:CI_Date></gmd:date></gmd:CI_Citation></gmd:thesaurusName></gmd:MD_Keywords
></gmd:descriptiveKeywords>';*/
-
$descriptiveKeywordsNodeList = $xpath->query('//gmd:MD_Metadata/gmd:identificationInfo//gmd:descriptiveKeywords');
//data and service identification!
- $arrayDescriptiveKeywordsNodeList = (array)$descriptiveKeywordsNodeList;
-
+ //$arrayDescriptiveKeywordsNodeList = (array)$descriptiveKeywordsNodeList;
foreach ($keywordsArray as $keyword) {
$keywordXMLSnippet ='<?xml version="1.0" encoding="UTF-8"?><gmd:descriptiveKeywords xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink">
<gmd:MD_Keywords>
@@ -177,11 +163,9 @@
</gmd:MD_Keywords>
</gmd:descriptiveKeywords>';
//count old resourceConstraints elements
-
//TODO - if this is empty - create a new entry
//if (!empty($arrayResourceConstraintsNodeList)) {
-logMessages("Count of existing descriptiveKeywordsNodeList: ".count($descriptiveKeywordsNodeList));
-//$e = new mb_exception("count array descriptiveKeywordsNodeList: ".count($arrayDescriptiveKeywordsNodeList));
+//logMessages("Count of existing descriptiveKeywordsNodeList: ".count($descriptiveKeywordsNodeList));
if (count($descriptiveKeywordsNodeList) > 0) {
//$e = new mb_exception("list is not empty!");
//load xml from constraint generator
@@ -189,8 +173,6 @@
$keywordDomObject->loadXML($keywordXMLSnippet);
$xpathKeyword = new DOMXpath($keywordDomObject);
$keywordNodeList = $xpathKeyword->query('/gmd:descriptiveKeywords');
-//$e = new mb_exception("new keyword length: ".$keywordNodeList->length);
-//$e = new mb_exception("old keyword length: ".$descriptiveKeywordsNodeList->length);
//insert new keyword before first old constraints node
//for ($i = ($keywordNodeList->length)-1; $i >= 0; $i--) {
$descriptiveKeywordsNodeList->item(0)->parentNode->insertBefore($metadataDomObject->importNode($keywordNodeList->item(0), true), $descriptiveKeywordsNodeList->item(0));
@@ -200,20 +182,28 @@
$temp = $resourceConstraintsNodeList->item($i); //avoid calling a function twice
$temp->parentNode->removeChild($temp);
}*/
- }
+ }//end for descriptiveKeywordsNodeList
+
} //end - foreach keyword in array
- //test http://localhost/mb_trunk/php/mod_dataISOMetadata.php?outputFormat=iso19139&id=0da11651-aa61-d75a-446c-ea4ea073bc48
- }
+ //if keyword was injected - the metadata dateStamp has to be altered - fictive 1 day will be added to mark the difference!
+ $dateNodeList = $xpath->query('//gmd:MD_Metadata/gmd:dateStamp/gco:Date');
+ $dateStamp = $dateNodeList->item(0)->nodeValue;
+ $date = new DateTime($dateStamp);
+ //add one day
+ $date->add(new DateInterval('P1D'));
+ $dateNew = date_format($date, 'Y-m-d');
+ $fragment = $metadataDomObject->createElementNS('http://www.isotc211.org/2005/gco', 'gco:Date', $dateNew);
+ $dateNodeList->item(0)->parentNode->replaceChild($fragment, $dateNodeList->item(0));
+ } //end for parsing xml successfully
return $metadataDomObject->saveXML();
}
+
function logMessages($message) {
if (php_sapi_name() === 'cli' OR defined('STDIN')) {
- echo __FILE__.$message."\n";
+ echo __FILE__.": ".$message."\n";
} else {
- $e = new mb_exception(__FILE__.$message);
+ $e = new mb_exception(__FILE__.": ".$message);
}
}
-
-
?>
More information about the Mapbender_commits
mailing list