From d601ab93beb9be2cc69d64fa04803ff3c3601c3a Mon Sep 17 00:00:00 2001
From: Romain LE DISEZ <romain.git@ledisez.net>
Date: Tue, 23 Jun 2009 10:12:09 +0200
Subject: Value stored in comment.state is not 15 char length. Use a VARCHAR
 instead of a CHAR. It improves compatibility with PgSQL.

---
 installer/install.sql | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'installer/install.sql')

diff --git a/installer/install.sql b/installer/install.sql
index 432aee64..b9c56043 100755
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -55,7 +55,7 @@ CREATE TABLE {comments} (
   `server_remote_addr` varchar(32) default NULL,
   `server_remote_host` varchar(64) default NULL,
   `server_remote_port` varchar(16) default NULL,
-  `state` char(15) default 'unpublished',
+  `state` varchar(15) default 'unpublished',
   `text` text,
   `updated` int(9) NOT NULL,
   PRIMARY KEY  (`id`)
-- 
cgit v1.2.3


From 719c59e0402464a0e2b14915f6d10218ff5d4729 Mon Sep 17 00:00:00 2001
From: Romain LE DISEZ <romain.git@ledisez.net>
Date: Sun, 19 Jul 2009 00:49:47 +0200
Subject: Use BOOLEAN instead of integer to describe the permissions :  - DENY
 = false  - ALLOW = true  - UNKNOW = null  (for intent only)  - INHERIT = null
 (for cache)

Upgrade is not included for now.
---
 installer/install.sql                           | 32 ++++++++++++-------------
 modules/gallery/helpers/access.php              | 31 +++++++++++++-----------
 modules/gallery/views/permissions_form.html.php |  2 +-
 modules/search/helpers/search.php               |  2 +-
 system/libraries/drivers/Database.php           |  4 ++--
 5 files changed, 37 insertions(+), 34 deletions(-)

(limited to 'installer/install.sql')

diff --git a/installer/install.sql b/installer/install.sql
index bda576d1..b17b5888 100755
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -4,12 +4,12 @@ DROP TABLE IF EXISTS {access_caches};
 CREATE TABLE {access_caches} (
   `id` int(9) NOT NULL auto_increment,
   `item_id` int(9) default NULL,
-  `view_full_1` smallint(6) NOT NULL default '0',
-  `edit_1` smallint(6) NOT NULL default '0',
-  `add_1` smallint(6) NOT NULL default '0',
-  `view_full_2` smallint(6) NOT NULL default '0',
-  `edit_2` smallint(6) NOT NULL default '0',
-  `add_2` smallint(6) NOT NULL default '0',
+  `view_full_1` binary(1) NOT NULL default false,
+  `edit_1` binary(1) NOT NULL default false,
+  `add_1` binary(1) NOT NULL default false,
+  `view_full_2` binary(1) NOT NULL default false,
+  `edit_2` binary(1) NOT NULL default false,
+  `add_2` binary(1) NOT NULL default false,
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
 /*!40101 SET character_set_client = @saved_cs_client */;
@@ -20,14 +20,14 @@ DROP TABLE IF EXISTS {access_intents};
 CREATE TABLE {access_intents} (
   `id` int(9) NOT NULL auto_increment,
   `item_id` int(9) default NULL,
-  `view_1` tinyint(1) default NULL,
-  `view_full_1` tinyint(1) default NULL,
-  `edit_1` tinyint(1) default NULL,
-  `add_1` tinyint(1) default NULL,
-  `view_2` tinyint(1) default NULL,
-  `view_full_2` tinyint(1) default NULL,
-  `edit_2` tinyint(1) default NULL,
-  `add_2` tinyint(1) default NULL,
+  `view_1` binary(1) default NULL,
+  `view_full_1` binary(1) default NULL,
+  `edit_1` binary(1) default NULL,
+  `add_1` binary(1) default NULL,
+  `view_2` binary(1) default NULL,
+  `view_full_2` binary(1) default NULL,
+  `edit_2` binary(1) default NULL,
+  `add_2` binary(1) default NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
 /*!40101 SET character_set_client = @saved_cs_client */;
@@ -164,8 +164,8 @@ CREATE TABLE {items} (
   `view_count` int(9) default '0',
   `weight` int(9) NOT NULL default '0',
   `width` int(9) default NULL,
-  `view_1` smallint(6) NOT NULL default '0',
-  `view_2` smallint(6) NOT NULL default '0',
+  `view_1` binary(1) default false,
+  `view_2` binary(1) default false,
   PRIMARY KEY  (`id`),
   KEY `parent_id` (`parent_id`),
   KEY `type` (`type`),
diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php
index 63324e5d..a468c43c 100644
--- a/modules/gallery/helpers/access.php
+++ b/modules/gallery/helpers/access.php
@@ -66,9 +66,10 @@
  *   the Access_Intent_Model
  */
 class access_Core {
-  const DENY      = 0;
-  const ALLOW     = 1;
-  const UNKNOWN   = 2;
+  const DENY      = false;
+  const ALLOW     = true;
+  const INHERIT   = null; // access_intent
+  const UNKNOWN   = null; // cache (access_cache, items)
 
   /**
    * Does the active user have this permission on this item?
@@ -129,7 +130,7 @@ class access_Core {
    * @param  Group_Model $group
    * @param  string      $perm_name
    * @param  Item_Model  $item
-   * @return integer     access::ALLOW, access::DENY or null for no intent
+   * @return boolean     access::ALLOW, access::DENY or access::INHERIT (null) for no intent
    */
   static function group_intent($group, $perm_name, $item) {
     $intent = model_cache::get("access_intent", $item->id, "item_id");
@@ -157,7 +158,7 @@ class access_Core {
       ->where("`right` >= $item->right")
       ->where("items.id <> $item->id")
       ->join("access_intents", "items.id", "access_intents.item_id")
-      ->where("access_intents.view_$group->id", 0)
+      ->where("access_intents.view_$group->id", access::DENY)
       ->orderby("level", "DESC")
       ->limit(1)
       ->find();
@@ -241,7 +242,7 @@ class access_Core {
     if ($item->id == 1) {
       throw new Exception("@todo CANT_RESET_ROOT_PERMISSION");
     }
-    self::_set($group, $perm_name, $item, null);
+    self::_set($group, $perm_name, $item, access::INHERIT);
   }
 
   /**
@@ -443,9 +444,10 @@ class access_Core {
     $db = Database::instance();
     $field = "{$perm_name}_{$group->id}";
     $cache_table = $perm_name == "view" ? "items" : "access_caches";
-    $db->query("ALTER TABLE {{$cache_table}} ADD `$field` SMALLINT NOT NULL DEFAULT 0");
-    $db->query("ALTER TABLE {access_intents} ADD `$field` BOOLEAN DEFAULT NULL");
-    $db->update("access_intents", array($field => 0), array("item_id" => 1));
+    $not_null = $cache_table == "items" ? "" : "NOT NULL";
+    $db->query("ALTER TABLE {{$cache_table}} ADD `$field` BINARY $not_null DEFAULT FALSE");
+    $db->query("ALTER TABLE {access_intents} ADD `$field` BINARY DEFAULT NULL");
+    $db->update("access_intents", array($field => access::DENY), array("item_id" => 1));
     model_cache::clear();
     ORM::factory("access_intent")->clear_cache();
   }
@@ -501,7 +503,7 @@ class access_Core {
       ->where("left >=", $item->left)
       ->where("right <=", $item->right)
       ->where("type", "album")
-      ->where("access_intents.$field IS NOT", null)
+      ->where("access_intents.$field IS NOT", self::INHERIT)
       ->orderby("level", "DESC")
       ->find_all();
     foreach ($query as $row) {
@@ -545,12 +547,12 @@ class access_Core {
     //
     // @todo To optimize this, we wouldn't need to propagate from the parent, we could just
     //       propagate from here with the parent's intent.
-    if ($access->$field === null) {
+    if ($access->$field === self::INHERIT) {
       $tmp_item = ORM::factory("item")
         ->join("access_intents", "items.id", "access_intents.item_id")
         ->where("left <", $item->left)
         ->where("right >", $item->right)
-        ->where("$field IS NOT", null)
+        ->where("$field IS NOT", self::UNKNOWN)
         ->orderby("left", "DESC")
         ->limit(1)
         ->find();
@@ -566,12 +568,13 @@ class access_Core {
       ->join("items", "items.id", "access_intents.item_id")
       ->where("left >=", $item->left)
       ->where("right <=", $item->right)
-      ->where("$field IS NOT", null)
+      ->where("$field IS NOT", self::INHERIT)
       ->orderby("level", "ASC")
       ->find_all();
     foreach  ($query as $row) {
+      $value = ($row->$field === access::ALLOW) ? "TRUE" : "FALSE";
       $db->query(
-        "UPDATE {access_caches} SET `$field` = {$row->$field} " .
+        "UPDATE {access_caches} SET `$field` = $value " .
         "WHERE `item_id` IN " .
         "  (SELECT `id` FROM {items} " .
         "  WHERE `left` >= $row->left " .
diff --git a/modules/gallery/views/permissions_form.html.php b/modules/gallery/views/permissions_form.html.php
index 0f60070a..ee5e3a24 100644
--- a/modules/gallery/views/permissions_form.html.php
+++ b/modules/gallery/views/permissions_form.html.php
@@ -26,7 +26,7 @@
             </a>
           </td>
         <? else: ?>
-          <? if ($intent === null): ?>
+          <? if ($intent === access::INHERIT): ?>
             <? if ($allowed): ?>
               <td class="gAllowed">
                 <a href="javascript:set('allow',<?= $group->id ?>,<?= $permission->id ?>,<?= $item->id ?>)"
diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php
index 34eaecbd..dd18babb 100644
--- a/modules/search/helpers/search.php
+++ b/modules/search/helpers/search.php
@@ -24,7 +24,7 @@ class search_Core {
 
     if (!user::active()->admin) {
       foreach (user::group_ids() as $id) {
-        $fields[] = "`view_$id` = " . access::ALLOW;
+        $fields[] = "`view_$id` = TRUE"; // access::ALLOW
       }
       $access_sql = "AND (" . join(" AND ", $fields) . ")";
     } else {
diff --git a/system/libraries/drivers/Database.php b/system/libraries/drivers/Database.php
index 807469f6..27f6ea8e 100644
--- a/system/libraries/drivers/Database.php
+++ b/system/libraries/drivers/Database.php
@@ -120,7 +120,7 @@ abstract class Database_Driver {
 					$key .= ' =';
 				}
 
-				$value = ($value == TRUE) ? ' 1' : ' 0';
+				$value = ($value == TRUE) ? ' TRUE' : ' FALSE';
 			}
 			else
 			{
@@ -310,7 +310,7 @@ abstract class Database_Driver {
 				$value = '\''.$this->escape_str($value).'\'';
 			break;
 			case 'boolean':
-				$value = (int) $value;
+				$value = ($value == TRUE) ? 'TRUE' : 'FALSE';
 			break;
 			case 'double':
 				// Convert to non-locale aware float to prevent possible commas
-- 
cgit v1.2.3


From 23bb6eb7e35637c8a2124216dbb6d3246ad3d702 Mon Sep 17 00:00:00 2001
From: Romain LE DISEZ <romain.git@ledisez.net>
Date: Sat, 25 Jul 2009 19:06:54 +0200
Subject: Rename columns that use reserved SQL words : items.left and
 items.right

---
 installer/install.sql                            | 72 +-------------------
 modules/gallery/helpers/access.php               | 40 +++++------
 modules/gallery/helpers/gallery_installer.php    | 16 +++--
 modules/gallery/libraries/ORM_MPTT.php           | 84 ++++++++++++------------
 modules/gallery/models/item.php                  | 10 +--
 modules/gallery/module.info                      |  2 +-
 modules/gallery/tests/Database_Test.php          |  8 +--
 modules/gallery/tests/Gallery_Installer_Test.php | 10 +--
 modules/gallery/tests/ORM_MPTT_Test.php          | 14 ++--
 modules/gallery/tests/Photo_Helper_Test.php      |  4 +-
 modules/notification/helpers/notification.php    |  4 +-
 11 files changed, 102 insertions(+), 162 deletions(-)

(limited to 'installer/install.sql')

diff --git a/installer/install.sql b/installer/install.sql
index 36ccaaff..fc5f967a 100755
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -1,6 +1,4 @@
 DROP TABLE IF EXISTS {access_caches};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {access_caches} (
   `id` int(9) NOT NULL auto_increment,
   `item_id` int(9) default NULL,
@@ -12,11 +10,8 @@ CREATE TABLE {access_caches} (
   `add_2` binary(1) NOT NULL default '0',
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {access_caches} VALUES (1,1,'1','0','0','1','0','0');
 DROP TABLE IF EXISTS {access_intents};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {access_intents} (
   `id` int(9) NOT NULL auto_increment,
   `item_id` int(9) default NULL,
@@ -30,11 +25,8 @@ CREATE TABLE {access_intents} (
   `add_2` binary(1) default NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {access_intents} VALUES (1,1,'1','1','0','0','1','1','0','0');
 DROP TABLE IF EXISTS {caches};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {caches} (
   `id` int(9) NOT NULL auto_increment,
   `key` varchar(255) NOT NULL,
@@ -44,10 +36,7 @@ CREATE TABLE {caches} (
   PRIMARY KEY  (`id`),
   KEY `tags` (`tags`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {comments};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {comments} (
   `author_id` int(9) default NULL,
   `created` int(9) NOT NULL,
@@ -73,10 +62,7 @@ CREATE TABLE {comments} (
   `updated` int(9) NOT NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {graphics_rules};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {graphics_rules} (
   `id` int(9) NOT NULL auto_increment,
   `active` tinyint(1) default '0',
@@ -87,12 +73,9 @@ CREATE TABLE {graphics_rules} (
   `target` varchar(32) NOT NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {graphics_rules} VALUES (1,1,'a:3:{s:5:\"width\";i:200;s:6:\"height\";i:200;s:6:\"master\";i:2;}','gallery','resize',100,'thumb');
 INSERT INTO {graphics_rules} VALUES (2,1,'a:3:{s:5:\"width\";i:640;s:6:\"height\";i:480;s:6:\"master\";i:2;}','gallery','resize',100,'resize');
 DROP TABLE IF EXISTS {groups};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {groups} (
   `id` int(9) NOT NULL auto_increment,
   `name` char(64) default NULL,
@@ -100,25 +83,19 @@ CREATE TABLE {groups} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {groups} VALUES (1,'Everybody',1);
 INSERT INTO {groups} VALUES (2,'Registered Users',1);
 DROP TABLE IF EXISTS {groups_users};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {groups_users} (
   `group_id` int(9) NOT NULL,
   `user_id` int(9) NOT NULL,
   PRIMARY KEY  (`group_id`,`user_id`),
   UNIQUE KEY `user_id` (`user_id`,`group_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {groups_users} VALUES (1,1);
 INSERT INTO {groups_users} VALUES (1,2);
 INSERT INTO {groups_users} VALUES (2,2);
 DROP TABLE IF EXISTS {incoming_translations};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {incoming_translations} (
   `id` int(9) NOT NULL auto_increment,
   `key` char(32) NOT NULL,
@@ -130,10 +107,7 @@ CREATE TABLE {incoming_translations} (
   UNIQUE KEY `key` (`key`,`locale`),
   KEY `locale_key` (`locale`,`key`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {items};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {items} (
   `id` int(9) NOT NULL auto_increment,
   `album_cover_item_id` int(9) default NULL,
@@ -141,7 +115,7 @@ CREATE TABLE {items} (
   `created` int(9) default NULL,
   `description` varchar(2048) default NULL,
   `height` int(9) default NULL,
-  `left` int(9) NOT NULL,
+  `left_ptr` int(9) NOT NULL,
   `level` int(9) NOT NULL,
   `mime_type` varchar(64) default NULL,
   `name` varchar(255) default NULL,
@@ -152,7 +126,7 @@ CREATE TABLE {items} (
   `resize_dirty` tinyint(1) default '1',
   `resize_height` int(9) default NULL,
   `resize_width` int(9) default NULL,
-  `right` int(9) NOT NULL,
+  `right_ptr` int(9) NOT NULL,
   `sort_column` varchar(64) default NULL,
   `sort_order` char(4) default 'ASC',
   `thumb_dirty` tinyint(1) default '1',
@@ -171,11 +145,8 @@ CREATE TABLE {items} (
   KEY `type` (`type`),
   KEY `random` (`rand_key`)
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {items} VALUES (1,NULL,NULL,UNIX_TIMESTAMP(),'',NULL,1,1,NULL,NULL,NULL,0,NULL,'',1,NULL,NULL,2,'weight','ASC',1,NULL,NULL,'Gallery','album',UNIX_TIMESTAMP(),0,1,NULL,'1','1');
 DROP TABLE IF EXISTS {items_tags};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {items_tags} (
   `id` int(9) NOT NULL auto_increment,
   `item_id` int(9) NOT NULL,
@@ -184,10 +155,7 @@ CREATE TABLE {items_tags} (
   KEY `tag_id` (`tag_id`,`id`),
   KEY `item_id` (`item_id`,`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {logs};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {logs} (
   `id` int(9) NOT NULL auto_increment,
   `category` varchar(64) default NULL,
@@ -200,10 +168,7 @@ CREATE TABLE {logs} (
   `user_id` int(9) default '0',
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {messages};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {messages} (
   `id` int(9) NOT NULL auto_increment,
   `key` varchar(255) default NULL,
@@ -212,10 +177,7 @@ CREATE TABLE {messages} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `key` (`key`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {modules};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {modules} (
   `id` int(9) NOT NULL auto_increment,
   `active` tinyint(1) default '0',
@@ -224,8 +186,7 @@ CREATE TABLE {modules} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
-INSERT INTO {modules} VALUES (1,1,'gallery',7);
+INSERT INTO {modules} VALUES (1,1,'gallery',9);
 INSERT INTO {modules} VALUES (2,1,'user',1);
 INSERT INTO {modules} VALUES (3,1,'comment',2);
 INSERT INTO {modules} VALUES (4,1,'organize',1);
@@ -235,8 +196,6 @@ INSERT INTO {modules} VALUES (7,1,'search',1);
 INSERT INTO {modules} VALUES (8,1,'slideshow',1);
 INSERT INTO {modules} VALUES (9,1,'tag',1);
 DROP TABLE IF EXISTS {outgoing_translations};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {outgoing_translations} (
   `id` int(9) NOT NULL auto_increment,
   `base_revision` int(9) default NULL,
@@ -248,10 +207,7 @@ CREATE TABLE {outgoing_translations} (
   UNIQUE KEY `key` (`key`,`locale`),
   KEY `locale_key` (`locale`,`key`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {permissions};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {permissions} (
   `id` int(9) NOT NULL auto_increment,
   `display_name` varchar(64) default NULL,
@@ -259,14 +215,11 @@ CREATE TABLE {permissions} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {permissions} VALUES (1,'View','view');
 INSERT INTO {permissions} VALUES (2,'View Full Size','view_full');
 INSERT INTO {permissions} VALUES (3,'Edit','edit');
 INSERT INTO {permissions} VALUES (4,'Add','add');
 DROP TABLE IF EXISTS {search_records};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {search_records} (
   `id` int(9) NOT NULL auto_increment,
   `item_id` int(9) default NULL,
@@ -276,21 +229,15 @@ CREATE TABLE {search_records} (
   KEY `item_id` (`item_id`),
   FULLTEXT KEY `data` (`data`)
 ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {search_records} VALUES (1,1,0,'   Gallery');
 DROP TABLE IF EXISTS {sessions};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {sessions} (
   `session_id` varchar(127) NOT NULL,
   `data` text NOT NULL,
   `last_activity` int(10) unsigned NOT NULL,
   PRIMARY KEY  (`session_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {tags};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {tags} (
   `id` int(9) NOT NULL auto_increment,
   `name` varchar(64) NOT NULL,
@@ -298,10 +245,7 @@ CREATE TABLE {tags} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {tasks};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {tasks} (
   `id` int(9) NOT NULL auto_increment,
   `callback` varchar(128) default NULL,
@@ -316,10 +260,7 @@ CREATE TABLE {tasks} (
   PRIMARY KEY  (`id`),
   KEY `owner_id` (`owner_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {themes};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {themes} (
   `id` int(9) NOT NULL auto_increment,
   `name` varchar(64) default NULL,
@@ -327,12 +268,9 @@ CREATE TABLE {themes} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {themes} VALUES (1,'default',1);
 INSERT INTO {themes} VALUES (2,'admin_default',1);
 DROP TABLE IF EXISTS {users};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {users} (
   `id` int(9) NOT NULL auto_increment,
   `name` varchar(32) NOT NULL,
@@ -350,12 +288,9 @@ CREATE TABLE {users} (
   UNIQUE KEY `name` (`name`),
   UNIQUE KEY `hash` (`hash`)
 ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {users} VALUES (1,'guest','Guest User','',0,0,NULL,0,1,NULL,NULL,NULL);
 INSERT INTO {users} VALUES (2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL,NULL,NULL);
 DROP TABLE IF EXISTS {vars};
-SET @saved_cs_client     = @@character_set_client;
-SET character_set_client = utf8;
 CREATE TABLE {vars} (
   `id` int(9) NOT NULL auto_increment,
   `module_name` varchar(64) NOT NULL,
@@ -364,7 +299,6 @@ CREATE TABLE {vars} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `module_name` (`module_name`,`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8;
-SET character_set_client = @saved_cs_client;
 INSERT INTO {vars} VALUES (1,'gallery','active_site_theme','default');
 INSERT INTO {vars} VALUES (2,'gallery','active_admin_theme','admin_default');
 INSERT INTO {vars} VALUES (3,'gallery','page_size','9');
diff --git a/modules/gallery/helpers/access.php b/modules/gallery/helpers/access.php
index c84527f4..949aea84 100644
--- a/modules/gallery/helpers/access.php
+++ b/modules/gallery/helpers/access.php
@@ -166,8 +166,8 @@ class access_Core {
     // For view permissions, if any parent is self::DENY, then those parents lock this one.
     // Return
     $lock = ORM::factory("item")
-      ->where("`left` <= $item->left")
-      ->where("`right` >= $item->right")
+      ->where("`left_ptr` <= $item->left_ptr")
+      ->where("`right_ptr` >= $item->right_ptr")
       ->where("items.id <> $item->id")
       ->join("access_intents", "items.id", "access_intents.item_id")
       ->where("access_intents.view_$group->id", self::DENY)
@@ -490,11 +490,11 @@ class access_Core {
     // item, then its safe to propagate from here.
     if ($access->$field !== self::DENY) {
       $tmp_item = ORM::factory("item")
-        ->where("left <", $item->left)
-        ->where("right >", $item->right)
+        ->where("left_ptr <", $item->left_ptr)
+        ->where("right_ptr >", $item->right_ptr)
         ->join("access_intents", "access_intents.item_id", "items.id")
         ->where("access_intents.$field", self::DENY)
-        ->orderby("left", "DESC")
+        ->orderby("left_ptr", "DESC")
         ->limit(1)
         ->find();
       if ($tmp_item->loaded) {
@@ -507,13 +507,13 @@ class access_Core {
     // them according the rule above.  So mark every permission below this level as UNKNOWN so
     // that we can tell which permissions have been changed, and which ones need to be updated.
     $db->update("items", array($field => self::UNKNOWN),
-                array("left >=" => $item->left, "right <=" => $item->right));
+                array("left_ptr >=" => $item->left_ptr, "right_ptr <=" => $item->right_ptr));
 
     $query = ORM::factory("access_intent")
-      ->select(array("access_intents.$field", "items.left", "items.right", "items.id"))
+      ->select(array("access_intents.$field", "items.left_ptr", "items.right_ptr", "items.id"))
       ->join("items", "items.id", "access_intents.item_id")
-      ->where("left >=", $item->left)
-      ->where("right <=", $item->right)
+      ->where("left_ptr >=", $item->left_ptr)
+      ->where("right_ptr <=", $item->right_ptr)
       ->where("type", "album")
       ->where("access_intents.$field IS NOT", self::INHERIT)
       ->orderby("level", "DESC")
@@ -522,11 +522,11 @@ class access_Core {
       if ($row->$field == self::ALLOW) {
         // Propagate ALLOW for any row that is still UNKNOWN.
         $db->update("items", array($field => $row->$field),
-          array($field => self::UNKNOWN, "left >=" => $row->left, "right <=" => $row->right));
+          array($field => self::UNKNOWN, "left_ptr >=" => $row->left_ptr, "right_ptr <=" => $row->right_ptr));
       } else if ($row->$field == self::DENY) {
         // DENY overwrites everything below it
         $db->update("items", array($field => $row->$field),
-                    array("left >=" => $row->left, "right <=" => $row->right));
+                    array("left_ptr >=" => $row->left_ptr, "right_ptr <=" => $row->right_ptr));
       }
     }
 
@@ -534,7 +534,7 @@ class access_Core {
     // DENY parent in the hierarchy to propagate from.  So we'll still have a UNKNOWN values in
     // the hierarchy, and all of those are safe to change to ALLOW.
     $db->update("items", array($field => self::ALLOW),
-                array($field => self::UNKNOWN, "left >=" => $item->left, "right <=" => $item->right));
+                array($field => self::UNKNOWN, "left_ptr >=" => $item->left_ptr, "right_ptr <=" => $item->right_ptr));
   }
 
   /**
@@ -562,10 +562,10 @@ class access_Core {
     if ($access->$field === self::INHERIT) {
       $tmp_item = ORM::factory("item")
         ->join("access_intents", "items.id", "access_intents.item_id")
-        ->where("left <", $item->left)
-        ->where("right >", $item->right)
+        ->where("left_ptr <", $item->left_ptr)
+        ->where("right_ptr >", $item->right_ptr)
         ->where("$field IS NOT", self::UNKNOWN)
-        ->orderby("left", "DESC")
+        ->orderby("left_ptr", "DESC")
         ->limit(1)
         ->find();
       if ($tmp_item->loaded) {
@@ -576,10 +576,10 @@ class access_Core {
     // With non-view permissions, each level can override any permissions that came above it
     // so start at the top and work downwards, overlaying permissions as we go.
     $query = ORM::factory("access_intent")
-      ->select(array("access_intents.$field", "items.left", "items.right"))
+      ->select(array("access_intents.$field", "items.left_ptr", "items.right_ptr"))
       ->join("items", "items.id", "access_intents.item_id")
-      ->where("left >=", $item->left)
-      ->where("right <=", $item->right)
+      ->where("left_ptr >=", $item->left_ptr)
+      ->where("right_ptr <=", $item->right_ptr)
       ->where("$field IS NOT", self::INHERIT)
       ->orderby("level", "ASC")
       ->find_all();
@@ -589,8 +589,8 @@ class access_Core {
         "UPDATE {access_caches} SET `$field` = $value " .
         "WHERE `item_id` IN " .
         "  (SELECT `id` FROM {items} " .
-        "  WHERE `left` >= $row->left " .
-        "  AND `right` <= $row->right)");
+        "  WHERE `left_ptr` >= $row->left_ptr " .
+        "  AND `right_ptr` <= $row->right_ptr)");
     }
   }
 
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index db13307f..760bec31 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -72,7 +72,7 @@ class gallery_installer {
                  `created` int(9) default NULL,
                  `description` varchar(2048) default NULL,
                  `height` int(9) default NULL,
-                 `left` int(9) NOT NULL,
+                 `left_ptr` int(9) NOT NULL,
                  `level` int(9) NOT NULL,
                  `mime_type` varchar(64) default NULL,
                  `name` varchar(255) default NULL,
@@ -83,7 +83,7 @@ class gallery_installer {
                  `resize_dirty` boolean default 1,
                  `resize_height` int(9) default NULL,
                  `resize_width` int(9) default NULL,
-                 `right` int(9) NOT NULL,
+                 `right_ptr` int(9) NOT NULL,
                  `sort_column` varchar(64) default NULL,
                  `sort_order` char(4) default 'ASC',
                  `thumb_dirty` boolean default 1,
@@ -204,8 +204,8 @@ class gallery_installer {
     $root->type = "album";
     $root->title = "Gallery";
     $root->description = "";
-    $root->left = 1;
-    $root->right = 2;
+    $root->left_ptr = 1;
+    $root->right_ptr = 2;
     $root->parent_id = 0;
     $root->level = 1;
     $root->thumb_dirty = 1;
@@ -258,7 +258,7 @@ class gallery_installer {
     module::set_var("gallery", "show_credits", 1);
     // @todo this string needs to be picked up by l10n_scanner
     module::set_var("gallery", "credits", "Powered by <a href=\"%url\">Gallery %version</a>");
-    module::set_version("gallery", 7);
+    module::set_version("gallery", 9);
   }
 
   static function upgrade($version) {
@@ -323,6 +323,12 @@ class gallery_installer {
       }
       module::set_version("gallery", $version = 8);
     }
+
+    if ($version == 8) {
+      $db->query("ALTER TABLE {items} CHANGE COLUMN `left`  `left_ptr`  INT(9) NOT NULL;");
+      $db->query("ALTER TABLE {items} CHANGE COLUMN `right` `right_ptr` INT(9) NOT NULL;");
+      module::set_version("gallery", $version = 9);
+    }
   }
 
   static function uninstall() {
diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php
index e371f159..1917d738 100644
--- a/modules/gallery/libraries/ORM_MPTT.php
+++ b/modules/gallery/libraries/ORM_MPTT.php
@@ -52,14 +52,14 @@ class ORM_MPTT_Core extends ORM {
     try {
       // Make a hole in the parent for this new item
       $this->db->query(
-        "UPDATE {{$this->table_name}} SET `left` = `left` + 2 WHERE `left` >= {$parent->right}");
+        "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + 2 WHERE `left_ptr` >= {$parent->right_ptr}");
       $this->db->query(
-        "UPDATE {{$this->table_name}} SET `right` = `right` + 2 WHERE `right` >= {$parent->right}");
-      $parent->right += 2;
+        "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + 2 WHERE `right_ptr` >= {$parent->right_ptr}");
+      $parent->right_ptr += 2;
 
       // Insert this item into the hole
-      $this->left = $parent->right - 2;
-      $this->right = $parent->right - 1;
+      $this->left_ptr = $parent->right_ptr - 2;
+      $this->right_ptr = $parent->right_ptr - 1;
       $this->parent_id = $parent->id;
       $this->level = $parent->level + 1;
       $this->save();
@@ -81,7 +81,7 @@ class ORM_MPTT_Core extends ORM {
     if ($children) {
       foreach ($this->children() as $item) {
         // Deleting children affects the MPTT tree, so we have to reload each child before we
-        // delete it so that we have current left/right pointers.  This is inefficient.
+        // delete it so that we have current left_ptr/right_ptr pointers.  This is inefficient.
         // @todo load each child once, not twice.
         $item->reload()->delete();
       }
@@ -93,9 +93,9 @@ class ORM_MPTT_Core extends ORM {
     $this->lock();
     try {
       $this->db->query(
-        "UPDATE {{$this->table_name}} SET `left` = `left` - 2 WHERE `left` > {$this->right}");
+        "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - 2 WHERE `left_ptr` > {$this->right_ptr}");
       $this->db->query(
-        "UPDATE {{$this->table_name}} SET `right` = `right` - 2 WHERE `right` > {$this->right}");
+        "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - 2 WHERE `right_ptr` > {$this->right_ptr}");
     } catch (Exception $e) {
       $this->unlock();
       throw $e;
@@ -111,7 +111,7 @@ class ORM_MPTT_Core extends ORM {
    * @return boolean
    */
   function is_descendant($target) {
-    return ($this->left <= $target->left && $this->right >= $target->right);
+    return ($this->left_ptr <= $target->left_ptr && $this->right_ptr >= $target->right_ptr);
   }
 
   /**
@@ -133,10 +133,10 @@ class ORM_MPTT_Core extends ORM {
    */
   function parents() {
     return $this
-      ->where("`left` <= {$this->left}")
-      ->where("`right` >= {$this->right}")
+      ->where("`left_ptr` <= {$this->left_ptr}")
+      ->where("`right_ptr` >= {$this->right_ptr}")
       ->where("id <> {$this->id}")
-      ->orderby("left", "ASC")
+      ->orderby("left_ptr", "ASC")
       ->find_all();
   }
 
@@ -181,8 +181,8 @@ class ORM_MPTT_Core extends ORM {
    * @return object ORM_Iterator
    */
   function descendants($limit=null, $offset=0, $type=null, $orderby=null) {
-    $this->where("left >", $this->left)
-      ->where("right <=", $this->right);
+    $this->where("left_ptr >", $this->left_ptr)
+      ->where("right_ptr <=", $this->right_ptr);
     if ($type) {
       $this->where("type", $type);
     }
@@ -203,8 +203,8 @@ class ORM_MPTT_Core extends ORM {
    * @return   integer  child count
    */
   function descendants_count($type=null) {
-    $this->where("left >", $this->left)
-      ->where("right <=", $this->right);
+    $this->where("left_ptr >", $this->left_ptr)
+      ->where("right_ptr <=", $this->right_ptr);
     if ($type) {
       $this->where("type", $type);
     }
@@ -219,16 +219,16 @@ class ORM_MPTT_Core extends ORM {
    * @return  ORM_MTPP
    */
   function move_to($target) {
-    if ($this->left <= $target->left &&
-        $this->right >= $target->right) {
+    if ($this->left_ptr <= $target->left_ptr &&
+        $this->right_ptr >= $target->right_ptr) {
       throw new Exception("@todo INVALID_TARGET can't move item inside itself");
     }
 
-    $number_to_move = (int)(($this->right - $this->left) / 2 + 1);
+    $number_to_move = (int)(($this->right_ptr - $this->left_ptr) / 2 + 1);
     $size_of_hole = $number_to_move * 2;
-    $original_left = $this->left;
-    $original_right = $this->right;
-    $target_right = $target->right;
+    $original_left_ptr = $this->left_ptr;
+    $original_right_ptr = $this->right_ptr;
+    $target_right_ptr = $target->right_ptr;
     $level_delta = ($target->level + 1) - $this->level;
 
     $this->lock();
@@ -237,45 +237,45 @@ class ORM_MPTT_Core extends ORM {
         // Update the levels for the to-be-moved items
         $this->db->query(
           "UPDATE {{$this->table_name}} SET `level` = `level` + $level_delta" .
-          " WHERE `left` >= $original_left AND `right` <= $original_right");
+          " WHERE `left_ptr` >= $original_left_ptr AND `right_ptr` <= $original_right_ptr");
       }
 
       // Make a hole in the target for the move
       $target->db->query(
-        "UPDATE {{$this->table_name}} SET `left` = `left` + $size_of_hole" .
-        " WHERE `left` >= $target_right");
+        "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` + $size_of_hole" .
+        " WHERE `left_ptr` >= $target_right_ptr");
       $target->db->query(
-        "UPDATE {{$this->table_name}} SET `right` = `right` + $size_of_hole" .
-        " WHERE `right` >= $target_right");
+        "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` + $size_of_hole" .
+        " WHERE `right_ptr` >= $target_right_ptr");
 
       // Change the parent.
       $this->db->query(
         "UPDATE {{$this->table_name}} SET `parent_id` = {$target->id}" .
         " WHERE `id` = {$this->id}");
 
-      // If the source is to the right of the target then we just adjusted its left and right above.
-      $left = $original_left;
-      $right = $original_right;
-      if ($original_left > $target_right) {
-        $left += $size_of_hole;
-        $right += $size_of_hole;
+      // If the source is to the right of the target then we just adjusted its left_ptr and right_ptr above.
+      $left_ptr = $original_left_ptr;
+      $right_ptr = $original_right_ptr;
+      if ($original_left_ptr > $target_right_ptr) {
+        $left_ptr += $size_of_hole;
+        $right_ptr += $size_of_hole;
       }
 
-      $new_offset = $target->right - $left;
+      $new_offset = $target->right_ptr - $left_ptr;
       $this->db->query(
         "UPDATE {{$this->table_name}}" .
-        "   SET `left` = `left` + $new_offset," .
-        "       `right` = `right` + $new_offset" .
-      " WHERE `left` >= $left" .
-        "   AND `right` <= $right");
+        "   SET `left_ptr` = `left_ptr` + $new_offset," .
+        "       `right_ptr` = `right_ptr` + $new_offset" .
+      " WHERE `left_ptr` >= $left_ptr" .
+        "   AND `right_ptr` <= $right_ptr");
 
       // Close the hole in the source's parent after the move
       $this->db->query(
-        "UPDATE {{$this->table_name}} SET `left` = `left` - $size_of_hole" .
-        " WHERE `left` > $right");
+        "UPDATE {{$this->table_name}} SET `left_ptr` = `left_ptr` - $size_of_hole" .
+        " WHERE `left_ptr` > $right_ptr");
       $this->db->query(
-        "UPDATE {{$this->table_name}} SET `right` = `right` - $size_of_hole" .
-        " WHERE `right` > $right");
+        "UPDATE {{$this->table_name}} SET `right_ptr` = `right_ptr` - $size_of_hole" .
+        " WHERE `right_ptr` > $right_ptr");
     } catch (Exception $e) {
       $this->unlock();
       throw $e;
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 58ac8f18..d9dd88f5 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -150,7 +150,7 @@ class Item_Model extends ORM_MPTT {
       Database::instance()
         ->update("items",
                  array("relative_path_cache" => null),
-                 array("left >" => $this->left, "right <" => $this->right));
+                 array("left_ptr >" => $this->left_ptr, "right_ptr <" => $this->right_ptr));
     } else {
       @rename($original_resize_path, $this->resize_path());
       @rename($original_thumb_path, $this->thumb_path());
@@ -186,7 +186,7 @@ class Item_Model extends ORM_MPTT {
       Database::instance()
         ->update("items",
                  array("relative_path_cache" => null),
-                 array("left >" => $this->left, "right <" => $this->right));
+                 array("left_ptr >" => $this->left_ptr, "right_ptr <" => $this->right_ptr));
     }
 
     return $this;
@@ -302,10 +302,10 @@ class Item_Model extends ORM_MPTT {
       foreach (Database::instance()
                ->select("name")
                ->from("items")
-               ->where("left <=", $this->left)
-               ->where("right >=", $this->right)
+               ->where("left_ptr <=", $this->left_ptr)
+               ->where("right_ptr >=", $this->right_ptr)
                ->where("id <>", 1)
-               ->orderby("left", "ASC")
+               ->orderby("left_ptr", "ASC")
                ->get() as $row) {
         $paths[] = $row->name;
       }
diff --git a/modules/gallery/module.info b/modules/gallery/module.info
index ba367878..c5a9d25d 100644
--- a/modules/gallery/module.info
+++ b/modules/gallery/module.info
@@ -1,3 +1,3 @@
 name = "Gallery 3"
 description = "Gallery core application"
-version = 8
+version = 9
diff --git a/modules/gallery/tests/Database_Test.php b/modules/gallery/tests/Database_Test.php
index bd3d2f53..d83212ad 100644
--- a/modules/gallery/tests/Database_Test.php
+++ b/modules/gallery/tests/Database_Test.php
@@ -103,15 +103,15 @@ class Database_Test extends Unit_Test_Case {
     $sql = "UPDATE {test_tables} SET `name` = '{test string}' " .
         "WHERE `item_id` IN " .
         "  (SELECT `id` FROM {items} " .
-        "  WHERE `left` >= 1 " .
-        "  AND `right` <= 6)";
+        "  WHERE `left_ptr` >= 1 " .
+        "  AND `right_ptr` <= 6)";
     $sql = $db->add_table_prefixes($sql);
 
     $expected = "UPDATE g3test_test_tables SET `name` = '{test string}' " .
         "WHERE `item_id` IN " .
         "  (SELECT `id` FROM g3test_items " .
-        "  WHERE `left` >= 1 " .
-        "  AND `right` <= 6)";
+        "  WHERE `left_ptr` >= 1 " .
+        "  AND `right_ptr` <= 6)";
 
     $this->assert_same($expected, $sql);
   }
diff --git a/modules/gallery/tests/Gallery_Installer_Test.php b/modules/gallery/tests/Gallery_Installer_Test.php
index 27157d6e..36ced2bb 100644
--- a/modules/gallery/tests/Gallery_Installer_Test.php
+++ b/modules/gallery/tests/Gallery_Installer_Test.php
@@ -34,13 +34,13 @@ class Gallery_Installer_Test extends Unit_Test_Case {
   }
 
   public function install_creates_root_item_test() {
-    $max_right = ORM::factory("item")
-      ->select("MAX(`right`) AS `right`")
-      ->find()->right;
+    $max_right_ptr = ORM::factory("item")
+      ->select("MAX(`right_ptr`) AS `right_ptr`")
+      ->find()->right_ptr;
     $root = ORM::factory('item')->find(1);
     $this->assert_equal("Gallery", $root->title);
-    $this->assert_equal(1, $root->left);
-    $this->assert_equal($max_right, $root->right);
+    $this->assert_equal(1, $root->left_ptr);
+    $this->assert_equal($max_right_ptr, $root->right_ptr);
     $this->assert_equal(null, $root->parent_id);
     $this->assert_equal(1, $root->level);
   }
diff --git a/modules/gallery/tests/ORM_MPTT_Test.php b/modules/gallery/tests/ORM_MPTT_Test.php
index 200c8a74..943810c3 100644
--- a/modules/gallery/tests/ORM_MPTT_Test.php
+++ b/modules/gallery/tests/ORM_MPTT_Test.php
@@ -33,8 +33,8 @@ class ORM_MPTT_Test extends Unit_Test_Case {
     $album->sort_order = "ASC";
     $album->add_to_parent($root);
 
-    $this->assert_equal($album->parent()->right - 2, $album->left);
-    $this->assert_equal($album->parent()->right - 1, $album->right);
+    $this->assert_equal($album->parent()->right_ptr - 2, $album->left_ptr);
+    $this->assert_equal($album->parent()->right_ptr - 1, $album->right_ptr);
     $this->assert_equal($album->parent()->level + 1, $album->level);
     $this->assert_equal($album->parent()->id, $album->parent_id);
   }
@@ -48,10 +48,10 @@ class ORM_MPTT_Test extends Unit_Test_Case {
     $album1_1_2 = self::create_item_and_add_to_parent($album1_1);
 
     $album1->reload();
-    $this->assert_equal(9, $album1->right - $album1->left);
+    $this->assert_equal(9, $album1->right_ptr - $album1->left_ptr);
 
     $album1_1->reload();
-    $this->assert_equal(5, $album1_1->right - $album1_1->left);
+    $this->assert_equal(5, $album1_1->right_ptr - $album1_1->left_ptr);
   }
 
   public function delete_hierarchy_test() {
@@ -66,7 +66,7 @@ class ORM_MPTT_Test extends Unit_Test_Case {
     $album1->reload();
 
     // Now album1 contains only album1_2
-    $this->assert_equal(3, $album1->right - $album1->left);
+    $this->assert_equal(3, $album1->right_ptr - $album1->left_ptr);
   }
 
   public function move_to_test() {
@@ -85,8 +85,8 @@ class ORM_MPTT_Test extends Unit_Test_Case {
     $album1_1->reload();
     $album1_2->reload();
 
-    $this->assert_equal(3, $album1_1->right - $album1_1->left);
-    $this->assert_equal(3, $album1_2->right - $album1_2->left);
+    $this->assert_equal(3, $album1_1->right_ptr - $album1_1->left_ptr);
+    $this->assert_equal(3, $album1_2->right_ptr - $album1_2->left_ptr);
 
     $this->assert_equal(
       array($album1_1_2->id => "move_to_test_1_1_2"),
diff --git a/modules/gallery/tests/Photo_Helper_Test.php b/modules/gallery/tests/Photo_Helper_Test.php
index cc1f20da..c0641ef4 100644
--- a/modules/gallery/tests/Photo_Helper_Test.php
+++ b/modules/gallery/tests/Photo_Helper_Test.php
@@ -43,8 +43,8 @@ class Photo_Helper_Test extends Unit_Test_Case {
     $this->assert_equal($image_info[0], $photo->width);
     $this->assert_equal($image_info[1], $photo->height);
 
-    $this->assert_equal($photo->parent()->right - 2, $photo->left);
-    $this->assert_equal($photo->parent()->right - 1, $photo->right);
+    $this->assert_equal($photo->parent()->right_ptr - 2, $photo->left_ptr);
+    $this->assert_equal($photo->parent()->right_ptr - 1, $photo->right_ptr);
   }
 
   public function create_conflicting_photo_test() {
diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php
index d91a37e8..92c40d4f 100644
--- a/modules/notification/helpers/notification.php
+++ b/modules/notification/helpers/notification.php
@@ -73,8 +73,8 @@ class notification {
       ->join("subscriptions", "users.id", "subscriptions.user_id")
       ->join("items", "subscriptions.item_id", "items.id")
       ->where("email IS NOT", null)
-      ->where("items.left <=", $item->left)
-      ->where("items.right >", $item->right)
+      ->where("items.left_ptr <=", $item->left_ptr)
+      ->where("items.right_ptr >", $item->right_ptr)
       ->find_all();
 
     $subscribers = array();
-- 
cgit v1.2.3


From 482e223b602d60eec424081d0328cde66d28a758 Mon Sep 17 00:00:00 2001
From: Andy Staudacher <andy.st@gmail.com>
Date: Sun, 26 Jul 2009 23:58:46 -0700
Subject: Updating install.sql with the packaging script, basically re-adding
 the charset (utf8) expressions that were removed by merging in rledisez's
 left/right -> left_ptr/right_ptr changes.

---
 installer/install.sql | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

(limited to 'installer/install.sql')

diff --git a/installer/install.sql b/installer/install.sql
index fc5f967a..0f8a2410 100755
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -1,4 +1,6 @@
 DROP TABLE IF EXISTS {access_caches};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {access_caches} (
   `id` int(9) NOT NULL auto_increment,
   `item_id` int(9) default NULL,
@@ -10,8 +12,11 @@ CREATE TABLE {access_caches} (
   `add_2` binary(1) NOT NULL default '0',
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {access_caches} VALUES (1,1,'1','0','0','1','0','0');
 DROP TABLE IF EXISTS {access_intents};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {access_intents} (
   `id` int(9) NOT NULL auto_increment,
   `item_id` int(9) default NULL,
@@ -25,8 +30,11 @@ CREATE TABLE {access_intents} (
   `add_2` binary(1) default NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {access_intents} VALUES (1,1,'1','1','0','0','1','1','0','0');
 DROP TABLE IF EXISTS {caches};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {caches} (
   `id` int(9) NOT NULL auto_increment,
   `key` varchar(255) NOT NULL,
@@ -36,7 +44,10 @@ CREATE TABLE {caches} (
   PRIMARY KEY  (`id`),
   KEY `tags` (`tags`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {comments};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {comments} (
   `author_id` int(9) default NULL,
   `created` int(9) NOT NULL,
@@ -62,7 +73,10 @@ CREATE TABLE {comments} (
   `updated` int(9) NOT NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {graphics_rules};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {graphics_rules} (
   `id` int(9) NOT NULL auto_increment,
   `active` tinyint(1) default '0',
@@ -73,9 +87,12 @@ CREATE TABLE {graphics_rules} (
   `target` varchar(32) NOT NULL,
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {graphics_rules} VALUES (1,1,'a:3:{s:5:\"width\";i:200;s:6:\"height\";i:200;s:6:\"master\";i:2;}','gallery','resize',100,'thumb');
 INSERT INTO {graphics_rules} VALUES (2,1,'a:3:{s:5:\"width\";i:640;s:6:\"height\";i:480;s:6:\"master\";i:2;}','gallery','resize',100,'resize');
 DROP TABLE IF EXISTS {groups};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {groups} (
   `id` int(9) NOT NULL auto_increment,
   `name` char(64) default NULL,
@@ -83,19 +100,25 @@ CREATE TABLE {groups} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {groups} VALUES (1,'Everybody',1);
 INSERT INTO {groups} VALUES (2,'Registered Users',1);
 DROP TABLE IF EXISTS {groups_users};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {groups_users} (
   `group_id` int(9) NOT NULL,
   `user_id` int(9) NOT NULL,
   PRIMARY KEY  (`group_id`,`user_id`),
   UNIQUE KEY `user_id` (`user_id`,`group_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {groups_users} VALUES (1,1);
 INSERT INTO {groups_users} VALUES (1,2);
 INSERT INTO {groups_users} VALUES (2,2);
 DROP TABLE IF EXISTS {incoming_translations};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {incoming_translations} (
   `id` int(9) NOT NULL auto_increment,
   `key` char(32) NOT NULL,
@@ -107,7 +130,10 @@ CREATE TABLE {incoming_translations} (
   UNIQUE KEY `key` (`key`,`locale`),
   KEY `locale_key` (`locale`,`key`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {items};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {items} (
   `id` int(9) NOT NULL auto_increment,
   `album_cover_item_id` int(9) default NULL,
@@ -145,8 +171,11 @@ CREATE TABLE {items} (
   KEY `type` (`type`),
   KEY `random` (`rand_key`)
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {items} VALUES (1,NULL,NULL,UNIX_TIMESTAMP(),'',NULL,1,1,NULL,NULL,NULL,0,NULL,'',1,NULL,NULL,2,'weight','ASC',1,NULL,NULL,'Gallery','album',UNIX_TIMESTAMP(),0,1,NULL,'1','1');
 DROP TABLE IF EXISTS {items_tags};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {items_tags} (
   `id` int(9) NOT NULL auto_increment,
   `item_id` int(9) NOT NULL,
@@ -155,7 +184,10 @@ CREATE TABLE {items_tags} (
   KEY `tag_id` (`tag_id`,`id`),
   KEY `item_id` (`item_id`,`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {logs};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {logs} (
   `id` int(9) NOT NULL auto_increment,
   `category` varchar(64) default NULL,
@@ -168,7 +200,10 @@ CREATE TABLE {logs} (
   `user_id` int(9) default '0',
   PRIMARY KEY  (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {messages};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {messages} (
   `id` int(9) NOT NULL auto_increment,
   `key` varchar(255) default NULL,
@@ -177,7 +212,10 @@ CREATE TABLE {messages} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `key` (`key`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {modules};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {modules} (
   `id` int(9) NOT NULL auto_increment,
   `active` tinyint(1) default '0',
@@ -186,6 +224,7 @@ CREATE TABLE {modules} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {modules} VALUES (1,1,'gallery',9);
 INSERT INTO {modules} VALUES (2,1,'user',1);
 INSERT INTO {modules} VALUES (3,1,'comment',2);
@@ -196,6 +235,8 @@ INSERT INTO {modules} VALUES (7,1,'search',1);
 INSERT INTO {modules} VALUES (8,1,'slideshow',1);
 INSERT INTO {modules} VALUES (9,1,'tag',1);
 DROP TABLE IF EXISTS {outgoing_translations};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {outgoing_translations} (
   `id` int(9) NOT NULL auto_increment,
   `base_revision` int(9) default NULL,
@@ -207,7 +248,10 @@ CREATE TABLE {outgoing_translations} (
   UNIQUE KEY `key` (`key`,`locale`),
   KEY `locale_key` (`locale`,`key`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {permissions};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {permissions} (
   `id` int(9) NOT NULL auto_increment,
   `display_name` varchar(64) default NULL,
@@ -215,11 +259,14 @@ CREATE TABLE {permissions} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {permissions} VALUES (1,'View','view');
 INSERT INTO {permissions} VALUES (2,'View Full Size','view_full');
 INSERT INTO {permissions} VALUES (3,'Edit','edit');
 INSERT INTO {permissions} VALUES (4,'Add','add');
 DROP TABLE IF EXISTS {search_records};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {search_records} (
   `id` int(9) NOT NULL auto_increment,
   `item_id` int(9) default NULL,
@@ -229,15 +276,21 @@ CREATE TABLE {search_records} (
   KEY `item_id` (`item_id`),
   FULLTEXT KEY `data` (`data`)
 ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {search_records} VALUES (1,1,0,'   Gallery');
 DROP TABLE IF EXISTS {sessions};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {sessions} (
   `session_id` varchar(127) NOT NULL,
   `data` text NOT NULL,
   `last_activity` int(10) unsigned NOT NULL,
   PRIMARY KEY  (`session_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {tags};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {tags} (
   `id` int(9) NOT NULL auto_increment,
   `name` varchar(64) NOT NULL,
@@ -245,7 +298,10 @@ CREATE TABLE {tags} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {tasks};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {tasks} (
   `id` int(9) NOT NULL auto_increment,
   `callback` varchar(128) default NULL,
@@ -260,7 +316,10 @@ CREATE TABLE {tasks} (
   PRIMARY KEY  (`id`),
   KEY `owner_id` (`owner_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 DROP TABLE IF EXISTS {themes};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {themes} (
   `id` int(9) NOT NULL auto_increment,
   `name` varchar(64) default NULL,
@@ -268,9 +327,12 @@ CREATE TABLE {themes} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {themes} VALUES (1,'default',1);
 INSERT INTO {themes} VALUES (2,'admin_default',1);
 DROP TABLE IF EXISTS {users};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {users} (
   `id` int(9) NOT NULL auto_increment,
   `name` varchar(32) NOT NULL,
@@ -288,9 +350,12 @@ CREATE TABLE {users} (
   UNIQUE KEY `name` (`name`),
   UNIQUE KEY `hash` (`hash`)
 ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {users} VALUES (1,'guest','Guest User','',0,0,NULL,0,1,NULL,NULL,NULL);
 INSERT INTO {users} VALUES (2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL,NULL,NULL);
 DROP TABLE IF EXISTS {vars};
+SET @saved_cs_client     = @@character_set_client;
+SET character_set_client = utf8;
 CREATE TABLE {vars} (
   `id` int(9) NOT NULL auto_increment,
   `module_name` varchar(64) NOT NULL,
@@ -299,6 +364,7 @@ CREATE TABLE {vars} (
   PRIMARY KEY  (`id`),
   UNIQUE KEY `module_name` (`module_name`,`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
 INSERT INTO {vars} VALUES (1,'gallery','active_site_theme','default');
 INSERT INTO {vars} VALUES (2,'gallery','active_admin_theme','admin_default');
 INSERT INTO {vars} VALUES (3,'gallery','page_size','9');
-- 
cgit v1.2.3


From 9d2420e789cd02d459e7b1504b995bd9f4e84d00 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta <bharat@menalto.com>
Date: Wed, 29 Jul 2009 16:45:26 -0700
Subject: Updated for gallery v10

---
 installer/install.sql | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

(limited to 'installer/install.sql')

diff --git a/installer/install.sql b/installer/install.sql
index 0f8a2410..48b504ba 100755
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -169,7 +169,8 @@ CREATE TABLE {items} (
   PRIMARY KEY  (`id`),
   KEY `parent_id` (`parent_id`),
   KEY `type` (`type`),
-  KEY `random` (`rand_key`)
+  KEY `random` (`rand_key`),
+  KEY `weight` (`weight`)
 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
 SET character_set_client = @saved_cs_client;
 INSERT INTO {items} VALUES (1,NULL,NULL,UNIX_TIMESTAMP(),'',NULL,1,1,NULL,NULL,NULL,0,NULL,'',1,NULL,NULL,2,'weight','ASC',1,NULL,NULL,'Gallery','album',UNIX_TIMESTAMP(),0,1,NULL,'1','1');
@@ -225,7 +226,7 @@ CREATE TABLE {modules} (
   UNIQUE KEY `name` (`name`)
 ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
 SET character_set_client = @saved_cs_client;
-INSERT INTO {modules} VALUES (1,1,'gallery',9);
+INSERT INTO {modules} VALUES (1,1,'gallery',10);
 INSERT INTO {modules} VALUES (2,1,'user',1);
 INSERT INTO {modules} VALUES (3,1,'comment',2);
 INSERT INTO {modules} VALUES (4,1,'organize',1);
@@ -277,7 +278,7 @@ CREATE TABLE {search_records} (
   FULLTEXT KEY `data` (`data`)
 ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
 SET character_set_client = @saved_cs_client;
-INSERT INTO {search_records} VALUES (1,1,0,'   Gallery');
+INSERT INTO {search_records} VALUES (1,1,0,'  Gallery');
 DROP TABLE IF EXISTS {sessions};
 SET @saved_cs_client     = @@character_set_client;
 SET character_set_client = utf8;
-- 
cgit v1.2.3

