diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-07-30 01:55:56 +0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-07-30 01:59:07 +0800 |
commit | ead6a61d9e96d37ca3a0aecb93d18755099e341c (patch) | |
tree | 7dab5b22d8e673f79b8f8e9aec642dc5bca81fe4 /modules | |
parent | eb90fc9e63e35e1131f19204a370fe711f5ecc01 (diff) |
Fix for ticket #576
Add a weight index to the item table and changed the retrieval of the maximum
weight to select weight from items order by weight desc limit 1.
Upgrades the gallery module to version 10
Signed-off-by: Tim Almdal <tnalmdal@shaw.ca>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 21 | ||||
-rw-r--r-- | modules/gallery/models/item.php | 16 | ||||
-rw-r--r-- | modules/gallery/module.info | 2 |
3 files changed, 34 insertions, 5 deletions
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 760bec31..2322110e 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -98,9 +98,20 @@ class gallery_installer { PRIMARY KEY (`id`), KEY `parent_id` (`parent_id`), KEY `type` (`type`), - KEY `random` (`rand_key`)) + KEY `random` (`rand_key`), + KEY `weight` (`weight` DESC)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + $db->query("DELIMITER | + CREATE TRIGGER setweight BEFORE INSERT ON {items} + FOR EACH ROW BEGIN + DECLARE new_weight int(9); + SELECT weight+1 FROM {items} + ORDER BY weight LIMIT 1 INTO new_weight; + SET NEW.weight = new_weight; + END;| + DELIMITER ;"); + $db->query("CREATE TABLE {logs} ( `id` int(9) NOT NULL auto_increment, `category` varchar(64) default NULL, @@ -329,7 +340,13 @@ class gallery_installer { $db->query("ALTER TABLE {items} CHANGE COLUMN `right` `right_ptr` INT(9) NOT NULL;"); module::set_version("gallery", $version = 9); } - } + + if ($version == 9) { + $db->query("ALTER TABLE {items} ADD KEY `weight` (`weight` DESC);"); + + module::set_version("gallery", $version = 10); + } +} static function uninstall() { $db = Database::instance(); diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index dcbee991..481b22bc 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -350,9 +350,21 @@ class Item_Model extends ORM_MPTT { if (!empty($this->changed) && $this->changed != array("view_count" => "view_count")) { $this->updated = time(); if (!$this->loaded) { + try { $this->created = $this->updated; - $r = ORM::factory("item")->select("MAX(weight) as max_weight")->find(); - $this->weight = $r->max_weight + 1; + Kohana::log("error", "get Weight"); + $weight = ORM::factory("item") + ->select("weight") + ->orderby("weight", "DESC") + ->limit(1) + ->find_all() + ->current()->weight; + Kohana::log("error", "Weight: $weight"); + $this->weight = $weight + 1; + } catch (Exception $e) { + Kohana::log("error", $e->__toString()); + throw $e; + } } else { $send_event = 1; } diff --git a/modules/gallery/module.info b/modules/gallery/module.info index c5a9d25d..dfb1a7a2 100644 --- a/modules/gallery/module.info +++ b/modules/gallery/module.info @@ -1,3 +1,3 @@ name = "Gallery 3" description = "Gallery core application" -version = 9 +version = 10 |