[Mapbender-commits] r9543 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu Jul 14 08:01:01 PDT 2016
Author: armin11
Date: 2016-07-14 08:01:01 -0700 (Thu, 14 Jul 2016)
New Revision: 9543
Modified:
trunk/mapbender/http/classes/class_wms.php
Log:
New possibility to sync mapbender registry with external csw via csw-t - done for wms layer resources
Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php 2016-07-13 15:13:47 UTC (rev 9542)
+++ trunk/mapbender/http/classes/class_wms.php 2016-07-14 15:01:01 UTC (rev 9543)
@@ -14,6 +14,7 @@
require_once dirname(__FILE__) . "/class_georss_factory.php";
require_once dirname(__FILE__) . "/class_mb_exception.php";
require_once dirname(__FILE__) . "/class_iso19139.php";
+require_once(dirname(__FILE__) . "/class_cswClient.php");
require_once dirname(__FILE__) . "/../classes/class_universal_wms_factory.php";
class wms {
var $lastURL;
@@ -1905,7 +1906,38 @@
$e = new mb_exception("class_wms.php: Twitter API give back error code: ".$result);
}
}
-
+ //Propagate information for each new layer to csw if configured
+ if (defined("SYNC_CHANGES_TO_CSW") && SYNC_CHANGES_TO_CSW == true && defined("SYNC_CATALOGUE_ID") && is_int(SYNC_CATALOGUE_ID)) {
+ if (defined("MAPBENDER_PATH") && MAPBENDER_PATH !== "") {
+ //layer service metadata generator
+ $servMdPath = MAPBENDER_PATH."/php/mod_layerISOMetadata.php?SERVICE=WMS&outputFormat=iso19139&Id=";
+ } else {
+ $servMdPath = "http://".$_SERVER['HTTP_HOST']."/mapbender"."/php/mod_layerISOMetadata.php?SERVICE=WMS&outputFormat=iso19139&Id=";
+ }
+ $cswClient = new cswClient();
+ $cswClient->cswId = SYNC_CATALOGUE_ID;
+ $isoMetadata = new Iso19139();
+ //select all layer which are searchable
+ $sql = "SELECT layer_id, uuid FROM layer WHERE fkey_wms_id = $1 and layer_searchable = 1";
+ $v = array($myWMS);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $insertedLayerArray = array();
+ while($row = db_fetch_array($res)){
+ $insertedLayerArray[] = array(
+ "id" => $row['layer_id'],
+ "uuid" => $row['uuid']
+ );
+ }
+ //update existing layer
+ foreach ($insertedLayerArray as $insertedLayer) {
+ //$e = new mb_exception("classes/class_wms.php: try to push metadata for layer ".$insertedLayer['id']." into csw");
+ $metadata = $isoMetadata->createFromUrl($servMdPath.$insertedLayer['id']);
+ $result = $cswClient->pushRecord($metadata);
+ //$e = new mb_exception("classes/class_wms.php: result of pushing: ".$result);
+ }
+ }
+
//Changes JW
$this->wms_id = $myWMS;
}
@@ -2002,6 +2034,7 @@
$e = new mb_exception("class_wms.php: Twitter API give back error code: ".$result);
}
}
+
}
}
function updateLayer($i,$myWMS,$updateMetadataOnly=false){
@@ -2870,7 +2903,7 @@
$v = array($myWMS);
$t = array('i');
$c = 2;
- $sql = "SELECT layer_id, layer_name, layer_title, layer_abstract, inspire_download FROM layer WHERE fkey_wms_id = $1 AND layer_pos > 0 AND NOT layer_name IN(";
+ $sql = "SELECT layer_id, layer_name, layer_title, layer_abstract, inspire_download, uuid FROM layer WHERE fkey_wms_id = $1 AND layer_pos > 0 AND NOT layer_name IN(";
for($i=1; $i<count($this->objLayer); $i++){
if($i>1){$sql .= ',';}
$sql .= "$".$c;
@@ -2885,7 +2918,9 @@
"id" => $row["layer_id"],
"name" => $row["layer_name"],
"title" => $row["layer_title"],
- "abstract" => $row["layer_abstract"]
+ "abstract" => $row["layer_abstract"],
+ "uuid" => $row["uuid"],
+ "layer_searchable" => $row["layer_searchable"]
//"inspire_download" => $row["inspire_download"]
);
@@ -2935,7 +2970,7 @@
################ end section for all child layers
# update or insert?
- $sql = "SELECT layer_name FROM layer WHERE fkey_wms_id = $1";
+ $sql = "SELECT layer_id, layer_name, uuid, layer_searchable FROM layer WHERE fkey_wms_id = $1";
$v = array($myWMS);
$t = array('i');
$res = db_prep_query($sql,$v,$t);
@@ -2943,7 +2978,6 @@
while($row = db_fetch_array($res)){
array_push($exLayer,$row["layer_name"]);
}
-
$sql = "SELECT fkey_gui_id FROM gui_wms WHERE fkey_wms_id = $1";
$v = array($myWMS);
$t = array('i');
@@ -2972,6 +3006,20 @@
}
}
}
+ //select new layer after update and insert
+ $sql = "SELECT layer_id, layer_name, uuid, layer_searchable FROM layer WHERE fkey_wms_id = $1";
+ $v = array($myWMS);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ $updatedInsertedLayerArray = array();
+ while($row = db_fetch_array($res)){
+ $updatedInsertedLayerArray[] = array(
+ "id" => $row['layer_id'],
+ "uuid" => $row['uuid'],
+ "layer_searchable" => $row['layer_searchable']
+ );
+ //$e = new mb_exception("insert update layer: ".$row['uuid']." - searchable: ". $row['layer_searchable']);
+ }
db_commit();
//
@@ -3040,8 +3088,45 @@
$e = new mb_exception("class_wms.php: Twitter API give back error code: ".$result);
}
}
-
}
+ //sync to metadatacatalogue (service metadata for each layer by uuid) if configured - use uuid
+ //TODO need absolute url to srv metadata generator! - possible if invoked via shell (scheduler)?
+ //
+ if (defined("SYNC_CHANGES_TO_CSW") && SYNC_CHANGES_TO_CSW == true && defined("SYNC_CATALOGUE_ID") && is_int(SYNC_CATALOGUE_ID)) {
+ if (defined("MAPBENDER_PATH") && MAPBENDER_PATH !== "") {
+ //layer service metadata generator
+ $servMdPath = MAPBENDER_PATH."/php/mod_layerISOMetadata.php?SERVICE=WMS&outputFormat=iso19139&Id=";
+ } else {
+ $servMdPath = "http://".$_SERVER['HTTP_HOST']."/mapbender"."/php/mod_layerISOMetadata.php?SERVICE=WMS&outputFormat=iso19139&Id=";
+ }
+ $cswClient = new cswClient();
+ $cswClient->cswId = SYNC_CATALOGUE_ID;
+ //delete old orphaned layer
+ foreach ($oldLayerNameArray as $oldLayer) {
+ if ($oldLayer['layer_searchable'] == "1") {
+ //$e = new mb_exception("classes/class_wms.php: try to delete: ".$oldLayer['uuid']);
+ $result = $cswClient->deleteRecord($oldLayer['uuid']);
+ //$e = new mb_exception("classes/class_wms.php: delete metadata in csw: ".$result);
+ }
+ }
+ $isoMetadata = new Iso19139();
+ //update existing layer
+ foreach ($updatedInsertedLayerArray as $updatedInsertedLayer) {
+ //$e = new mb_exception("classes/class_wms.php: layer_searchable: ".gettype($updatedInsertedLayer['layer_searchable'])." - value: ".$updatedInsertedLayer['layer_searchable']);
+ if ($updatedInsertedLayer['layer_searchable'] !== "1") {
+ //$e = new mb_exception("classes/class_wms.php: try to delete: ".$updatedInsertedLayer['uuid']);
+ $result = $cswClient->deleteRecord($updatedInsertedLayer['uuid']);
+ //$e = new mb_exception("classes/class_wms.php: delete metadata in csw: ".$result);
+ } else {
+ //$e = new mb_exception("classes/class_wms.php: try to insert or update: ".$updatedInsertedLayer['uuid']);
+ $metadata = $isoMetadata->createFromUrl($servMdPath.$updatedInsertedLayer['id']);
+ //$e = new mb_exception("classes/class_wms.php: metadata url: ".$servMdPath.$updatedInsertedLayer['id']);
+ $result = $cswClient->pushRecord($metadata);
+ //$e = new mb_exception("classes/class_wms.php: insert or update metadata in csw: ".$result);
+ }
+ }
+ }
+ //
if ($authType != '') { //some authentication is needed!
$admin = new administration();
echo "WMS ID: ".$myWMS;
More information about the Mapbender_commits
mailing list