summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRomain LE DISEZ <romain.git@ledisez.net>2009-07-19 00:49:47 +0200
committerBharat Mediratta <bharat@menalto.com>2009-07-23 09:11:55 -0700
commit350c1b02670d971d3a389f786f46fb9be2dec8ed (patch)
tree64b7bac43d4e725eaf218186400b321bf5b5adf0
parent5999ccb512d65ad9ae06a0a5542eb1123b44e9db (diff)
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. (cherry picked from commit 719c59e0402464a0e2b14915f6d10218ff5d4729)
-rwxr-xr-xinstaller/install.sql32
-rw-r--r--modules/gallery/helpers/access.php31
-rw-r--r--modules/gallery/views/permissions_form.html.php2
-rw-r--r--modules/search/helpers/search.php2
-rw-r--r--system/libraries/drivers/Database.php4
5 files changed, 37 insertions, 34 deletions
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 65316a8a..4130964d 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?
@@ -141,7 +142,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");
@@ -169,7 +170,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();
@@ -253,7 +254,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);
}
/**
@@ -455,9 +456,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();
}
@@ -513,7 +515,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) {
@@ -557,12 +559,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();
@@ -578,12 +580,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 6317020f..b08cf89d 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