[Mapbender-commits] r8733 - in trunk/mapbender: http/classes http/php tools

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Fri Oct 25 03:33:08 PDT 2013


Author: armin11
Date: 2013-10-25 03:33:08 -0700 (Fri, 25 Oct 2013)
New Revision: 8733

Modified:
   trunk/mapbender/http/classes/class_wms.php
   trunk/mapbender/http/php/mb_getWmsData.php
   trunk/mapbender/http/php/mod_createJSLayerObjFromXML.php
   trunk/mapbender/http/php/mod_createJSObjFromXML.php
   trunk/mapbender/http/php/mod_loadwms.php
   trunk/mapbender/http/php/mod_monitorCapabilities_read.php
   trunk/mapbender/http/php/mod_updateWMS.php
   trunk/mapbender/tools/mod_runScheduler.php
Log:
Give possibility to propagate error messages from wms XML parsing to other modules. TODO: Enhance wms capabilities tests and give reasonable error messages.

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2013-10-24 10:29:48 UTC (rev 8732)
+++ trunk/mapbender/http/classes/class_wms.php	2013-10-25 10:33:08 UTC (rev 8733)
@@ -1064,20 +1064,63 @@
 				continue;
 			}
 		}
+
+		//test if there are double layer names! - if so give a reasonable feedback to the users!
+		//create array of layer_names:
+		foreach ($this->objLayer as $layer) {
+			$layerNames[] = $layer->layer_name;
+			//$e = new mb_exception("class_wms: createObjFromXML: layer name: " . $layer->layer_name);
+		}		
+		//double entries
+		$doubleLayers = $this->array_not_unique($layerNames);
+		//foreach ($doubleLayers as $layer) {
+		//	$e = new mb_exception("class_wms: createObjFromXML: double layers: " . $layer);
+		//}
+
+		if(count($doubleLayers) > 0) {
+			$e = new mb_exception("class_wms: createObjFromXML: WMS has " . count($doubleLayers) . " double layer name entries and could therefor not be loaded.");
+			$returnObject['success'] = false;
+			$returnObject['message'] = _mb("WMS has double layer names and could therefor not be loaded!");
+			return $returnObject;	
+		}
+
 		if(!$this->wms_title || $this->wms_title == "" || !$this->wms_getmap || $this->wms_getmap == ""){
 			$this->wms_status = false;
 			$this->optimizeWMS();
 			$e = new mb_exception("class_wms: createObjFromXML: WMS " . $url . " could not be loaded.");
-			return false;
+			$returnObject['success'] = false;
+			$returnObject['message'] = _mb("WMS could not be loaded!");
+			return $returnObject;	
 		}
+
 		else{
 			$this->wms_status = true;
 			$this->optimizeWMS();
 			$e = new mb_notice("class_wms: createObjFromXML: WMS " . $url . " has been loaded successfully.");
-			return true;
+			$returnObject['success'] = true;
+			return $returnObject;	
 		}
 	}
