[icinga-checkins] icinga.org: icinga-web/master: * Fix for working with models and different databases

git at icinga.org git at icinga.org
Thu Feb 2 13:34:36 CET 2012


Module: icinga-web
Branch: master
Commit: dfc26662f4db90be960cce1c66195a137c720cf4
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=dfc26662f4db90be960cce1c66195a137c720cf4

Author: Marius Hein <marius.hein at netways.de>
Date:   Thu Feb  2 13:34:17 2012 +0100

* Fix for working with models and different databases

---

 .../lib/database/IcingaDoctrineDatabase.class.php  |    9 +++++++++
 .../Cronks/lib/model/CronksBaseModel.class.php     |    5 ++++-
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/app/modules/Api/lib/database/IcingaDoctrineDatabase.class.php b/app/modules/Api/lib/database/IcingaDoctrineDatabase.class.php
index 787f885..3f592ac 100644
--- a/app/modules/Api/lib/database/IcingaDoctrineDatabase.class.php
+++ b/app/modules/Api/lib/database/IcingaDoctrineDatabase.class.php
@@ -5,6 +5,15 @@ class IcingaDoctrineDatabase extends AppKitDoctrineDatabase {
     const CONNECTION_ICINGA = 'icinga';
 
     private $use_retained = false;
+    
+    /**
+     * When working with icinga objects and multiple addon databases
+     * this method ensures that you're working on the right space!
+     */
+    public static function resetCurrentConnection() {
+        Doctrine_Manager::getInstance()->setCurrentConnection(self::CONNECTION_ICINGA);
+    }
+    
     public function initialize(AgaviDatabaseManager $databaseManager, array $parameters = array()) {
         parent::initialize($databaseManager, $parameters);
         
diff --git a/app/modules/Cronks/lib/model/CronksBaseModel.class.php b/app/modules/Cronks/lib/model/CronksBaseModel.class.php
index 6df3cce..1de2761 100644
--- a/app/modules/Cronks/lib/model/CronksBaseModel.class.php
+++ b/app/modules/Cronks/lib/model/CronksBaseModel.class.php
@@ -4,7 +4,10 @@
  * The base model from which all Cronks module models inherit.
  */
 class CronksBaseModel extends AppKitBaseModel {
-    // EMPTY
+    public function initialize(AgaviContext $context, array $parameters = array()) {
+        parent::initialize($context, $parameters);
+        IcingaDoctrineDatabase::resetCurrentConnection();
+    }
 }
 
 ?>
\ No newline at end of file





More information about the icinga-checkins mailing list