Add migration script for Kronolith.
authorJan Schneider <jan@horde.org>
Tue, 18 Jan 2011 23:11:36 +0000 (00:11 +0100)
committerJan Schneider <jan@horde.org>
Tue, 18 Jan 2011 23:12:56 +0000 (00:12 +0100)
framework/Core/lib/Horde/Core/Share/Driver.php
framework/Share/lib/Horde/Share/Sqlng.php
framework/Share/test/Horde/Share/Sqlng/Base.php
kronolith/migration/15_kronolith_upgrade_sqlng.php [new file with mode: 0644]

index 6d6d448..6bc2cd3 100644 (file)
@@ -28,6 +28,7 @@ class Horde_Core_Share_Driver
      */
     protected $_storageMap = array(
         'Horde_Share_Sql' => 'Horde_Db_Adapter',
+        'Horde_Share_Sqlng' => 'Horde_Db_Adapter',
         'Horde_Share_Sql_Hierarchical' => 'Horde_Db_Adapter',
         'Horde_Share_Kolab' => 'Horde_Kolab_Storage');
 
index 3924e56..544bb15 100644 (file)
@@ -38,6 +38,16 @@ class Horde_Share_Sqlng extends Horde_Share_Sql
     protected $_availablePermissions = array();
 
     /**
+     *
+     * @see Horde_Share_Base::__construct()
+     */
+    public function __construct($app, $user, Horde_Perms $perms, Horde_Group $groups)
+    {
+        parent::__construct($app, $user, $perms, $groups);
+        $this->_table = $this->_app . '_sharesng';
+    }
+
+    /**
      * Passes the available permissions to the share object.
      *
      * @param Horde_Share_Object $object
index 5f2c76f..ace6e22 100644 (file)
@@ -23,7 +23,7 @@ class Horde_Share_Test_Sqlng_Base extends Horde_Share_Test_Base
 
     public function testSetTable()
     {
-        $this->assertEquals('test_shares', self::$share->getTable());
+        $this->assertEquals('test_sharesng', self::$share->getTable());
         self::$share->setTable('foo');
         $this->assertEquals('foo', self::$share->getTable());
         self::$share->setTable('test_shares');
@@ -164,12 +164,10 @@ class Horde_Share_Test_Sqlng_Base extends Horde_Share_Test_Base
     public static function tearDownAfterClass()
     {
         if (self::$db) {
-            /*
             $migration = new Horde_Db_Migration_Base(self::$db);
             $migration->dropTable('test_shares');
             $migration->dropTable('test_shares_groups');
             $migration->dropTable('test_shares_users');
-            */
             self::$db = null;
         }
     }
