[icinga-checkins] icinga.org: icinga-web/mhein/default: Removing the last route of a context doesn't screw up the routing anymore

git at icinga.org git at icinga.org
Tue Apr 13 13:17:21 CEST 2010


Module: icinga-web
Branch: mhein/default
Commit: 11845cfded7275154a1080ea09ec0ecc54e9c73b
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=11845cfded7275154a1080ea09ec0ecc54e9c73b

Author: jmosshammer <jmosshammer at ws-jmosshammer.(none)>
Date:   Thu Apr  8 11:36:19 2010 +0200

Removing the last route of a context doesn't screw up the routing anymore

---

 plugins/bin/doctrineDBBuilderTask.php         |    5 +-
 plugins/bin/manifestAgaviConfiguratorTask.php |    6 ++-
 plugins/bin/manifestRouteRemover.php          |   41 +++++++++++++++++
 plugins/bin/manifestRouteRemoverTask.php      |   60 +++++++++++++++++++++++++
 plugins/build.xml                             |    5 +-
 plugins/db.ini                                |   21 +++++++++
 6 files changed, 131 insertions(+), 7 deletions(-)

diff --git a/plugins/bin/doctrineDBBuilderTask.php b/plugins/bin/doctrineDBBuilderTask.php
index 873ee0f..b05773c 100644
--- a/plugins/bin/doctrineDBBuilderTask.php
+++ b/plugins/bin/doctrineDBBuilderTask.php
@@ -34,6 +34,7 @@ class doctrineDBBuilderTask extends Task {
 		
 		require_once($doctrinePath."/Doctrine.php");
 		spl_autoload_register("Doctrine::autoload");
+//		spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
 		
 		$iniData = parse_ini_file($this->ini);
 		if(empty($iniData))
@@ -55,7 +56,7 @@ class doctrineDBBuilderTask extends Task {
 	public function buildDBFromModels() {	
 		$icinga = $this->project->getUserProperty("PATH_Icinga");
 		$modelPath = $icinga."/app/modules/".$this->project->getUserProperty("PLUGIN_Name")."/lib/";
-		Doctrine::createTablesFromModels($this->models);
+		Doctrine::createTablesFromModels(array($this->models.'/generated',$this->models));
 		Doctrine::loadModels($this->models);
 		$tables = Doctrine::getLoadedModels();
 		$tableList = array();
@@ -79,4 +80,4 @@ class doctrineDBBuilderTask extends Task {
 	}
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/plugins/bin/manifestAgaviConfiguratorTask.php b/plugins/bin/manifestAgaviConfiguratorTask.php
index 1d93244..0d9a60d 100644
--- a/plugins/bin/manifestAgaviConfiguratorTask.php
+++ b/plugins/bin/manifestAgaviConfiguratorTask.php
@@ -157,8 +157,10 @@ class ManifestAgaviConfiguratorTask extends Task {
 				$route = $child;
 				break;
 			}			
-			if($routingSearcher->query("//default:configuration[@context='".$context."']/default:routes/default:route[@name='".$routeName."']")->item(0))
-				throw new BuildException("Route ".$routeName." already exists - aborting");
+			if($routingSearcher->query("//default:configuration[@context='".$context."']/default:routes/default:route[@name='".$routeName."']")->item(0)) {
+				echo("Route ".$routeName." already exists - skipping\n");
+				continue;
+			}
 			$contextConfigs = $routingSearcher->query("//default:configuration[@context='".$context."']/default:routes");
 			$config = null;
 			if($contextConfigs->length < 1) {
diff --git a/plugins/bin/manifestRouteRemover.php b/plugins/bin/manifestRouteRemover.php
new file mode 100644
index 0000000..a763204
--- /dev/null
+++ b/plugins/bin/manifestRouteRemover.php
@@ -0,0 +1,41 @@
+<?php
+
+require_once "manifestBaseClass.php";
+
+class ManifestRouteExtractorTask extends manifestBaseClass {
+	
+    public function main() {
+		parent::main();
+    	$this->removeRoutes();
+	}
+	public function removeRoutes() {
+		$manifest = $this->getXMLObject();
+		$configPath = $this->project->getUserProperty("PATH_Icinga")."/app/config/routing.xml";
+		$configDOM = new DOMDocument("1.0");
+		$configDOM->preserveWhiteSpaces = false;
+		$configDOM->load($configPath);
+		
+		$configSearcher = new DOMXPath($configDOM);
+		$configSearcher->registerNamespace("default","http://agavi.org/agavi/1.0/config");
+		foreach($manifest->Config->Routes->children() as $route) {
+			$context = $route["context"];
+			$name = $route["name"];
+			$routeToRemove = $configSearcher->query("//default:configuration[@context='".$context."']//route[@name='".$name."']")->item(0);
+			if(!$routeToRemove)
+				throw new BuildException("Route ".$name." not found!");
+			$configDOM->removeChild($routeToRemove);				
+		}
+		$configDOM->formatOutput = true;
+		$configDOM->save($configPath);
+		$this->reformat($configPath);
+	}
+	
+	protected function reformat($configPath) {
+		// Reformat the xml (triple whitespaces to tab)
+		$file = file_get_contents($configPath);
+		$file = preg_replace("/\t/","   ",$file);
+		$file = preg_replace("/ {3}/","\t",$file);
+		file_put_contents($configPath,$file);
+	}
+	
+}
\ No newline at end of file
diff --git a/plugins/bin/manifestRouteRemoverTask.php b/plugins/bin/manifestRouteRemoverTask.php
new file mode 100644
index 0000000..0e6c634
--- /dev/null
+++ b/plugins/bin/manifestRouteRemoverTask.php
@@ -0,0 +1,60 @@
+<?php
+
+require_once "manifestBaseClass.php";
+
+class ManifestRouteRemoverTask extends manifestBaseClass {
+
+	public function main() {
+		parent::main();
+		$this->removeRoutes();
+	}
+	public function removeRoutes() {
+		$manifest = $this->getXMLObject();
+		$configPath = $this->project->getUserProperty("PATH_Icinga")."/app/config/routing.xml";
+		$configDOM = new DOMDocument("1.0");
+		$configDOM->preserveWhiteSpaces = false;
+		$configDOM->load($configPath);
+
+		$configSearcher = new DOMXPath($configDOM);
+		$configSearcher->registerNamespace("default","http://agavi.org/agavi/1.0/config");
+		foreach($manifest->Config->Routes->children() as $route) {
+			$context = $route["context"];
+			$name = $route["name"];
+			$routeToRemove = $configSearcher->query("//default:configuration[@context='".$context."']//default:route[@name='".$name."']")->item(0);
+			if(!$routeToRemove)
+			throw new BuildException("Route ".$name." not found!");
+			$node = $routeToRemove->parentNode;
+			$routeToRemove->parentNode->removeChild($routeToRemove);
+			// remove empty branches
+			$this->checkIfNodeIsEmpty($node);
+				
+			echo "Removing route ".$name."\n";
+		}
+
+		$configDOM->formatOutput = true;
+		$configDOM->save($configPath);
+		$this->reformat($configPath);
+	}
+
+	protected function checkIfNodeIsEmpty(DOMNode $node) {
+		if($node->nodeName == "routes") {
+			foreach($node->childNodes as $child) {
+				if($child->nodeName == "route")
+				return true;
+			}
+		}
+		$node->parentNode->parentNode->removeChild($node->parentNode);
+
+		return true;
+	}
+
+
+	protected function reformat($configPath) {
+		// Reformat the xml (triple whitespaces to tab)
+		$file = file_get_contents($configPath);
+		$file = preg_replace("/\t/","   ",$file);
+		$file = preg_replace("/ {3}/","\t",$file);
+		file_put_contents($configPath,$file);
+	}
+
+}
\ No newline at end of file
diff --git a/plugins/build.xml b/plugins/build.xml
index c54a92b..b5d78d4 100644
--- a/plugins/build.xml
+++ b/plugins/build.xml
@@ -124,9 +124,8 @@
 			
 		 -->
 		<echo>Removing Routes</echo>
-		<taskdef name="manifestXPathRemover" classname="bin.manifestXPathRemoverTask" />
-		<manifestXPathRemover target="routing.xml" file="${manifest}" ns="default" uri="http://agavi.org/agavi/1.0/config" cfgPath="//Config/Routes/Route" 
-								removePath="//default:configuration[@context='%context%']//default:route[@name='%name%']"/>
+		<taskdef name="manifestRouteRemover" classname="bin.manifestRouteRemoverTask" />
+		<manifestRouteRemover file="${manifest}" />
 
 		<echo>Removing Config-Entries</echo>
 		<taskdef name="manifestSettingsRemover" classname="bin.manifestSettingsRemoverTask" />
diff --git a/plugins/db.ini b/plugins/db.ini
new file mode 100644
index 0000000..3401628
--- /dev/null
+++ b/plugins/db.ini
@@ -0,0 +1,21 @@
+; DB Setup ini
+; Change these values to fit to your DB
+; 
+; !! Please notice that keeping the db-password in this file after installing the plugin is a security risk !!
+
+;Type of your database
+dbtype = "mysql"
+
+;Address of the database
+host = "127.0.0.1"
+port = "3306"
+dbname = "icinga"
+
+;Credentials 
+dbuser = "icinga"
+dbpass = "icinga"
+
+
+
+
+





More information about the icinga-checkins mailing list