Skip to content

Commit

Permalink
Rename columns that use reserved SQL words : items.left and items.right
Browse files Browse the repository at this point in the history
  • Loading branch information
rledisez committed Jul 25, 2009
1 parent 0aa3ec3 commit 23bb6eb
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 162 deletions.
72 changes: 3 additions & 69 deletions 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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -87,38 +73,29 @@ 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,
`special` tinyint(1) default '0',
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,
Expand All @@ -130,18 +107,15 @@ 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,
`captured` int(9) default NULL,
`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,
Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -248,25 +207,19 @@ 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,
`name` varchar(64) default NULL,
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,
Expand All @@ -276,32 +229,23 @@ 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,
`count` int(10) unsigned NOT NULL default '0',
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,
Expand All @@ -316,23 +260,17 @@ 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,
`version` int(9) default NULL,
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,
Expand All @@ -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,
Expand All @@ -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');
Expand Down
40 changes: 20 additions & 20 deletions modules/gallery/helpers/access.php
Expand Up @@ -166,8 +166,8 @@ static function locked_by($group, $perm_name, $item) {
// 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)
Expand Down Expand Up @@ -490,11 +490,11 @@ private static function _update_access_view_cache($group, $item) {
// 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) {
Expand All @@ -507,13 +507,13 @@ private static function _update_access_view_cache($group, $item) {
// 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")
Expand All @@ -522,19 +522,19 @@ private static function _update_access_view_cache($group, $item) {
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));
}
}

// Finally, if our intent is DEFAULT at this point it means that we were unable to find a
// 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));
}

/**
Expand Down Expand Up @@ -562,10 +562,10 @@ private static function _update_access_non_view_cache($group, $perm_name, $item)
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) {
Expand All @@ -576,10 +576,10 @@ private static function _update_access_non_view_cache($group, $perm_name, $item)
// 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();
Expand All @@ -589,8 +589,8 @@ private static function _update_access_non_view_cache($group, $perm_name, $item)
"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)");
}
}

Expand Down

0 comments on commit 23bb6eb

Please sign in to comment.