[icinga-checkins] icinga.org: icinga-web/jmosshammer/default2: * Base Models are now loaded first

git at icinga.org git at icinga.org
Fri May 28 16:06:09 CEST 2010


Module: icinga-web
Branch: jmosshammer/default2
Commit: 1907dbd419cdd98cd43a75d1edc868447e956924
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=1907dbd419cdd98cd43a75d1edc868447e956924

Author: jmosshammer <jannis.mosshammer at netways.de>
Date:   Fri May 28 16:05:48 2010 +0200

* Base Models are now loaded first

---

 etc/build.xml            |   15 ++++++---------
 etc/lib/dbUpdateTask.php |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 etc/lib/doctrineTask.php |    2 +-
 3 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/etc/build.xml b/etc/build.xml
index ed2eefd..4140d34 100755
--- a/etc/build.xml
+++ b/etc/build.xml
@@ -62,6 +62,11 @@
 		
 	</target>
 	
+	<target name="db-upgrade" depends="db-prepare">
+		<taskdef name="dbUpdate" classname="etc.lib.dbUpdateTask"/>
+		<dbUpdate icingapath="${src}" modelPath="${db.doctrine.models}" dsn="${db.dsn}"/>
+	</target>
+	
 	<target name="db-drop" depends="db-prepare">
 		
 		<input propertyname="db.sql.dropchoice" promptChar="?" validArgs="no,DROPMYDATA">Really drop the database</input>
@@ -77,6 +82,7 @@
 			</else>
 		</if>
 	</target>
+	
 	<target name="doc2sql" depends="db-prepare">
 		<taskdef name="doctrineToSql" classname="etc.lib.doctrineToSqlTask"/>
 		<input propertyname="db.sql.path" defaultValue="${src}etc/schema/" >Save .sql at:</input>
@@ -89,15 +95,6 @@
 			file="${db.sql.path}"
 		/>
 	</target>
-
-	<target name="db-upgrade" depends="db-prepare">
-		<exec
-		command="${db.deployer.call_global} --migrationStore ${dbMigrations} --update --ignoreErrors"
-		dir="${builddir}"
-		passthru="true"
-		checkreturn="false" />
-	</target>
-
 	
 	<target name="db-initialize">
 		<phingcall target="db-create" />
diff --git a/etc/lib/dbUpdateTask.php b/etc/lib/dbUpdateTask.php
new file mode 100644
index 0000000..92cdc79
--- /dev/null
+++ b/etc/lib/dbUpdateTask.php
@@ -0,0 +1,46 @@
+<?php
+
+require_once(dirname(__FILE__)."/doctrineTask.php");
+
+class dbUpdateTask extends doctrineTask {
+	
+	
+	public function main() {
+		parent::main();
+		$this->checkIfDBExists();
+		$this->checkVersion();
+		$this->updateStructure();
+	}
+	
+	public function checkVersion() {
+		$vers = Doctrine_Core::getTable("NsmDbVersion")->findBy("vers_id",1)->getFirst();
+		if(!$vers instanceof NsmDbVersion) {
+			echo "No version number found, proceeding anyway.\n";
+			return true;
+		}
+		$thisVersion = NsmDbVersion::getInitialData();
+		$newVersion = $thisVersion[0]["version"];
+		if($vers->get("version") >= $newVersion) {
+			echo "Current version is equal or higher than the version you provided, no update needed";
+			throw new BuildException("No update performed");
+		}
+		return true;
+	}
+	
+	public function checkIfDBExists() {
+		try {
+			Doctrine_Manager::connection()->connect();
+		} catch(Exception $e) {
+			echo "\nCritical error: DB connection failed: ".$e."\n";
+			throw new BuildException("Unable to connect to database");
+		}
+	}
+	
+	public function updateStructure() {
+		echo "\nUpdating DB Structure";
+		$models = Doctrine::getLoadedModels();
+		print_r($models);
+		
+	}
+	
+}
\ No newline at end of file
diff --git a/etc/lib/doctrineTask.php b/etc/lib/doctrineTask.php
index ce62a64..0e800a8 100644
--- a/etc/lib/doctrineTask.php
+++ b/etc/lib/doctrineTask.php
@@ -33,7 +33,7 @@ class doctrineTask extends Task {
 	public function main() {
 		Doctrine_Manager::connection($this->dsn,"mainConnection");
 	
-		Doctrine::setModelsDirectory($this->modelPath."generated/");
+		Doctrine::loadModels($this->modelPath."generated/");
 		Doctrine::setModelsDirectory($this->modelPath."/");
 		if($this->action == 'dropDB')
 			$this->dropDB();





More information about the icinga-checkins mailing list