-	
+
+	//http://stackoverflow.com/questions/1259407/php-return-only-duplicated-entries-from-an-array
+	function array_not_unique($raw_array) {
+    		$dupes = array();
+    		natcasesort($raw_array);
+    		reset ($raw_array);
+   		$old_key    = NULL;
+     		$old_value    = NULL;
+  		foreach ($raw_array as $key => $value) {
+        		if ($value === NULL) { continue; }
+        		if (strcasecmp($old_value, $value) === 0) {
+            			$dupes[$old_key]    = $old_value;
+            			$dupes[$key]        = $value;
+        		}
+        		$old_value    = $value;
+        		$old_key    = $key;
+    		}
+		return $dupes;
+	}
+
 	function getLayerInfo() {
 	    $resultArray = array();
 	    for($i=0; $i<count($this->objLayer); $i++){

Modified: trunk/mapbender/http/php/mb_getWmsData.php
===================================================================
--- trunk/mapbender/http/php/mb_getWmsData.php	2013-10-24 10:29:48 UTC (rev 8732)
+++ trunk/mapbender/http/php/mb_getWmsData.php	2013-10-25 10:33:08 UTC (rev 8733)
@@ -56,15 +56,15 @@
     	//get xml wms information
 	$updateWms = new wms();
 	if ($useAuthentication) {
-		$xml = $updateWms->createObjFromXML($url, $auth);
+		$result = $updateWms->createObjFromXML($url, $auth);
 	} else {
-		$xml = $updateWms->createObjFromXML($url);
+		$result = $updateWms->createObjFromXML($url);
 	}
-	if($xml == "") {
-	    echo "WMS could not be loaded, no valid XML. Please check WMS GetCapabilities";
-	    die();
+	if(!$result['success']) {
+	    	echo $result['message'];
+	    	die();
 	}
-	    
+
 	$updateWms->optimizeWMS();
 	$xmlObj = $updateWms->getLayerInfo();
 	
@@ -105,10 +105,14 @@
 	
     	$mywms = new wms();
 	if ($useAuthentication) {
-		$mywms->createObjFromXML($url, $auth);   
+		$result = $mywms->createObjFromXML($url, $auth);   
 	} else {
-		$mywms->createObjFromXML($url);  
+		$result = $mywms->createObjFromXML($url);  
 	}
+	if(!$result['success']) {
+	    	echo $result['message'];
+	    	die();
+	}
 	$mywms->optimizeWMS();
 	echo "<br />";  
 	if (!MD_OVERWRITE) {

Modified: trunk/mapbender/http/php/mod_createJSLayerObjFromXML.php
===================================================================
--- trunk/mapbender/http/php/mod_createJSLayerObjFromXML.php	2013-10-24 10:29:48 UTC (rev 8732)
+++ trunk/mapbender/http/php/mod_createJSLayerObjFromXML.php	2013-10-25 10:33:08 UTC (rev 8733)
@@ -29,8 +29,18 @@
 $charset = CHARSET;
 
 $mywms = new wms();
-$mywms->createObjFromXML($capabilitiesURL);
+$result = $mywms->createObjFromXML($capabilitiesURL);
 
+if (!$result['success']) {
+	$output .= "try {" . 
+		"Mapbender.Modules.dialogManager.openDialog({" . 
+		"content: '" . $result['message'] . "<br><br><b>" . $capabilitiesURL . 
+		"', modal: false, effectShow: 'puff'});" . 
+		"} catch (e) {" . 
+		"prompt('" . $result['message'] . "', '" . $capabilitiesURL . "');" . 
+		"}";
+}
+/*
 $errorMessage = _mb("Error: The Capabilities Document could not be accessed. " . 
 	"Please check whether the server is responding and accessible to " . 
 	"Mapbender.");
@@ -42,7 +52,7 @@
 		"} catch (e) {" . 
 		"prompt('" . $errorMessage . "', '" . $capabilitiesURL . "');" . 
 		"}";
-}
+}*/
 else {
 	if ($noHtml) {
 		$output .= $mywms->createJsLayerObjFromWMS(false, $layerName);

Modified: trunk/mapbender/http/php/mod_createJSObjFromXML.php
===================================================================
--- trunk/mapbender/http/php/mod_createJSObjFromXML.php	2013-10-24 10:29:48 UTC (rev 8732)
+++ trunk/mapbender/http/php/mod_createJSObjFromXML.php	2013-10-25 10:33:08 UTC (rev 8733)
@@ -35,8 +35,18 @@
 #$e = new mb_exception("mod_createJSObjFromXML: CapUrl decodes to load: ".$caps);
 $caps = html_entity_decode($_REQUEST['caps']);
 //$caps = html_entity_decode(base64_decode($_REQUEST['caps']));
-$mywms->createObjFromXML($caps);
+$result = $mywms->createObjFromXML($caps);
 
+if (!$result['success']) {
+	$output .= "try {" . 
+		"Mapbender.Modules.dialogManager.openDialog({" . 
+		"content: '" . $result['message'] . "<br><br><b>" . $capabilitiesURL . 
+		"', modal: false, effectShow: 'puff'});" . 
+		"} catch (e) {" . 
+		"prompt('" . $result['message'] . "', '" . $capabilitiesURL . "');" . 
+		"}";
+}
+/*
 $errorMessage = _mb("Error: The Capabilities Document could not be accessed. " . 
 	"Please check whether the server is responding and accessible to " . 
 	"Mapbender.");
@@ -48,7 +58,7 @@
 		"} catch (e) {" . 
 		"prompt('" . $errorMessage . "', '" . $capabilitiesURL . "');" . 
 		"}";
-}
+}*/
 else {
 	if ($noHtml) {
 		$output .= $mywms->createJsObjFromWMS_(false);

Modified: trunk/mapbender/http/php/mod_loadwms.php
===================================================================
--- trunk/mapbender/http/php/mod_loadwms.php	2013-10-24 10:29:48 UTC (rev 8732)
+++ trunk/mapbender/http/php/mod_loadwms.php	2013-10-25 10:33:08 UTC (rev 8733)
@@ -41,12 +41,22 @@
 		$mywms->setGeoRss = false;
 	}
 	if (isset($auth)) {
-		$mywms->createObjFromXML($xml, $auth);	
-	    	$mywms->writeObjInDB($gui_id, $auth);  
+		$result = $mywms->createObjFromXML($xml, $auth);	
+		if ($result['success']) {
+			$mywms->writeObjInDB($gui_id, $auth);  
+		} else {
+			echo $result['message'];
+			die();
+		}
 	}
 	else {
-		$mywms->createObjFromXML($xml);	
-		$mywms->writeObjInDB($gui_id);
+		$result = $mywms->createObjFromXML($xml);
+		if ($result['success']) {
+			$mywms->writeObjInDB($gui_id);  
+		} else {
+			echo $result['message'];
+			die();
+		}
 	}
         
    	$mywms->displayWMS();

Modified: trunk/mapbender/http/php/mod_monitorCapabilities_read.php
===================================================================
--- trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2013-10-24 10:29:48 UTC (rev 8732)
+++ trunk/mapbender/http/php/mod_monitorCapabilities_read.php	2013-10-25 10:33:08 UTC (rev 8733)
@@ -69,38 +69,43 @@
 		
 		// update WMS from upload URL
 		$mywms = new wms();
-		$mywms->createObjFromXML($uploadUrl);    
-		$mywms->optimizeWMS();
+		$result = $mywms->createObjFromXML($uploadUrl);
+
+		if (!$result['success']) {
+	    		//echo $result['message']; //do nothing first - TODO give negative result!
+	    		//die();
+		} else {
+			$mywms->optimizeWMS();
 		
-		echo "<br />";  
-		if (!MD_OVERWRITE) {
-			$mywms->overwrite=false;
-		} 
-		//possibility to see update information in georss and/or twitter channel
-		if(empty($_POST['twitter_news'])) {
-			$mywms->twitterNews = false;
+			echo "<br />";  
+			if (!MD_OVERWRITE) {
+				$mywms->overwrite=false;
+			} 
+			//possibility to see update information in georss and/or twitter channel
+			if(empty($_POST['twitter_news'])) {
+				$mywms->twitterNews = false;
+			}
+			if(empty($_POST['rss_news'])) {
+				$mywms->setGeoRss = false;
+			}	
+			$mywms->updateObjInDB($upd_wmsid);
+			echo "<br>Updated: " . $upd_wmsid . "<br>";
 		}
-		if(empty($_POST['rss_news'])) {
-			$mywms->setGeoRss = false;
-		}	
-		$mywms->updateObjInDB($upd_wmsid);
-		echo "<br>Updated: " . $upd_wmsid . "<br>";
-
-/*
-		// start new monitoring for this WMS
-		$now = time();
-		$sql = "UPDATE mb_monitor SET status = '-2', status_comment = 'Monitoring is still in progress...', " . 
+	/*
+			// start new monitoring for this WMS
+			$now = time();
+			$sql = "UPDATE mb_monitor SET status = '-2', status_comment = 'Monitoring is still in progress...', " . 
 			"timestamp_begin = $1, timestamp_end = $2 WHERE upload_id = $3 AND fkey_wms_id = $4";
-		$v = array($now, $now, $upload_id, $upd_wmsid);
-		$t = array('s', 's', 's', 'i');
-		$res = db_prep_query($sql,$v,$t);
+			$v = array($now, $now, $upload_id, $upd_wmsid);
+			$t = array('s', 's', 's', 'i');
+			$res = db_prep_query($sql,$v,$t);
 
-		$currentFilename = "wms_monitor_report_" . $upload_id . "_" . 
+			$currentFilename = "wms_monitor_report_" . $upload_id . "_" . 
 			$upd_wmsid . "_" . $wmsOwner . ".xml";		
-		$exec = PHP_PATH . "php5 ../../tools/mod_monitorCapabilities_write.php " . 
-			$currentFilename. " 0";
-		echo exec(escapeshellcmd($exec));
-*/
+			$exec = PHP_PATH . "php5 ../../tools/mod_monitorCapabilities_write.php " . 
+				$currentFilename. " 0";
+			echo exec(escapeshellcmd($exec));
+	*/
 	}
 	echo "<br>Please note: The updated services need to be monitored again in order to update the database.<br><br>";
 }

Modified: trunk/mapbender/http/php/mod_updateWMS.php
===================================================================
--- trunk/mapbender/http/php/mod_updateWMS.php	2013-10-24 10:29:48 UTC (rev 8732)
+++ trunk/mapbender/http/php/mod_updateWMS.php	2013-10-25 10:33:08 UTC (rev 8733)
@@ -464,21 +464,21 @@
  		$auth['username'] = $imrAuthName; 
  		$auth['password'] = $imrAuthPassword; 
  		$auth['auth_type'] = $imrHttpAuth; 
- 		$mywms->createObjFromXML($myURL, $auth); 
+ 		$result = $mywms->createObjFromXML($myURL, $auth); 
  	} elseif ($imrHttpAuth == 'keep') { 
  		$auth = array(); 
  		$auth['username'] = $imrOldAuthName; 
  		$auth['password'] = $imrOldAuthPasswword; 
  		$auth['auth_type'] = $imrOldAuthType; 
- 		$mywms->createObjFromXML($myURL, $auth); 
+ 		$result = $mywms->createObjFromXML($myURL, $auth); 
  	} else { 
- 		$mywms->createObjFromXML($myURL); 
+ 		$result = $mywms->createObjFromXML($myURL); 
  	} 
 
-	/*if($xml == "") {
-	    echo "<br>WMS could not be loaded, no valid XML. Please check WMS GetCapabilities";
-	    die();
-	}*/
+	if (!$result['success']) {
+	    	echo $result['message'];
+	    	die();
+	}
 	
 	$mywms->optimizeWMS();
 	echo "<br />";  

Modified: trunk/mapbender/tools/mod_runScheduler.php
===================================================================
--- trunk/mapbender/tools/mod_runScheduler.php	2013-10-24 10:29:48 UTC (rev 8732)
+++ trunk/mapbender/tools/mod_runScheduler.php	2013-10-25 10:33:08 UTC (rev 8733)
@@ -74,8 +74,9 @@
     	//create new wms object
     	$updateWms = new wms();
     	$createObjFromXml = $updateWms->createObjFromXML($wmsToUpdate[$i]['wms_upload_url']);
-    	if(!$createObjFromXml) {
-        	$errorMsg = "Error while creating object from GetCapabilities XML";
+    	if(!$createObjFromXml['success']) {
+        	//$errorMsg = "Error while creating object from GetCapabilities XML";
+		$errorMsg =$createObjFromXml['message'];
     	}
     	//check scheduler_searchable attribute for layer searchable in class_wms.php
     	$updateWms->optimizeWMS($wmsToUpdate[$i]['scheduler_searchable']);
@@ -104,7 +105,7 @@
 		$updateWms->setGeoRss=false;
 		echo "publish = false\n";
 	}
-	die();
+	
    	$updateObjInDb = $updateWms->updateObjInDB($wmsToUpdate[$i]['wms_id']);
     	if(!$updateObjInDb) {
     	    $errorMsg = "Error while updating wms object in database";



More information about the Mapbender_commits mailing list