diff --git a/kronolith/migration/15_kronolith_upgrade_sqlng.php b/kronolith/migration/15_kronolith_upgrade_sqlng.php
new file mode 100644 (file)
index 0000000..be7b787
--- /dev/null
@@ -0,0 +1,176 @@
+<?php
+/**
+ * @author   Jan Schneider <jan@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @package  Kronolith
+ */
+
+require_once dirname(__FILE__) . '/../lib/Kronolith.php';
+
+/**
+ * Adds tables for the Sqlng share driver.
+ *
+ * Copyright 2011 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Jan Schneider <jan@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @package  Kronolith
+ */
+class KronolithUpgradeSqlng extends Horde_Db_Migration_Base
+{
+    /**
+     * Upgrade.
+     */
+    public function up()
+    {
+        $t = $this->createTable('kronolith_sharesng', array('primaryKey' => 'share_id'));
+        $t->column('share_name', 'string', array('limit' => 255, 'null' => false));
+        $t->column('share_owner', 'string', array('limit' => 255));
+        $t->column('share_flags', 'integer', array('default' => 0, 'null' => false));
+        $t->column('perm_creator_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_creator_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_creator_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_creator_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_creator_' . Kronolith::PERMS_DELEGATE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_default_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_default_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_default_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_default_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_default_' . Kronolith::PERMS_DELEGATE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_guest_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_guest_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_guest_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_guest_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_guest_' . Kronolith::PERMS_DELEGATE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('attribute_name', 'string', array('limit' => 255, 'null' => false));
+        $t->column('attribute_desc', 'string', array('limit' => 255));
+        $t->column('attribute_color', 'string', array('limit' => 7));
+        $t->end();
+
+        $this->addIndex('kronolith_sharesng', array('share_name'));
+        $this->addIndex('kronolith_sharesng', array('share_owner'));
+        $this->addIndex('kronolith_sharesng', array('perm_creator_' . Horde_Perms::SHOW));
+        $this->addIndex('kronolith_sharesng', array('perm_creator_' . Horde_Perms::READ));
+        $this->addIndex('kronolith_sharesng', array('perm_creator_' . Horde_Perms::EDIT));
+        $this->addIndex('kronolith_sharesng', array('perm_creator_' . Horde_Perms::DELETE));
+        $this->addIndex('kronolith_sharesng', array('perm_creator_' . Kronolith::PERMS_DELEGATE));
+        $this->addIndex('kronolith_sharesng', array('perm_default_' . Horde_Perms::SHOW));
+        $this->addIndex('kronolith_sharesng', array('perm_default_' . Horde_Perms::READ));
+        $this->addIndex('kronolith_sharesng', array('perm_default_' . Horde_Perms::EDIT));
+        $this->addIndex('kronolith_sharesng', array('perm_default_' . Horde_Perms::DELETE));
+        $this->addIndex('kronolith_sharesng', array('perm_default_' . Kronolith::PERMS_DELEGATE));
+        $this->addIndex('kronolith_sharesng', array('perm_guest_' . Horde_Perms::SHOW));
+        $this->addIndex('kronolith_sharesng', array('perm_guest_' . Horde_Perms::READ));
+        $this->addIndex('kronolith_sharesng', array('perm_guest_' . Horde_Perms::EDIT));
+        $this->addIndex('kronolith_sharesng', array('perm_guest_' . Horde_Perms::DELETE));
+        $this->addIndex('kronolith_sharesng', array('perm_guest_' . Kronolith::PERMS_DELEGATE));
+
+        $t = $this->createTable('kronolith_sharesng_groups', array('primaryKey' => false));
+        $t->column('share_id', 'integer', array('null' => false));
+        $t->column('group_uid', 'string', array('limit' => 255, 'null' => false));
+        $t->column('perm_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Kronolith::PERMS_DELEGATE, 'boolean', array('default' => false, 'null' => false));
+        $t->end();
+
+        $this->addIndex('kronolith_sharesng_groups', array('share_id'));
+        $this->addIndex('kronolith_sharesng_groups', array('group_uid'));
+        $this->addIndex('kronolith_sharesng_groups', array('perm_' . Horde_Perms::SHOW));
+        $this->addIndex('kronolith_sharesng_groups', array('perm_' . Horde_Perms::READ));
+        $this->addIndex('kronolith_sharesng_groups', array('perm_' . Horde_Perms::EDIT));
+        $this->addIndex('kronolith_sharesng_groups', array('perm_' . Horde_Perms::DELETE));
+        $this->addIndex('kronolith_sharesng_groups', array('perm_' . Kronolith::PERMS_DELEGATE));
+
+        $t = $this->createTable('kronolith_sharesng_users', array('primaryKey' => false));
+        $t->column('share_id', 'integer', array('null' => false));
+        $t->column('user_uid', 'string', array('limit' => 255));
+        $t->column('perm_' . Horde_Perms::SHOW, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::READ, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::EDIT, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Horde_Perms::DELETE, 'boolean', array('default' => false, 'null' => false));
+        $t->column('perm_' . Kronolith::PERMS_DELEGATE, 'boolean', array('default' => false, 'null' => false));
+        $t->end();
+
+        $this->addIndex('kronolith_sharesng_users', array('share_id'));
+        $this->addIndex('kronolith_sharesng_users', array('user_uid'));
+        $this->addIndex('kronolith_sharesng_users', array('perm_' . Horde_Perms::SHOW));
+        $this->addIndex('kronolith_sharesng_users', array('perm_' . Horde_Perms::READ));
+        $this->addIndex('kronolith_sharesng_users', array('perm_' . Horde_Perms::EDIT));
+        $this->addIndex('kronolith_sharesng_users', array('perm_' . Horde_Perms::DELETE));
+        $this->addIndex('kronolith_sharesng_users', array('perm_' . Kronolith::PERMS_DELEGATE));
+
+        $this->dataUp();
+    }
+
+    /**
+     * Downgrade
+     */
+    public function down()
+    {
+        $this->dropTable('kronolith_sharesng');
+        $this->dropTable('kronolith_sharesng_groups');
+        $this->dropTable('kronolith_sharesng_users');
+    }
+
+    public function dataUp()
+    {
+        $whos = array('creator', 'default', 'guest');
+        $perms = array(Horde_Perms::SHOW,
+                       Horde_Perms::READ,
+                       Horde_Perms::EDIT,
+                       Horde_Perms::DELETE,
+                       Kronolith::PERMS_DELEGATE);
+
+        $sql = 'INSERT INTO kronolith_sharesng (share_id, share_name, share_owner, share_flags, attribute_name, attribute_desc, attribute_color';
+        $count = 0;
+        foreach ($whos as $who) {
+            foreach ($perms as $perm) {
+                $sql .= ', perm_' . $who . '_' . $perm;
+                $count++;
+            }
+        }
+        $sql .= ') VALUES (?, ?, ?, ?, ?, ?, ?' . str_repeat(', ?', $count) . ')';
+
+        foreach ($this->select('SELECT * FROM kronolith_shares') as $share) {
+            $values = array($share['share_id'],
+                            $share['share_name'],
+                            $share['share_owner'],
+                            $share['share_flags'],
+                            $share['attribute_name'],
+                            $share['attribute_desc'],
+                            $share['attribute_color']);
+            foreach ($whos as $who) {
+                foreach ($perms as $perm) {
+                    $values[] = (bool)($share['perm_' . $who] & $perm);
+                }
+            }
+            $this->insert($sql, $values);
+        }
+
+        foreach (array('user', 'group') as $what) {
+            $sql = 'INSERT INTO kronolith_sharesng_' . $what . 's (share_id, ' . $what . '_uid';
+            $count = 0;
+            foreach ($perms as $perm) {
+                $sql .= ', perm_' . $perm;
+                $count++;
+            }
+            $sql .= ') VALUES (?, ?' . str_repeat(', ?', $count) . ')';
+
+            foreach ($this->select('SELECT * FROM kronolith_shares_' . $what . 's') as $share) {
+                $values = array($share['share_id'],
+                                $share[$what . '_uid']);
+                foreach ($perms as $perm) {
+                    $values[] = (bool)($share['perm'] & $perm);
+                }
+                $this->insert($sql, $values);
+            }
+        }
+    }
+}