Module: nagvis
Branch: master
Commit: caa06c51363aef619168ee1ef553dbf338fa228c
URL:    
http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=caa06c51363aef619168ee1ef553dbf338fa228c

Author: Lars Michelsen <[email protected]>
Date:   Wed Apr 28 23:15:07 2010 +0200

Added sqlite update code to bring old database versions to new 1.5b4 scheme

---

 share/server/core/classes/CoreAuthModSQLite.php    |    3 ++
 .../core/classes/CoreAuthorisationModSQLite.php    |    3 ++
 share/server/core/classes/CoreSQLiteHandler.php    |   28 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/share/server/core/classes/CoreAuthModSQLite.php 
b/share/server/core/classes/CoreAuthModSQLite.php
index d788dea..5f28ebb 100644
--- a/share/server/core/classes/CoreAuthModSQLite.php
+++ b/share/server/core/classes/CoreAuthModSQLite.php
@@ -65,6 +65,9 @@ class CoreAuthModSQLite extends CoreAuthModule {
                        // Create initial db scheme if needed
                        if(!$this->DB->tableExist('users')) {
                                $this->DB->createInitialDb();
+                       } else {
+                               // Maybe an update is needed
+                               $this->DB->updateDb();
                        }
                }
        }
diff --git a/share/server/core/classes/CoreAuthorisationModSQLite.php 
b/share/server/core/classes/CoreAuthorisationModSQLite.php
index 9bddfdd..33bd82c 100644
--- a/share/server/core/classes/CoreAuthorisationModSQLite.php
+++ b/share/server/core/classes/CoreAuthorisationModSQLite.php
@@ -44,6 +44,9 @@ class CoreAuthorisationModSQLite extends 
CoreAuthorisationModule {
                        // Create initial db scheme if needed
                        if(!$this->DB->tableExist('users')) {
                                $this->DB->createInitialDb();
+                       } else {
+                               // Maybe an update is needed
+                               $this->DB->updateDb();
                        }
                }
        }
diff --git a/share/server/core/classes/CoreSQLiteHandler.php 
b/share/server/core/classes/CoreSQLiteHandler.php
index 56c7e93..cc5f93f 100644
--- a/share/server/core/classes/CoreSQLiteHandler.php
+++ b/share/server/core/classes/CoreSQLiteHandler.php
@@ -173,6 +173,34 @@ class CoreSQLiteHandler {
        private function addRolePerm($roleId, $mod, $act, $obj) {
                $this->DB->query('INSERT INTO roles2perms (roleId, permId) 
VALUES ('.$roleId.', (SELECT permId FROM perms WHERE mod=\''.$mod.'\' AND 
act=\''.$act.'\' AND obj=\''.$obj.'\'))');
        }
+
+       public function updateDb() {
+               if(!$this->tableExist('version')) {
+                       // Perform pre b4 updates
+                       $this->updateDb15b4();
+               }
+       }
+
+       private function updateDb15b4() {
+               if(DEBUG&&DEBUGLEVEL&2) debug('auth.db: Performing update to 
1.5b4 scheme');
+               
+               $this->DB->query('CREATE TABLE version (version VARCHAR(100), 
PRIMARY KEY(version))');
+               $this->DB->query('INSERT INTO version (version) VALUES 
(\''.CONST_VERSION.'\')');
+
+               // Add addModify permission
+               $RES = $this->DB->query('SELECT obj FROM perms WHERE 
mod=\'Map\' AND act=\'view\'');
+               while($data = $this->fetchAssoc($RES)) {
+                       if(DEBUG&&DEBUGLEVEL&2) debug('auth.db: Adding new 
addModify perms for map '.$data['obj']);
+                       $this->DB->query('INSERT INTO perms (mod, act, obj) 
VALUES (\'Map\', \'addModify\', '.$this->escape($data['obj']).')');
+               }
+
+               // Assign the addModify permission to the managers
+               $RES = $this->DB->query('SELECT roleId FROM roles WHERE 
name=\'Managers\'');
+               while($data = $this->fetchAssoc($RES)) {
+                       if(DEBUG&&DEBUGLEVEL&2) debug('auth.db: Assigning 
addModify perms to Managers role');
+                       $this->addRolePerm($data['roleId'], 'Map', 'addModify', 
'*');
+               }
+       }
        
        public function createInitialDb() {
                $this->DB->query('CREATE TABLE users (userId INTEGER, name 
VARCHAR(100), password VARCHAR(40), PRIMARY KEY(userId), UNIQUE(name))');


------------------------------------------------------------------------------
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to