[Mapbender-commits] r8612 - in trunk/mapbender/http: classes php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Thu May 2 02:09:31 PDT 2013
Author: armin11
Date: 2013-05-02 02:09:30 -0700 (Thu, 02 May 2013)
New Revision: 8612
Modified:
trunk/mapbender/http/classes/class_wfs.php
trunk/mapbender/http/classes/class_wfsToDb.php
trunk/mapbender/http/php/mod_dataISOMetadata.php
trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php
trunk/mapbender/http/php/mod_inspireDownloadFeed.php
trunk/mapbender/http/php/mod_wfs_server.php
Log:
Possibility to define overwrite for wfs metadata. Now the categories and keywords may not be overwritten if wished so. Some bugfixes for iso19139 metadata.
Modified: trunk/mapbender/http/classes/class_wfs.php
===================================================================
--- trunk/mapbender/http/classes/class_wfs.php 2013-04-30 07:07:06 UTC (rev 8611)
+++ trunk/mapbender/http/classes/class_wfs.php 2013-05-02 09:09:30 UTC (rev 8612)
@@ -34,6 +34,7 @@
var $describeFeatureTypeNamespace;
var $getFeature;
var $transaction;
+ var $overwrite = true;
var $featureTypeArray = array();
/**
Modified: trunk/mapbender/http/classes/class_wfsToDb.php
===================================================================
--- trunk/mapbender/http/classes/class_wfsToDb.php 2013-04-30 07:07:06 UTC (rev 8611)
+++ trunk/mapbender/http/classes/class_wfsToDb.php 2013-05-02 09:09:30 UTC (rev 8612)
@@ -26,7 +26,8 @@
//require_once dirname(__FILE__) . "//class_Uuid.php";
class WfsToDb {
-
+ //check if metadata should be overwritten completly by caps or not. Default to overwrite all (keywords, categories, ...)
+ var $overwrite = true;
/**
* Inserts a new or updates an existing WFS. Replaces the old wfs2db function.
*
@@ -193,18 +194,17 @@
db_rollback();
return false;
}
-
- # delete and refill wfs_termsofuse
- $sql = "DELETE FROM wfs_termsofuse WHERE fkey_wfs_id = $1 ";
- $v = array($aWfs->id);
- $t = array('i');
- $res = db_prep_query($sql,$v,$t);
- if(!$res){
- db_rollback();
+ if ($updateMetadataOnly) {
+ # delete and refill wfs_termsofuse
+ $sql = "DELETE FROM wfs_termsofuse WHERE fkey_wfs_id = $1 ";
+ $v = array($aWfs->id);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ db_rollback();
+ }
+ WfsToDb::insertTermsOfUse($aWfs);
}
-
- WfsToDb::insertTermsOfUse($aWfs);
-
# update TABLE wfs_featuretype
$oldFeatureTypeNameArray = array();
$v = array($aWfs->id);
@@ -241,7 +241,7 @@
if (WfsToDb::featureTypeExists($currentFeatureType)) {
// update existing WFS feature types
$e = new mb_notice("class_wfsToDb.php: class_wfsToDb.php: FT exists");
- if (!WfsToDb::updateFeatureType($currentFeatureType,$updateMetadataOnly)) {
+ if (!WfsToDb::updateFeatureType($currentFeatureType,$updateMetadataOnly,$aWfs->overwrite)) {
db_rollback();
return false;
}
@@ -642,7 +642,7 @@
* @return Boolean
* @param $aWfsFeatureType WfsFeatureType
*/
- private static function updateFeatureType ($aWfsFeatureType, $updateMetadataOnly=false) {
+ private static function updateFeatureType ($aWfsFeatureType, $updateMetadataOnly=false, $overwrite) {
$aWfsFeatureType->id = WfsToDb::getFeatureTypeId($aWfsFeatureType);
$sql = "SELECT featuretype_id, featuretype_searchable, inspire_download FROM wfs_featuretype WHERE fkey_wfs_id = $1 AND featuretype_name = $2";
@@ -766,36 +766,37 @@
}
// update categories for feature type
- $types = array("md_topic", "inspire", "custom");
- foreach ($types as $cat) {
- $sql = "DELETE FROM wfs_featuretype_{$cat}_category WHERE fkey_featuretype_id = $1";
- $v = array($aWfsFeatureType->id);
- $t = array('i');
- $res = db_prep_query($sql,$v,$t);
- if(!$res){
- $e = new mb_exception("Error while deleting old categories for WFS feature type in the database.");
- return false;
- }
+ if ($overwrite) {
+ $types = array("md_topic", "inspire", "custom");
+ foreach ($types as $cat) {
+ $sql = "DELETE FROM wfs_featuretype_{$cat}_category WHERE fkey_featuretype_id = $1";
+ $v = array($aWfsFeatureType->id);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ $e = new mb_exception("Error while deleting old categories for WFS feature type in the database.");
+ return false;
+ }
- $attr = "featuretype_{$cat}_category_id";
- $k = $aWfsFeatureType->$attr;
+ $attr = "featuretype_{$cat}_category_id";
+ $k = $aWfsFeatureType->$attr;
- if($aWfsFeatureType->$attr && count($k) > 0) {
- for ($j = 0; $j < count($k); $j++) {
- if ($k[$j] != "") {
- $sql = "INSERT INTO wfs_featuretype_{$cat}_category (fkey_featuretype_id, fkey_{$cat}_category_id) VALUES ($1, $2)";
- $v = array($aWfsFeatureType->id, $k[$j]);
- $t = array('i', 'i');
- $res = db_prep_query($sql,$v,$t);
- if(!$res){
- $e = new mb_exception("Error while inserting WFS feature type categories into the database.");
- return false;
+ if($aWfsFeatureType->$attr && count($k) > 0) {
+ for ($j = 0; $j < count($k); $j++) {
+ if ($k[$j] != "") {
+ $sql = "INSERT INTO wfs_featuretype_{$cat}_category (fkey_featuretype_id, fkey_{$cat}_category_id) VALUES ($1, $2)";
+ $v = array($aWfsFeatureType->id, $k[$j]);
+ $t = array('i', 'i');
+ $res = db_prep_query($sql,$v,$t);
+ if(!$res){
+ $e = new mb_exception("Error while inserting WFS feature type categories into the database.");
+ return false;
+ }
}
}
- }
- }
+ }
+ }
}
-
//update CRS and MetadataURLs only if update is not started via Metadata Editor
if (!$updateMetadataOnly) {
//update CRS
@@ -829,63 +830,65 @@
}
}
}
- // update keywords
- $sql = "DELETE FROM wfs_featuretype_keyword WHERE fkey_featuretype_id = $1";
- $v = array($aWfsFeatureType->id);
- $t = array('i');
- $res = db_prep_query($sql,$v,$t);
+ if ($overwrite) {
+ // update keywords
+ $sql = "DELETE FROM wfs_featuretype_keyword WHERE fkey_featuretype_id = $1";
+ $v = array($aWfsFeatureType->id);
+ $t = array('i');
+ $res = db_prep_query($sql,$v,$t);
- $k = $aWfsFeatureType->featuretype_keyword;
-// var_dump($k);
- for($j=0; $j<count($k); $j++){
- $keyword_id = "";
+ $k = $aWfsFeatureType->featuretype_keyword;
+
+ for($j=0; $j<count($k); $j++){
+ $keyword_id = "";
- while ($keyword_id == "") {
- $sql = "SELECT keyword_id FROM keyword WHERE UPPER(keyword) = UPPER($1)";
- $v = array($k[$j]);
- $t = array('s');
- $res = db_prep_query($sql,$v,$t);
- $row = db_fetch_array($res);
- //print_r($row);
- if ($row) {
- $keyword_id = $row["keyword_id"];
- $e = new mb_notice("class_wfsToDb.php: Keyword ".$k[$j]." already exists in table keyword in DB.");
- }
- else {
- $sql_insertKeyword = "INSERT INTO keyword (keyword)";
- $sql_insertKeyword .= "VALUES ($1)";
- $v1 = array($k[$j]);
- $t1 = array('s');
- $e = new mb_notice("class_wfsToDb.php: Inserting keyword ".$k[$j]." into table keyword in DB.");
- $res_insertKeyword = db_prep_query($sql_insertKeyword,$v1,$t1);
- if(!$res_insertKeyword){
- $e = new mb_exception("Error while inserting keywords into the database.");
- return false;
+ while ($keyword_id == "") {
+ $sql = "SELECT keyword_id FROM keyword WHERE UPPER(keyword) = UPPER($1)";
+ $v = array($k[$j]);
+ $t = array('s');
+ $res = db_prep_query($sql,$v,$t);
+ $row = db_fetch_array($res);
+ //print_r($row);
+ if ($row) {
+ $keyword_id = $row["keyword_id"];
+ $e = new mb_notice("class_wfsToDb.php: Keyword ".$k[$j]." already exists in table keyword in DB.");
}
+ else {
+ $sql_insertKeyword = "INSERT INTO keyword (keyword)";
+ $sql_insertKeyword .= "VALUES ($1)";
+ $v1 = array($k[$j]);
+ $t1 = array('s');
+ $e = new mb_notice("class_wfsToDb.php: Inserting keyword ".$k[$j]." into table keyword in DB.");
+ $res_insertKeyword = db_prep_query($sql_insertKeyword,$v1,$t1);
+ if(!$res_insertKeyword){
+ $e = new mb_exception("Error while inserting keywords into the database.");
+ return false;
+ }
+ }
}
- }
- // check if featuretype/keyword combination already exists
- $sql_fiKeywordExists = "SELECT * FROM wfs_featuretype_keyword WHERE fkey_featuretype_id = $1 AND fkey_keyword_id = $2";
- $v = array($aWfsFeatureType->id, $keyword_id);
- $t = array('i', 'i');
- $res_fiKeywordExists = db_prep_query($sql_fiKeywordExists, $v, $t);
- $row = db_fetch_array($res_fiKeywordExists);
- //print_r($row);
- if (!$row) {
- $sql1 = "INSERT INTO wfs_featuretype_keyword (fkey_keyword_id,fkey_featuretype_id)";
- $sql1 .= "VALUES ($1,$2)";
- $e = new mb_notice("class_wfsToDb.php: Inserting keyword id ".$keyword_id." for featuretype id ".$aWfsFeatureType->id." into DB.");
- $v1 = array($keyword_id,$aWfsFeatureType->id);
- $t1 = array('i','i');
- $res1 = db_prep_query($sql1,$v1,$t1);
- if(!$res1){
- $e = new mb_exception("Error while inserting wfs_featuretype_keywords into the database.");
- return false;
+ // check if featuretype/keyword combination already exists
+ $sql_fiKeywordExists = "SELECT * FROM wfs_featuretype_keyword WHERE fkey_featuretype_id = $1 AND fkey_keyword_id = $2";
+ $v = array($aWfsFeatureType->id, $keyword_id);
+ $t = array('i', 'i');
+ $res_fiKeywordExists = db_prep_query($sql_fiKeywordExists, $v, $t);
+ $row = db_fetch_array($res_fiKeywordExists);
+ //print_r($row);
+ if (!$row) {
+ $sql1 = "INSERT INTO wfs_featuretype_keyword (fkey_keyword_id,fkey_featuretype_id)";
+ $sql1 .= "VALUES ($1,$2)";
+ $e = new mb_notice("class_wfsToDb.php: Inserting keyword id ".$keyword_id." for featuretype id ".$aWfsFeatureType->id." into DB.");
+ $v1 = array($keyword_id,$aWfsFeatureType->id);
+ $t1 = array('i','i');
+ $res1 = db_prep_query($sql1,$v1,$t1);
+ if(!$res1){
+ $e = new mb_exception("Error while inserting wfs_featuretype_keywords into the database.");
+ return false;
+ }
}
}
}
-
+ //end of update keywords
return true;
}
Modified: trunk/mapbender/http/php/mod_dataISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_dataISOMetadata.php 2013-04-30 07:07:06 UTC (rev 8611)
+++ trunk/mapbender/http/php/mod_dataISOMetadata.php 2013-05-02 09:09:30 UTC (rev 8612)
@@ -896,14 +896,16 @@
$res = db_prep_query($sql,$v,$t);
$descriptiveKeywords=$iso19139->createElement("gmd:descriptiveKeywords");
$MD_Keywords=$iso19139->createElement("gmd:MD_Keywords");
- //push in keywords without thesaurus
while ($row = db_fetch_array($res)) {
- $keyword=$iso19139->createElement("gmd:keyword");
- $keyword_cs=$iso19139->createElement("gco:CharacterString");
- $keywordText = $iso19139->createTextNode($row['keyword']);
- $keyword_cs->appendChild($keywordText);
- $keyword->appendChild($keyword_cs);
- $MD_Keywords->appendChild($keyword);
+ if (isset($row['keyword']) && $row['keyword'] != "") {
+
+ $keyword=$iso19139->createElement("gmd:keyword");
+ $keyword_cs=$iso19139->createElement("gco:CharacterString");
+ $keywordText = $iso19139->createTextNode($row['keyword']);
+ $keyword_cs->appendChild($keywordText);
+ $keyword->appendChild($keyword_cs);
+ $MD_Keywords->appendChild($keyword);
+ }
}
//pull special keywords from custom categories:
$e = new mb_notice("layer: ".$layerId);
Modified: trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php 2013-04-30 07:07:06 UTC (rev 8611)
+++ trunk/mapbender/http/php/mod_inspireAtomFeedISOMetadata.php 2013-05-02 09:09:30 UTC (rev 8612)
@@ -58,6 +58,8 @@
//Initialize XML document
$iso19139Doc = new DOMDocument('1.0');
$iso19139Doc->encoding = 'UTF-8';
+ $iso19139Doc->preserveWhiteSpace = false;
+ $iso19139Doc->formatOutput = true;
} else {
//echo 'outputFormat: <b>'.$_REQUEST['OUTPUTFORMAT'].'</b> is not set or valid.<br/>';
echo 'Parameter <b>outputFormat</b> is not set or valid (iso19139).<br/>';
Modified: trunk/mapbender/http/php/mod_inspireDownloadFeed.php
===================================================================
--- trunk/mapbender/http/php/mod_inspireDownloadFeed.php 2013-04-30 07:07:06 UTC (rev 8611)
+++ trunk/mapbender/http/php/mod_inspireDownloadFeed.php 2013-05-02 09:09:30 UTC (rev 8612)
@@ -1135,7 +1135,7 @@
$splittedLink = explode('&FILTER=',$furtherLink[$m]);
$furtherLink[$m] = $splittedLink[0];
}
- $furtherLinkType[$m] = "text/xml; subtype=gml/3.1.1";//TODO: set right format for wfs version!
+ $furtherLinkType[$m] = "application/gml+xml";//inspire media type registry http://inspire.ec.europa.eu/media-types/
$currentIndex = $m+1;
$furtherLinkTitle[$m] = $ressourceTitle." im CRS ".$mapbenderMetadata[$i]->metadata_ref_system." - ".$mapbenderMetadata[$i]->format." - Teil ".$currentIndex." von ".count($getFeatureLink)."";//TODO: set right format for wfs version!
//$furtherLinkBbox[$m] = $featureTypeBbox[$m];
Modified: trunk/mapbender/http/php/mod_wfs_server.php
===================================================================
--- trunk/mapbender/http/php/mod_wfs_server.php 2013-04-30 07:07:06 UTC (rev 8611)
+++ trunk/mapbender/http/php/mod_wfs_server.php 2013-05-02 09:09:30 UTC (rev 8612)
@@ -232,12 +232,13 @@
* @return boolean success
*/
function updateWfs($obj){
- //TODO: Update not the whole WFS, use the mapbender internal things and the metadata if wished!
$id = $obj->wfs;
$url = $obj->url;
-
$wfsFactory = new UniversalWfsFactory();
$myWfs = $wfsFactory->createFromUrl($url);
+ if (!MD_OVERWRITE) {
+ $myWfs->overwrite = false;
+ }
$myWfs->id = $id;
if(is_null($myWfs) || !$myWfs->update()){
More information about the Mapbender_commits
mailing list