summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-02-27 21:07:18 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-02-27 21:07:18 +0000
commitbd15853708ae73ee69220738a061e10d015d7fb9 (patch)
treefacfbd5b08e3cbb8e7fa2b4adf433b54d4c0c5bc
parent0b9fe18a6bf4036a05db7f9479d7b55d3fe5c782 (diff)
This implements table prefix for all the queries in core, user, exif,
tag, search, comment and notification modules (Ticket #68)
-rw-r--r--core/controllers/scaffold.php4
-rw-r--r--core/helpers/access.php12
-rw-r--r--core/helpers/core_installer.php56
-rw-r--r--core/helpers/graphics.php2
-rw-r--r--core/helpers/module.php2
-rw-r--r--core/libraries/ORM_MPTT.php22
-rw-r--r--modules/comment/controllers/admin_comments.php2
-rw-r--r--modules/comment/helpers/comment_installer.php7
-rw-r--r--modules/exif/helpers/exif_installer.php6
-rw-r--r--modules/notification/helpers/notification_installer.php4
-rw-r--r--modules/search/helpers/search_installer.php6
-rw-r--r--modules/search/helpers/search_task.php14
-rw-r--r--modules/tag/helpers/tag_event.php8
-rw-r--r--modules/tag/helpers/tag_installer.php8
-rw-r--r--modules/user/helpers/user_installer.php12
15 files changed, 83 insertions, 82 deletions
diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php
index 64d9000d..554d576c 100644
--- a/core/controllers/scaffold.php
+++ b/core/controllers/scaffold.php
@@ -509,8 +509,8 @@ class Scaffold_Controller extends Template_Controller {
// We now have a clean install with just the packages that we want. Make sure that the
// database is clean too.
$db = Database::instance();
- $db->query("TRUNCATE `sessions`");
- $db->query("TRUNCATE `logs`");
+ $db->query("TRUNCATE `[sessions]`");
+ $db->query("TRUNCATE `[logs]`");
$db->update("users", array("password" => ""), array("id" => 2));
$dbconfig = Kohana::config('database.default');
diff --git a/core/helpers/access.php b/core/helpers/access.php
index 8a88bdf5..a9f48c20 100644
--- a/core/helpers/access.php
+++ b/core/helpers/access.php
@@ -404,8 +404,8 @@ 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` DROP `$field`");
- $db->query("ALTER TABLE `access_intents` DROP `$field`");
+ $db->query("ALTER TABLE `[$cache_table]` DROP `$field`");
+ $db->query("ALTER TABLE `[access_intents]` DROP `$field`");
ORM::factory("access_intent")->clear_cache();
}
@@ -420,8 +420,8 @@ 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` TINYINT(2) NOT NULL DEFAULT 0");
- $db->query("ALTER TABLE `access_intents` ADD `$field` BOOLEAN DEFAULT NULL");
+ $db->query("ALTER TABLE `[$cache_table]` ADD `$field` TINYINT(2) 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));
ORM::factory("access_intent")->clear_cache();
}
@@ -547,9 +547,9 @@ class access_Core {
->find_all();
foreach ($query as $row) {
$db->query(
- "UPDATE `access_caches` SET `$field` = {$row->$field} " .
+ "UPDATE `[access_caches]` SET `$field` = {$row->$field} " .
"WHERE `item_id` IN " .
- " (SELECT `id` FROM `items` " .
+ " (SELECT `id` FROM `[items]` " .
" WHERE `left` >= $row->left " .
" AND `right` <= $row->right)");
}
diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php
index e1dd34c2..d3eb3090 100644
--- a/core/helpers/core_installer.php
+++ b/core/helpers/core_installer.php
@@ -31,19 +31,19 @@ class core_installer {
}
if ($version == 0) {
- $db->query("CREATE TABLE `access_caches` (
+ $db->query("CREATE TABLE `[access_caches]` (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `access_intents` (
+ $db->query("CREATE TABLE `[access_intents]` (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `graphics_rules` (
+ $db->query("CREATE TABLE `[graphics_rules]` (
`id` int(9) NOT NULL auto_increment,
`priority` int(9) NOT NULL,
`module_name` varchar(64) NOT NULL,
@@ -53,7 +53,7 @@ class core_installer {
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `items` (
+ $db->query("CREATE TABLE `[items]` (
`album_cover_item_id` int(9) default NULL,
`created` int(9) default NULL,
`description` varchar(255) default NULL,
@@ -84,7 +84,7 @@ class core_installer {
KEY `random` (`rand_key` DESC))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `logs` (
+ $db->query("CREATE TABLE `[logs]` (
`id` int(9) NOT NULL auto_increment,
`category` varchar(64) default NULL,
`html` varchar(255) default NULL,
@@ -97,7 +97,7 @@ class core_installer {
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `messages` (
+ $db->query("CREATE TABLE `[messages]` (
`id` int(9) NOT NULL auto_increment,
`key` varchar(255) default NULL,
`value` varchar(255) default NULL,
@@ -106,7 +106,7 @@ class core_installer {
UNIQUE KEY(`key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `modules` (
+ $db->query("CREATE TABLE `[modules]` (
`id` int(9) NOT NULL auto_increment,
`name` varchar(64) default NULL,
`version` int(9) default NULL,
@@ -114,7 +114,7 @@ class core_installer {
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `themes` (
+ $db->query("CREATE TABLE `[themes]` (
`id` int(9) NOT NULL auto_increment,
`name` varchar(64) default NULL,
`version` int(9) default NULL,
@@ -122,7 +122,7 @@ class core_installer {
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `permissions` (
+ $db->query("CREATE TABLE `[permissions]` (
`id` int(9) NOT NULL auto_increment,
`name` varchar(64) default NULL,
`display_name` varchar(64) default NULL,
@@ -130,7 +130,7 @@ class core_installer {
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `incoming_translations` (
+ $db->query("CREATE TABLE `[incoming_translations]` (
`id` int(9) NOT NULL auto_increment,
`key` char(32) NOT NULL,
`locale` char(10) NOT NULL,
@@ -142,7 +142,7 @@ class core_installer {
KEY `locale_key` (`locale`, `key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `outgoing_translations` (
+ $db->query("CREATE TABLE `[outgoing_translations]` (
`id` int(9) NOT NULL auto_increment,
`key` char(32) NOT NULL,
`locale` char(10) NOT NULL,
@@ -154,14 +154,14 @@ class core_installer {
KEY `locale_key` (`locale`, `key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `sessions` (
+ $db->query("CREATE TABLE `[sessions]` (
`session_id` varchar(127) NOT NULL,
`last_activity` int(10) UNSIGNED NOT NULL,
`data` text NOT NULL,
PRIMARY KEY (`session_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `tasks` (
+ $db->query("CREATE TABLE `[tasks]` (
`callback` varchar(128) default NULL,
`context` text NOT NULL,
`done` boolean default 0,
@@ -176,7 +176,7 @@ class core_installer {
KEY (`owner_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE `vars` (
+ $db->query("CREATE TABLE `[vars]` (
`id` int(9) NOT NULL auto_increment,
`module_name` varchar(64) NOT NULL,
`name` varchar(64) NOT NULL,
@@ -266,20 +266,20 @@ class core_installer {
static function uninstall() {
$db = Database::instance();
- $db->query("DROP TABLE IF EXISTS `access_caches`;");
- $db->query("DROP TABLE IF EXISTS `access_intents`;");
- $db->query("DROP TABLE IF EXISTS `graphics_rules`;");
- $db->query("DROP TABLE IF EXISTS `items`;");
- $db->query("DROP TABLE IF EXISTS `logs`;");
- $db->query("DROP TABLE IF EXISTS `messages`;");
- $db->query("DROP TABLE IF EXISTS `modules`;");
- $db->query("DROP TABLE IF EXISTS `themes`;");
- $db->query("DROP TABLE IF EXISTS `incoming_translations`;");
- $db->query("DROP TABLE IF EXISTS `outgoing_translations`;");
- $db->query("DROP TABLE IF EXISTS `permissions`;");
- $db->query("DROP TABLE IF EXISTS `sessions`;");
- $db->query("DROP TABLE IF EXISTS `tasks`;");
- $db->query("DROP TABLE IF EXISTS `vars`;");
+ $db->query("DROP TABLE IF EXISTS `[access_caches]`;");
+ $db->query("DROP TABLE IF EXISTS `[access_intents]`;");
+ $db->query("DROP TABLE IF EXISTS `[graphics_rules]`;");
+ $db->query("DROP TABLE IF EXISTS `[items`;");
+ $db->query("DROP TABLE IF EXISTS `[logs]`;");
+ $db->query("DROP TABLE IF EXISTS `[messages]`;");
+ $db->query("DROP TABLE IF EXISTS `[modules]`;");
+ $db->query("DROP TABLE IF EXISTS `[themes]`;");
+ $db->query("DROP TABLE IF EXISTS `[incoming_translations]`;");
+ $db->query("DROP TABLE IF EXISTS `[outgoing_translations]`;");
+ $db->query("DROP TABLE IF EXISTS `[permissions]`;");
+ $db->query("DROP TABLE IF EXISTS `[sessions]`;");
+ $db->query("DROP TABLE IF EXISTS `[tasks]`;");
+ $db->query("DROP TABLE IF EXISTS `[vars]`;");
foreach (array("albums", "resizes", "thumbs", "uploads", "modules") as $dir) {
system("/bin/rm -rf " . VARPATH . $dir);
}
diff --git a/core/helpers/graphics.php b/core/helpers/graphics.php
index d30701a0..5c3480c9 100644
--- a/core/helpers/graphics.php
+++ b/core/helpers/graphics.php
@@ -223,7 +223,7 @@ class graphics_Core {
*/
static function find_dirty_images_query() {
return Database::instance()->query(
- "SELECT `id` FROM `items` " .
+ "SELECT `id` FROM `[items]` " .
"WHERE (`thumb_dirty` = 1 AND (`type` <> 'album' OR `album_cover_item_id` IS NOT NULL))" .
" OR (`resize_dirty` = 1 AND `type` = 'photo')");
}
diff --git a/core/helpers/module.php b/core/helpers/module.php
index 23e90a3c..1bc8214f 100644
--- a/core/helpers/module.php
+++ b/core/helpers/module.php
@@ -241,7 +241,7 @@ class module_Core {
*/
static function incr_var($module_name, $name, $increment=1) {
Database::instance()->query(
- "UPDATE `vars` SET `value` = `value` + $increment " .
+ "UPDATE `[vars]` SET `value` = `value` + $increment " .
"WHERE `module_name` = '$module_name' " .
"AND `name` = '$name'");
}
diff --git a/core/libraries/ORM_MPTT.php b/core/libraries/ORM_MPTT.php
index bcbdde4e..c1adb920 100644
--- a/core/libraries/ORM_MPTT.php
+++ b/core/libraries/ORM_MPTT.php
@@ -52,9 +52,9 @@ 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` = `left` + 2 WHERE `left` >= {$parent->right}");
$this->db->query(
- "UPDATE `{$this->table_name}` SET `right` = `right` + 2 WHERE `right` >= {$parent->right}");
+ "UPDATE `[{$this->table_name}]` SET `right` = `right` + 2 WHERE `right` >= {$parent->right}");
$parent->right += 2;
// Insert this item into the hole
@@ -90,9 +90,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` = `left` - 2 WHERE `left` > {$this->right}");
$this->db->query(
- "UPDATE `{$this->table_name}` SET `right` = `right` - 2 WHERE `right` > {$this->right}");
+ "UPDATE `[{$this->table_name}]` SET `right` = `right` - 2 WHERE `right` > {$this->right}");
} catch (Exception $e) {
$this->unlock();
throw $e;
@@ -229,21 +229,21 @@ class ORM_MPTT_Core extends ORM {
if ($level_delta) {
// Update the levels for the to-be-moved items
$this->db->query(
- "UPDATE `{$this->table_name}` SET `level` = `level` + $level_delta" .
+ "UPDATE `[{$this->table_name}]` SET `level` = `level` + $level_delta" .
" WHERE `left` >= $original_left AND `right` <= $original_right");
}
// Make a hole in the target for the move
$target->db->query(
- "UPDATE `{$this->table_name}` SET `left` = `left` + $size_of_hole" .
+ "UPDATE `[{$this->table_name}]` SET `left` = `left` + $size_of_hole" .
" WHERE `left` >= $target_right");
$target->db->query(
- "UPDATE `{$this->table_name}` SET `right` = `right` + $size_of_hole" .
+ "UPDATE `[{$this->table_name}]` SET `right` = `right` + $size_of_hole" .
" WHERE `right` >= $target_right");
// Change the parent.
$this->db->query(
- "UPDATE `{$this->table_name}` SET `parent_id` = {$target->id}" .
+ "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.
@@ -256,7 +256,7 @@ class ORM_MPTT_Core extends ORM {
$new_offset = $target->right - $left;
$this->db->query(
- "UPDATE `{$this->table_name}`" .
+ "UPDATE `[{$this->table_name}]`" .
" SET `left` = `left` + $new_offset," .
" `right` = `right` + $new_offset" .
" WHERE `left` >= $left" .
@@ -264,10 +264,10 @@ class ORM_MPTT_Core extends ORM {
// Close the hole in the source's parent after the move
$this->db->query(
- "UPDATE `{$this->table_name}` SET `left` = `left` - $size_of_hole" .
+ "UPDATE `[{$this->table_name}]` SET `left` = `left` - $size_of_hole" .
" WHERE `left` > $right");
$this->db->query(
- "UPDATE `{$this->table_name}` SET `right` = `right` - $size_of_hole" .
+ "UPDATE `[{$this->table_name}]` SET `right` = `right` - $size_of_hole" .
" WHERE `right` > $right");
} catch (Exception $e) {
$this->unlock();
diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php
index cd408421..47e354af 100644
--- a/modules/comment/controllers/admin_comments.php
+++ b/modules/comment/controllers/admin_comments.php
@@ -57,7 +57,7 @@ class Admin_Comments_Controller extends Admin_Controller {
public function index() {
// Get rid of old deleted/spam comments
Database::instance()->query(
- "DELETE FROM `comments` " .
+ "DELETE FROM `[comments]` " .
"WHERE state IN ('deleted', 'spam') " .
"AND unix_timestamp(now()) - updated > 86400 * 7");
diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php
index 12caa547..a7852d05 100644
--- a/modules/comment/helpers/comment_installer.php
+++ b/modules/comment/helpers/comment_installer.php
@@ -23,7 +23,7 @@ class comment_installer {
$version = module::get_version("comment");
if ($version == 0) {
- $db->query("CREATE TABLE IF NOT EXISTS `comments` (
+ $db->query("CREATE TABLE IF NOT EXISTS `[comments]` (
`author_id` int(9) default NULL,
`created` int(9) NOT NULL,
`guest_email` varchar(128) default NULL,
@@ -58,10 +58,11 @@ class comment_installer {
static function uninstall() {
$db = Database::instance();
- $sql = "SELECT `item_id` FROM `comments`";
+ $sql = "SELECT `item_id` FROM `[comments]`";
module::event("item_related_update_batch", $sql);
- $db->query("DROP TABLE IF EXISTS `comments`;");
+ $db->query("DROP TABLE IF EXISTS `[comments]
+`;");
module::delete("comment");
}
}
diff --git a/modules/exif/helpers/exif_installer.php b/modules/exif/helpers/exif_installer.php
index 791cd4a6..964a9e6c 100644
--- a/modules/exif/helpers/exif_installer.php
+++ b/modules/exif/helpers/exif_installer.php
@@ -23,7 +23,7 @@ class exif_installer {
if ($version == 0) {
$db = Database::instance();
- $db->query("CREATE TABLE IF NOT EXISTS `exif_keys` (
+ $db->query("CREATE TABLE IF NOT EXISTS `[exif_keys]` (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) NOT NULL,
`name` varchar(64) NOT NULL,
@@ -32,7 +32,7 @@ class exif_installer {
PRIMARY KEY (`id`),
UNIQUE KEY(`item_id`, `summary`, `name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE IF NOT EXISTS `exif_records` (
+ $db->query("CREATE TABLE IF NOT EXISTS `[exif_records]` (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) NOT NULL,
`dirty` BOOLEAN default 1,
@@ -44,7 +44,7 @@ class exif_installer {
static function uninstall() {
$db = Database::instance();
- $db->query("DROP TABLE IF EXISTS `exif_keys`;");
+ $db->query("DROP TABLE IF EXISTS `[exif_keys]`;");
module::delete("exif");
}
}
diff --git a/modules/notification/helpers/notification_installer.php b/modules/notification/helpers/notification_installer.php
index f705fe68..00fc82db 100644
--- a/modules/notification/helpers/notification_installer.php
+++ b/modules/notification/helpers/notification_installer.php
@@ -23,7 +23,7 @@ class notification_installer {
$version = module::get_version("notification");
if ($version == 0) {
- $db->query("CREATE TABLE IF NOT EXISTS `subscriptions` (
+ $db->query("CREATE TABLE IF NOT EXISTS `[subscriptions]` (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) NOT NULL,
`user_id` int(9) NOT NULL,
@@ -38,7 +38,7 @@ class notification_installer {
static function uninstall() {
$db = Database::instance();
- $db->query("DROP TABLE IF EXISTS `subscriptions`;");
+ $db->query("DROP TABLE IF EXISTS `[subscriptions]`;");
module::delete("notification");
}
diff --git a/modules/search/helpers/search_installer.php b/modules/search/helpers/search_installer.php
index b823f498..05775fec 100644
--- a/modules/search/helpers/search_installer.php
+++ b/modules/search/helpers/search_installer.php
@@ -22,7 +22,7 @@ class search_installer {
$version = module::get_version("search");
$db = Database::instance();
if ($version == 0) {
- $db->query("CREATE TABLE `search_records` (
+ $db->query("CREATE TABLE `[search_records]` (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
`dirty` boolean default 1,
@@ -32,7 +32,7 @@ class search_installer {
ENGINE=MyISAM DEFAULT CHARSET=utf8;");
// populate the index with dirty records
- $db->query("insert into `search_records` (`item_id`) SELECT `id` FROM `items`");
+ $db->query("INSERT INTO `[search_records]` (`item_id`) SELECT `id` FROM `[items]`");
module::set_version("search", 1);
if (ORM::factory("search_record")->count_all() < 10) {
@@ -47,7 +47,7 @@ class search_installer {
static function uninstall() {
$db = Database::instance();
- $db->query("DROP TABLE `search_records`");
+ $db->query("DROP TABLE `[search_records]`");
site_status::clear("search_index_out_of_date");
module::delete("search");
}
diff --git a/modules/search/helpers/search_task.php b/modules/search/helpers/search_task.php
index ca5f8502..0071f2e0 100644
--- a/modules/search/helpers/search_task.php
+++ b/modules/search/helpers/search_task.php
@@ -21,16 +21,16 @@ class search_task_Core {
static function available_tasks() {
// Delete extra search_records
Database::instance()->query(
- "DELETE `search_records`.* FROM `search_records` " .
- "LEFT JOIN `items` ON (`search_records`.`item_id` = `items`.`id`) " .
- "WHERE `items`.`id` IS NULL");
+ "DELETE `[search_records]`.* FROM `[search_records]` " .
+ "LEFT JOIN `[items]` ON (`[search_records]`.`item_id` = `[items]`.`id`) " .
+ "WHERE `[items]`.`id` IS NULL");
// Insert missing search_records
Database::instance()->query(
- "INSERT INTO `search_records`(`item_id`) (" .
- " SELECT `items`.`id` FROM `items` " .
- " LEFT JOIN `search_records` ON (`search_records`.`item_id` = `items`.`id`) " .
- " WHERE `search_records`.`id` IS NULL)");
+ "INSERT INTO `[search_records]`(`item_id`) (" .
+ " SELECT `[items]`.`id` FROM `[items]` " .
+ " LEFT JOIN `[search_records]` ON (`[search_records]`.`item_id` = `[items]`.`id`) " .
+ " WHERE `[search_records]`.`id` IS NULL)");
list ($remaining, $total, $percent) = self::_get_stats();
return array(Task_Definition::factory()
diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php
index 47391355..a0c7b159 100644
--- a/modules/tag/helpers/tag_event.php
+++ b/modules/tag/helpers/tag_event.php
@@ -50,10 +50,10 @@ class tag_event_Core {
static function item_before_delete($item) {
$db = Database::instance();
- $db->query("UPDATE `tags` SET `count` = `count` - 1 WHERE `count` > 0 " .
- "AND `id` IN (SELECT `tag_id` from `items_tags` WHERE `item_id` = $item->id)");
- $db->query("DELETE FROM `tags` WHERE `count` = 0 AND `id` IN (" .
- "SELECT `tag_id` from `items_tags` WHERE `item_id` = $item->id)");
+ $db->query("UPDATE `[tags]` SET `count` = `count` - 1 WHERE `count` > 0 " .
+ "AND `id` IN (SELECT `tag_id` from `[items_tags]` WHERE `item_id` = $item->id)");
+ $dbs->query("DELETE FROM `tags` WHERE `count` = 0 AND `id` IN (" .
+ "SELECT `tag_id` from `[items_tags]` WHERE `item_id` = $item->id)");
$db->delete("items_tags", array("item_id" => "$item->id"));
}
diff --git a/modules/tag/helpers/tag_installer.php b/modules/tag/helpers/tag_installer.php
index 54ad52fe..1345cadb 100644
--- a/modules/tag/helpers/tag_installer.php
+++ b/modules/tag/helpers/tag_installer.php
@@ -22,7 +22,7 @@ class tag_installer {
$db = Database::instance();
$version = module::get_version("tag");
if ($version == 0) {
- $db->query("CREATE TABLE IF NOT EXISTS `tags` (
+ $db->query("CREATE TABLE IF NOT EXISTS `[tags]` (
`id` int(9) NOT NULL auto_increment,
`name` varchar(64) NOT NULL,
`count` int(10) unsigned NOT NULL DEFAULT 0,
@@ -30,7 +30,7 @@ class tag_installer {
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE IF NOT EXISTS `items_tags` (
+ $db->query("CREATE TABLE IF NOT EXISTS `[items_tags]` (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) NOT NULL,
`tag_id` int(9) NOT NULL,
@@ -44,8 +44,8 @@ class tag_installer {
static function uninstall() {
$db = Database::instance();
- $db->query("DROP TABLE IF EXISTS `tags`;");
- $db->query("DROP TABLE IF EXISTS `items_tags`;");
+ $db->query("DROP TABLE IF EXISTS `[tags]`;");
+ $db->query("DROP TABLE IF EXISTS `[items_tags]`;");
module::delete("tag");
}
}
diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php
index f293e109..414327f5 100644
--- a/modules/user/helpers/user_installer.php
+++ b/modules/user/helpers/user_installer.php
@@ -23,7 +23,7 @@ class user_installer {
$version = module::get_version("user");
if ($version == 0) {
- $db->query("CREATE TABLE IF NOT EXISTS `users` (
+ $db->query("CREATE TABLE IF NOT EXISTS `[users]` (
`id` int(9) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
`full_name` varchar(255) NOT NULL,
@@ -41,7 +41,7 @@ class user_installer {
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE IF NOT EXISTS `groups` (
+ $db->query("CREATE TABLE IF NOT EXISTS `[groups]` (
`id` int(9) NOT NULL auto_increment,
`name` char(64) default NULL,
`special` BOOLEAN default 0,
@@ -49,7 +49,7 @@ class user_installer {
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
- $db->query("CREATE TABLE IF NOT EXISTS `groups_users` (
+ $db->query("CREATE TABLE IF NOT EXISTS `[groups_users]` (
`group_id` int(9) NOT NULL,
`user_id` int(9) NOT NULL,
PRIMARY KEY (`group_id`, `user_id`),
@@ -105,9 +105,9 @@ class user_installer {
} catch (Exception $e) {
}
$db = Database::instance();
- $db->query("DROP TABLE IF EXISTS `users`;");
- $db->query("DROP TABLE IF EXISTS `groups`;");
- $db->query("DROP TABLE IF EXISTS `groups_users`;");
+ $db->query("DROP TABLE IF EXISTS `[users]`;");
+ $db->query("DROP TABLE IF EXISTS `[groups]`;");
+ $db->query("DROP TABLE IF EXISTS `[groups_users]`;");
module::delete("user");
}
} \ No newline at end of file