[icinga-checkins] icinga.org: icinga-web/mhein/testing: * working state module installer, not used anywhere at this time

git at icinga.org git at icinga.org
Mon Aug 22 15:19:23 CEST 2011


Module: icinga-web
Branch: mhein/testing
Commit: 6868938645cdb8764d621edf21ebcca986a43167
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=6868938645cdb8764d621edf21ebcca986a43167

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Sun Aug 21 15:16:21 2011 +0200

* working state module installer, not used anywhere at this time

---

 .../ModuleInstaller/ModuleValidatorModel.class.php |   54 ++++++++++++++
 .../AppKit/models/ModuleInstallerModel.class.php   |   73 ++++++++++++++++++++
 2 files changed, 127 insertions(+), 0 deletions(-)

diff --git a/app/modules/AppKit/models/ModuleInstaller/ModuleValidatorModel.class.php b/app/modules/AppKit/models/ModuleInstaller/ModuleValidatorModel.class.php
new file mode 100644
index 0000000..3eb79df
--- /dev/null
+++ b/app/modules/AppKit/models/ModuleInstaller/ModuleValidatorModel.class.php
@@ -0,0 +1,54 @@
+<?php
+// Exception tree
+class ModuleValidationException extends AppKitException {}
+class ModuleFolderDoesNotExistException extends ModuleValidationException {}
+class ModuleFolderPermissionException extends ModuleValidationException {}
+
+class AppKit_ModuleInstaller_ModuleValidatorModel extends AppKitBaseModel {
+    protected $modulename;
+    protected $dir; 
+    protected $moduleDom;
+    protected $hasAccessXML = false;
+    protected $hasDatabasesXML = false;
+    protected $hasMenuXML = false;
+
+
+    public function validateModule($modulename) {
+        $this->modulename = $modulename;
+        $this->moduleDom  = new AgaviXmlConfigDomDocument();
+        $this->checkModuleFilesystemConsistency();
+        $this->checkModuleConfig();
+        $this->checkVersion();
+        $this->checkIncludes();
+    }
+
+    protected function checkModuleFilesystemConsistency() {
+        $dir = AgaviToolKit::literalize("%core.module_dir/".$this->modulename);
+        if(!is_dir($dir))
+            throw new ModuleFolderDoesNotExistException("Module folder for $modulename couldn't be found at ".$dir);
+        if(!is_dir($dir."/config"))
+            throw new ModuleFolderDoesNotExistException("Config folder for $modulename couldn't be found at ".$dir);
+        if(!is_readable($dir."/config/module.xml") && !is_readable($dir."/config/module.xml.in"))
+            throw new ModuleFolderPermissionException("Couldn't read module.xml (or module.xml.in)");
+
+        $this->dir = $dir;
+ 
+        // get properties of this module
+        if(is_readable($dir."/config/menu.xml"))
+            $this->hasMenuXML = true;
+        if(is_readable($dir."/config/access.xml"))
+            $this->hasAccessXML = true;
+        if(is_readable($dir."/config/databases.xml"))
+            $this->hasDatabasesXML = true;
+    }       
+    
+
+    protected function checkModuleConfig() {
+        $
+    }
+
+    protected function checkVersion() {
+
+    }
+    
+}
diff --git a/app/modules/AppKit/models/ModuleInstallerModel.class.php b/app/modules/AppKit/models/ModuleInstallerModel.class.php
new file mode 100644
index 0000000..5be7a81
--- /dev/null
+++ b/app/modules/AppKit/models/ModuleInstallerModel.class.php
@@ -0,0 +1,73 @@
+<?php
+
+class ModuleNotFoundException extends AppKitException {};
+
+class AppKit_ModuleInstallerModel extends AppKitBaseModel {
+    private $versionInDB;
+    private $modulename;
+    private $isUpdate = true;
+    private $db;
+
+    private function getModuleVar($var) {
+        return AgaviConfig::get('modules.'.$this->modulename.'.'.$var);
+    }
+
+    private function startTransaction() {
+        $this->db->beginTransaction();  
+    }
+    private function commit() {
+        $this->db->commit();
+    }
+    private function rollback() {
+        $this->db->rollback();
+    }
+
+    private function initDB() {
+        $this->db = $this->getContext()->getDatabaseManager()->getDatabase('icinga_web')->getConnection(); 
+    }
+    
+    public function executeInstallation($modulename) {
+        $this->modulename = $modulename;
+        $version = $this->getModuleVar("version");
+        if(!$version)
+            throw new ModuleNotFoundException('Module '.$modulename.' couldn\'t be found');
+        if($version
+        $this->initDB(); 
+        $this->startTransaction();
+        try {   
+            $this->fetchModuleEntryFromDB();
+            $this->commit();
+        } catch(Exception $e) {
+            $this->rollback();  
+        }
+       
+    }
+
+    private function fetchModuleEntryFromDB() {
+ 
+        $query = $db->createQuery();
+     
+        $this->versionInDB = $query->select('*')
+            ->from('ModuleInfo m')
+            ->where('m.name = ?',$this->modulename)
+            ->execute(null,Doctrine::HYDRATE_RECORD);
+        
+        if(empty($result)) {
+            $this->isUpdate = false;
+            $this->createNewModule();    
+        }
+        $this->checkVersion();
+    }
+
+    private function createNewModule() {
+        $this->versionInDB = new ModuleInfo(); 
+        $this->versionInDB->name = $this->modulename;
+        $this->versionInDB->description = $this->getModuleVar("description");
+        $this->versionInDB->disabled = 1; // disable first
+        $this->versionInDB->version = "0.0.0";
+        $this->versionInDB->installed = new Date();
+        $this->versionInDB->last_update = new Date(); 
+    }
+
+    
+}





More information about the icinga-checkins mailing list