From 5b3b675b6d8a1cd9a5f2b9455c551791e18d88ff Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 16 Jul 2009 11:19:34 -0700 Subject: Non-trivial changes to the event handling code: 1) The item_updated event no longer takes the old and new items. Instead we overload ORM to track the original data and make that available via the item. This will allow us to move event publishing down into the API methods which in turn will give us more stability since we won't require each controller to remember to do it. 2) ORM class now tracks the original values. It doesn't track the original relationships (no need for that, yet) 3) Added new events: item_deleted group_deleted user_deleted --- modules/notification/helpers/notification.php | 19 +++++++++---------- modules/notification/helpers/notification_event.php | 10 +++++----- modules/notification/helpers/notification_menu.php | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) (limited to 'modules/notification/helpers') diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 8ee0c6ba..e246af2c 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -82,17 +82,16 @@ class notification { return $subscribers; } - static function send_item_updated($old, $new) { + static function send_item_updated($item) { $v = new View("item_updated.html"); - $v->old = $old; - $v->new = $new; - $v->subject = $old->is_album() ? - t("Album %title updated", array("title" => $old->title)) : - ($old->is_photo() ? - t("Photo %title updated", array("title" => $old->title)) - : t("Movie %title updated", array("title" => $old->title))); - - self::_notify_subscribers($old, $v->render(), $v->subject); + $v->item = $item; + $v->subject = $item->is_album() ? + t("Album %title updated", array("title" => $item->original("title"))) : + ($item->is_photo() ? + t("Photo %title updated", array("title" => $item->original("title"))) + : t("Movie %title updated", array("title" => $item->original("title")))); + + self::_notify_subscribers($item, $v->render(), $v->subject); } static function send_item_add($item) { diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index 1cf9ff58..536557c6 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -18,15 +18,15 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class notification_event_Core { - static function item_updated($old, $new) { - notification::send_item_updated($old, $new); + static function item_updated($item) { + notification::send_item_updated($item); } static function item_created($item) { notification::send_item_add($item); } - static function item_before_delete($item) { + static function item_deleted($item) { notification::send_item_deleted($item); if (notification::is_watching($item)) { @@ -40,8 +40,8 @@ class notification_event_Core { } } - static function comment_updated($old, $new) { - if ($new->state == "published" && $old->state != "published") { + static function comment_updated($item) { + if ($item->state == "published" && $item->original("state") != "published") { notification::send_comment_published($new); } } diff --git a/modules/notification/helpers/notification_menu.php b/modules/notification/helpers/notification_menu.php index 696aad62..87478b8a 100644 --- a/modules/notification/helpers/notification_menu.php +++ b/modules/notification/helpers/notification_menu.php @@ -21,7 +21,7 @@ class notification_menu_Core { static function site($menu, $theme) { if (!user::active()->guest) { $item = $theme->item(); - + if ($item && $item->is_album()) { $watching = notification::is_watching($item); -- cgit v1.2.3 From 427e1130b26a75a59b5e180e2008f5eace398920 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 22 Jul 2009 11:11:48 -0700 Subject: Modified the notification get_subscribers to ignore any users that don't have "view" access to the item the notification is being generated for. Fix for ticket: #538. --- modules/notification/helpers/notification.php | 14 ++++++++++---- modules/notification/helpers/notification_menu.php | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'modules/notification/helpers') diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index e246af2c..c3ffeb18 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -67,6 +67,8 @@ class notification { } static function get_subscribers($item) { + // @todo don't access the user table directly + // @todo only return distinct email addresses $users = ORM::factory("user") ->join("subscriptions", "users.id", "subscriptions.user_id") ->join("items", "subscriptions.item_id", "items.id") @@ -77,9 +79,13 @@ class notification { $subscribers = array(); foreach ($users as $user) { - $subscribers[] = $user->email; + Kohana::log("error", "user: $user->name"); + + if (access::user_can($user, "view", $item)) { + $subscribers[$user->email] = 1; + } } - return $subscribers; + return array_keys($subscribers); } static function send_item_updated($item) { @@ -103,8 +109,8 @@ class notification { array("title" => $item->title, "parent_title" => $parent->title)) : ($item->is_photo() ? t("Photo %title added to %parent_title", - array("title" => $item->title, "parent_title" => $parent->title)) - : t("Movie %title added to %parent_title", + array("title" => $item->title, "parent_title" => $parent->title)) : + t("Movie %title added to %parent_title", array("title" => $item->title, "parent_title" => $parent->title))); self::_notify_subscribers($item, $v->render(), $v->subject); diff --git a/modules/notification/helpers/notification_menu.php b/modules/notification/helpers/notification_menu.php index 87478b8a..73d1dd03 100644 --- a/modules/notification/helpers/notification_menu.php +++ b/modules/notification/helpers/notification_menu.php @@ -22,10 +22,10 @@ class notification_menu_Core { if (!user::active()->guest) { $item = $theme->item(); - if ($item && $item->is_album()) { + if ($item && $item->is_album() && access::can("view", $item)) { $watching = notification::is_watching($item); - $watching ? $label = t("Remove notifications") : $label = t("Enable notifications"); + $label = $watching ? t("Remove notifications") : t("Enable notifications"); $menu->get("options_menu") ->append(Menu::factory("link") -- cgit v1.2.3 From 5999ccb512d65ad9ae06a0a5542eb1123b44e9db Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 23 Jul 2009 08:40:00 -0700 Subject: Remove extra error log line --- modules/notification/helpers/notification.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'modules/notification/helpers') diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index c3ffeb18..d91a37e8 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -79,8 +79,6 @@ class notification { $subscribers = array(); foreach ($users as $user) { - Kohana::log("error", "user: $user->name"); - if (access::user_can($user, "view", $item)) { $subscribers[$user->email] = 1; } -- cgit v1.2.3 From 23bb6eb7e35637c8a2124216dbb6d3246ad3d702 Mon Sep 17 00:00:00 2001 From: Romain LE DISEZ 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 'modules/notification/helpers') 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 Gallery %version"); - 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 1e90e40d3a9fe2cb826b56686f23a33879418048 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 28 Jul 2009 13:47:22 -0700 Subject: Use events to generate menus, instead of having xxx_menu helpers. This is the first step towards having a simple, lightweight and unified API for module interaction. --- modules/akismet/helpers/akismet_event.php | 16 ++ modules/akismet/helpers/akismet_menu.php | 36 ----- modules/comment/helpers/comment_event.php | 17 +++ modules/comment/helpers/comment_menu.php | 37 ----- modules/digibug/helpers/digibug_event.php | 50 +++++++ modules/digibug/helpers/digibug_menu.php | 50 ------- modules/g2_import/helpers/g2_import_event.php | 9 ++ modules/g2_import/helpers/g2_import_menu.php | 29 ---- modules/gallery/helpers/gallery_menu.php | 164 --------------------- modules/gallery/libraries/Admin_View.php | 70 +++++++-- modules/gallery/libraries/Theme_View.php | 105 +++++++++---- .../notification/helpers/notification_event.php | 19 +++ modules/notification/helpers/notification_menu.php | 39 ----- modules/organize/helpers/organize_event.php | 33 +++++ modules/organize/helpers/organize_menu.php | 33 ----- modules/recaptcha/helpers/recaptcha_event.php | 8 + modules/recaptcha/helpers/recaptcha_menu.php | 28 ---- modules/server_add/helpers/server_add_event.php | 64 ++++++++ modules/server_add/helpers/server_add_menu.php | 64 -------- modules/slideshow/helpers/slideshow_event.php | 30 ++++ modules/slideshow/helpers/slideshow_menu.php | 51 ------- modules/tag/helpers/tag_event.php | 8 + modules/tag/helpers/tag_menu.php | 28 ---- modules/user/helpers/user_event.php | 8 + modules/user/helpers/user_menu.php | 28 ---- modules/watermark/helpers/watermark_event.php | 29 ++++ modules/watermark/helpers/watermark_menu.php | 29 ---- 27 files changed, 426 insertions(+), 656 deletions(-) delete mode 100644 modules/akismet/helpers/akismet_menu.php delete mode 100644 modules/comment/helpers/comment_menu.php create mode 100644 modules/digibug/helpers/digibug_event.php delete mode 100644 modules/digibug/helpers/digibug_menu.php delete mode 100644 modules/g2_import/helpers/g2_import_menu.php delete mode 100644 modules/gallery/helpers/gallery_menu.php delete mode 100644 modules/notification/helpers/notification_menu.php create mode 100644 modules/organize/helpers/organize_event.php delete mode 100644 modules/organize/helpers/organize_menu.php delete mode 100644 modules/recaptcha/helpers/recaptcha_menu.php create mode 100644 modules/server_add/helpers/server_add_event.php delete mode 100644 modules/server_add/helpers/server_add_menu.php delete mode 100644 modules/slideshow/helpers/slideshow_menu.php delete mode 100644 modules/tag/helpers/tag_menu.php delete mode 100644 modules/user/helpers/user_menu.php create mode 100644 modules/watermark/helpers/watermark_event.php delete mode 100644 modules/watermark/helpers/watermark_menu.php (limited to 'modules/notification/helpers') diff --git a/modules/akismet/helpers/akismet_event.php b/modules/akismet/helpers/akismet_event.php index bffc0fd7..d6cde222 100644 --- a/modules/akismet/helpers/akismet_event.php +++ b/modules/akismet/helpers/akismet_event.php @@ -51,4 +51,20 @@ class akismet_event_Core { akismet::submit_ham($new); } } + + static function admin_menu($menu, $theme) { + $menu->get("settings_menu") + ->append(Menu::factory("link") + ->id("akismet") + ->label(t("Akismet")) + ->url(url::site("admin/akismet"))); + + if (module::get_var("akismet", "api_key")) { + $menu->get("statistics_menu") + ->append(Menu::factory("link") + ->id("akismet") + ->label(t("Akismet")) + ->url(url::site("admin/akismet/stats"))); + } + } } diff --git a/modules/akismet/helpers/akismet_menu.php b/modules/akismet/helpers/akismet_menu.php deleted file mode 100644 index ebd948d6..00000000 --- a/modules/akismet/helpers/akismet_menu.php +++ /dev/null @@ -1,36 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("akismet") - ->label(t("Akismet")) - ->url(url::site("admin/akismet"))); - - if (module::get_var("akismet", "api_key")) { - $menu->get("statistics_menu") - ->append(Menu::factory("link") - ->id("akismet") - ->label(t("Akismet")) - ->url(url::site("admin/akismet/stats"))); - } - } -} diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index 3850a001..614c7c65 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -21,4 +21,21 @@ class comment_event_Core { static function item_deleted($item) { Database::instance()->delete("comments", array("item_id" => $item->id)); } + + static function admin_menu($menu, $theme) { + $menu->get("content_menu") + ->append(Menu::factory("link") + ->id("comments") + ->label(t("Comments")) + ->url(url::site("admin/comments"))); + } + + static function photo_menu($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("comments") + ->label(t("View comments on this item")) + ->url("#comments") + ->css_id("gCommentsLink")); + } } diff --git a/modules/comment/helpers/comment_menu.php b/modules/comment/helpers/comment_menu.php deleted file mode 100644 index 01881921..00000000 --- a/modules/comment/helpers/comment_menu.php +++ /dev/null @@ -1,37 +0,0 @@ -get("content_menu") - ->append(Menu::factory("link") - ->id("comments") - ->label(t("Comments")) - ->url(url::site("admin/comments"))); - } - - static function photo($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("comments") - ->label(t("View comments on this item")) - ->url("#comments") - ->css_id("gCommentsLink")); - } -} diff --git a/modules/digibug/helpers/digibug_event.php b/modules/digibug/helpers/digibug_event.php new file mode 100644 index 00000000..c4f9e560 --- /dev/null +++ b/modules/digibug/helpers/digibug_event.php @@ -0,0 +1,50 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("digibug_menu") + ->label(t("Digibug")) + ->url(url::site("admin/digibug"))); + } + + static function photo_menu($menu, $theme) { + $item = $theme->item(); + $menu->append( + Menu::factory("link") + ->id("digibug") + ->label(t("Print with Digibug")) + ->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf")) + ->css_id("gDigibugLink")); + } + + static function thumb_menu($menu, $theme, $item) { + if ($item->type == "photo") { + $menu->get("options_menu") + ->append( + Menu::factory("link") + ->id("digibug") + ->label(t("Print with Digibug")) + ->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf")) + ->css_id("gDigibugLink")); + } + } +} diff --git a/modules/digibug/helpers/digibug_menu.php b/modules/digibug/helpers/digibug_menu.php deleted file mode 100644 index 3f70fa24..00000000 --- a/modules/digibug/helpers/digibug_menu.php +++ /dev/null @@ -1,50 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("digibug_menu") - ->label(t("Digibug")) - ->url(url::site("admin/digibug"))); - } - - static function photo($menu, $theme) { - $item = $theme->item(); - $menu->append( - Menu::factory("link") - ->id("digibug") - ->label(t("Print with Digibug")) - ->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf")) - ->css_id("gDigibugLink")); - } - - static function thumb($menu, $theme, $item) { - if ($item->type == "photo") { - $menu->get("options_menu") - ->append( - Menu::factory("link") - ->id("digibug") - ->label(t("Print with Digibug")) - ->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf")) - ->css_id("gDigibugLink")); - } - } -} diff --git a/modules/g2_import/helpers/g2_import_event.php b/modules/g2_import/helpers/g2_import_event.php index 77b489a7..609e1a45 100644 --- a/modules/g2_import/helpers/g2_import_event.php +++ b/modules/g2_import/helpers/g2_import_event.php @@ -25,4 +25,13 @@ class g2_import_event_Core { static function item_created($item) { g2_import::copy_matching_thumbnails_and_resizes($item); } + + static function admin_menu($menu, $theme) { + $menu + ->get("settings_menu") + ->append(Menu::factory("link") + ->id("g2_import") + ->label(t("Gallery 2 Import")) + ->url(url::site("admin/g2_import"))); + } } diff --git a/modules/g2_import/helpers/g2_import_menu.php b/modules/g2_import/helpers/g2_import_menu.php deleted file mode 100644 index 68d75cb4..00000000 --- a/modules/g2_import/helpers/g2_import_menu.php +++ /dev/null @@ -1,29 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("g2_import") - ->label(t("Gallery 2 Import")) - ->url(url::site("admin/g2_import"))); - } -} diff --git a/modules/gallery/helpers/gallery_menu.php b/modules/gallery/helpers/gallery_menu.php deleted file mode 100644 index 040b19e1..00000000 --- a/modules/gallery/helpers/gallery_menu.php +++ /dev/null @@ -1,164 +0,0 @@ -append(Menu::factory("link") - ->id("home") - ->label(t("Home")) - ->url(url::site("albums/1"))); - - $item = $theme->item(); - - $can_edit = $item && access::can("edit", $item); - $can_add = $item && access::can("add", $item); - - if ($can_add) { - $menu->append(Menu::factory("dialog") - ->id("add_photos_item") - ->label(t("Add photos")) - ->url(url::site("simple_uploader/app/$item->id"))); - } - - $menu->append($options_menu = Menu::factory("submenu") - ->id("options_menu") - ->label(t("Options"))); - if ($item && ($can_edit || $can_add)) { - if ($can_edit) { - $options_menu - ->append(Menu::factory("dialog") - ->id("edit_item") - ->label($item->is_album() ? t("Edit album") : t("Edit photo")) - ->url(url::site("form/edit/{$item->type}s/$item->id"))); - } - - // @todo Move album options menu to the album quick edit pane - if ($item->is_album()) { - if ($can_add) { - $options_menu - ->append(Menu::factory("dialog") - ->id("add_album") - ->label(t("Add an album")) - ->url(url::site("form/add/albums/$item->id?type=album"))); - } - - if ($can_edit) { - $options_menu - ->append(Menu::factory("dialog") - ->id("edit_permissions") - ->label(t("Edit permissions")) - ->url(url::site("permissions/browse/$item->id"))); - } - } - } - - if (user::active()->admin) { - $menu->append($admin_menu = Menu::factory("submenu") - ->id("admin_menu") - ->label(t("Admin"))); - self::admin($admin_menu, $theme); - foreach (module::active() as $module) { - if ($module->name == "gallery") { - continue; - } - $class = "{$module->name}_menu"; - if (method_exists($class, "admin")) { - call_user_func_array(array($class, "admin"), array(&$admin_menu, $theme)); - } - } - } - } - - static function album($menu, $theme) { - } - - static function tag($menu, $theme) { - } - - static function thumb($menu, $theme, $item) { - $menu->append(Menu::factory("submenu") - ->id("options_menu") - ->label(t("Options")) - ->css_class("gThumbMenu")); - } - - static function photo($menu, $theme) { - if (access::can("view_full", $theme->item())) { - $menu->append(Menu::factory("link") - ->id("fullsize") - ->label(t("View full size")) - ->url($theme->item()->file_url()) - ->css_class("gFullSizeLink")); - } - } - - static function admin($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("dashboard") - ->label(t("Dashboard")) - ->url(url::site("admin"))) - ->append(Menu::factory("submenu") - ->id("settings_menu") - ->label(t("Settings")) - ->append(Menu::factory("link") - ->id("graphics_toolkits") - ->label(t("Graphics")) - ->url(url::site("admin/graphics"))) - ->append(Menu::factory("link") - ->id("languages") - ->label(t("Languages")) - ->url(url::site("admin/languages"))) - ->append(Menu::factory("link") - ->id("l10n_mode") - ->label(Session::instance()->get("l10n_mode", false) - ? t("Stop translating") : t("Start translating")) - ->url(url::site("l10n_client/toggle_l10n_mode?csrf=" . - access::csrf_token()))) - ->append(Menu::factory("link") - ->id("advanced") - ->label(t("Advanced")) - ->url(url::site("admin/advanced_settings")))) - ->append(Menu::factory("link") - ->id("modules") - ->label(t("Modules")) - ->url(url::site("admin/modules"))) - ->append(Menu::factory("submenu") - ->id("content_menu") - ->label(t("Content"))) - ->append(Menu::factory("submenu") - ->id("appearance_menu") - ->label(t("Appearance")) - ->append(Menu::factory("link") - ->id("themes") - ->label(t("Theme Choice")) - ->url(url::site("admin/themes"))) - ->append(Menu::factory("link") - ->id("theme_options") - ->label(t("Theme Options")) - ->url(url::site("admin/theme_options")))) - ->append(Menu::factory("submenu") - ->id("statistics_menu") - ->label(t("Statistics"))) - ->append(Menu::factory("link") - ->id("maintenance") - ->label(t("Maintenance")) - ->url(url::site("admin/maintenance"))); - } -} diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index 47770a90..2a48d1e3 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -44,22 +44,66 @@ class Admin_View_Core extends Gallery_View { $this->set_global("user", user::active()); } - public function admin_menu() { - $menu = Menu::factory("root"); - gallery_menu::admin($menu, $this); - - foreach (module::active() as $module) { - if ($module->name == "gallery") { - continue; - } - $class = "{$module->name}_menu"; - if (method_exists($class, "admin")) { - call_user_func_array(array($class, "admin"), array(&$menu, $this)); - } + public function admin_menu($menu=null) { + if (!$menu) { + $menu = Menu::factory("root"); } + $menu + ->append(Menu::factory("link") + ->id("dashboard") + ->label(t("Dashboard")) + ->url(url::site("admin"))) + ->append(Menu::factory("submenu") + ->id("settings_menu") + ->label(t("Settings")) + ->append(Menu::factory("link") + ->id("graphics_toolkits") + ->label(t("Graphics")) + ->url(url::site("admin/graphics"))) + ->append(Menu::factory("link") + ->id("languages") + ->label(t("Languages")) + ->url(url::site("admin/languages"))) + ->append(Menu::factory("link") + ->id("l10n_mode") + ->label(Session::instance()->get("l10n_mode", false) + ? t("Stop translating") : t("Start translating")) + ->url(url::site("l10n_client/toggle_l10n_mode?csrf=" . + access::csrf_token()))) + ->append(Menu::factory("link") + ->id("advanced") + ->label(t("Advanced")) + ->url(url::site("admin/advanced_settings")))) + ->append(Menu::factory("link") + ->id("modules") + ->label(t("Modules")) + ->url(url::site("admin/modules"))) + ->append(Menu::factory("submenu") + ->id("content_menu") + ->label(t("Content"))) + ->append(Menu::factory("submenu") + ->id("appearance_menu") + ->label(t("Appearance")) + ->append(Menu::factory("link") + ->id("themes") + ->label(t("Theme Choice")) + ->url(url::site("admin/themes"))) + ->append(Menu::factory("link") + ->id("theme_options") + ->label(t("Theme Options")) + ->url(url::site("admin/theme_options")))) + ->append(Menu::factory("submenu") + ->id("statistics_menu") + ->label(t("Statistics"))) + ->append(Menu::factory("link") + ->id("maintenance") + ->label(t("Maintenance")) + ->url(url::site("admin/maintenance"))); + + module::event("admin_menu", $menu, $this); $menu->compact(); - print $menu; + return $menu; } /** diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index fa45ec89..60471f75 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -81,52 +81,103 @@ class Theme_View_Core extends Gallery_View { public function site_menu() { $menu = Menu::factory("root"); if ($this->page_type != "login") { - gallery_menu::site($menu, $this); + $menu->append(Menu::factory("link") + ->id("home") + ->label(t("Home")) + ->url(url::site("albums/1"))); - foreach (module::active() as $module) { - if ($module->name == "gallery") { - continue; + $item = $this->item(); + + $can_edit = $item && access::can("edit", $item); + $can_add = $item && access::can("add", $item); + + if ($can_add) { + $menu->append(Menu::factory("dialog") + ->id("add_photos_item") + ->label(t("Add photos")) + ->url(url::site("simple_uploader/app/$item->id"))); + } + + $menu->append($options_menu = Menu::factory("submenu") + ->id("options_menu") + ->label(t("Options"))); + if ($item && ($can_edit || $can_add)) { + if ($can_edit) { + $options_menu + ->append(Menu::factory("dialog") + ->id("edit_item") + ->label($item->is_album() ? t("Edit album") : t("Edit photo")) + ->url(url::site("form/edit/{$item->type}s/$item->id"))); } - $class = "{$module->name}_menu"; - if (method_exists($class, "site")) { - call_user_func_array(array($class, "site"), array(&$menu, $this)); + + // @todo Move album options menu to the album quick edit pane + if ($item->is_album()) { + if ($can_add) { + $options_menu + ->append(Menu::factory("dialog") + ->id("add_album") + ->label(t("Add an album")) + ->url(url::site("form/add/albums/$item->id?type=album"))); + } + + if ($can_edit) { + $options_menu + ->append(Menu::factory("dialog") + ->id("edit_permissions") + ->label(t("Edit permissions")) + ->url(url::site("permissions/browse/$item->id"))); + } } } + + if (user::active()->admin) { + $menu->append($admin_menu = Menu::factory("submenu") + ->id("admin_menu") + ->label(t("Admin"))); + Admin_View::admin_menu($admin_menu, $this); + module::event("admin_menu", $admin_menu, $this); + } + + module::event("site_menu", $menu, $this); } - $menu->compact(); - print $menu; + return $menu->compact(); } public function album_menu() { - print $this->_menu("album"); + $menu = Menu::factory("root"); + module::event("album_menu", $menu, $this); + return $menu->compact(); } public function tag_menu() { - print $this->_menu("tag"); + $menu = Menu::factory("root"); + module::event("tag_menu", $menu, $this); + return $menu->compact(); } public function photo_menu() { - print $this->_menu("photo"); - } + $menu = Menu::factory("root"); + if (access::can("view_full", $this->item())) { + $menu->append(Menu::factory("link") + ->id("fullsize") + ->label(t("View full size")) + ->url($this->item()->file_url()) + ->css_class("gFullSizeLink")); + } - public function thumb_menu($item) { - print $this->_menu("thumb", $item)->css_class("gThumbMenu"); + module::event("photo_menu", $menu, $this); + return $menu->compact(); } - private function _menu($type, $item=null) { - $menu = Menu::factory("root"); - call_user_func_array(array("gallery_menu", $type), array(&$menu, $this, $item)); - foreach (module::active() as $module) { - if ($module->name == "gallery") { - continue; - } - $class = "{$module->name}_menu"; - if (method_exists($class, $type)) { - call_user_func_array(array($class, $type), array(&$menu, $this, $item)); - } - } + public function thumb_menu($item) { + $menu = Menu::factory("root") + ->append(Menu::factory("submenu") + ->id("options_menu") + ->label(t("Options")) + ->css_class("gThumbMenu")); + module::event("thumb_menu", $menu, $this, $item); return $menu->compact(); } diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index 536557c6..c6e770a7 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -55,4 +55,23 @@ class notification_event_Core { static function batch_complete() { notification::send_pending_notifications(); } + + static function site_menu($menu, $theme) { + if (!user::active()->guest) { + $item = $theme->item(); + + if ($item && $item->is_album() && access::can("view", $item)) { + $watching = notification::is_watching($item); + + $label = $watching ? t("Remove notifications") : t("Enable notifications"); + + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("watch") + ->label($label) + ->css_id("gNotifyLink") + ->url(url::site("notification/watch/$item->id?csrf=" . access::csrf_token()))); + } + } + } } \ No newline at end of file diff --git a/modules/notification/helpers/notification_menu.php b/modules/notification/helpers/notification_menu.php deleted file mode 100644 index 73d1dd03..00000000 --- a/modules/notification/helpers/notification_menu.php +++ /dev/null @@ -1,39 +0,0 @@ -guest) { - $item = $theme->item(); - - if ($item && $item->is_album() && access::can("view", $item)) { - $watching = notification::is_watching($item); - - $label = $watching ? t("Remove notifications") : t("Enable notifications"); - - $menu->get("options_menu") - ->append(Menu::factory("link") - ->id("watch") - ->label($label) - ->css_id("gNotifyLink") - ->url(url::site("notification/watch/$item->id?csrf=" . access::csrf_token()))); - } - } - } -} diff --git a/modules/organize/helpers/organize_event.php b/modules/organize/helpers/organize_event.php new file mode 100644 index 00000000..99a28673 --- /dev/null +++ b/modules/organize/helpers/organize_event.php @@ -0,0 +1,33 @@ +item(); + + if ($item && access::can("edit", $item) && $item->is_album()) { + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("organize") + ->label(t("Organize Album")) + ->css_id("gOrganizeLink") + ->url(url::site("organize/index/{$item->id}"))); + } + } +} diff --git a/modules/organize/helpers/organize_menu.php b/modules/organize/helpers/organize_menu.php deleted file mode 100644 index 850c1eab..00000000 --- a/modules/organize/helpers/organize_menu.php +++ /dev/null @@ -1,33 +0,0 @@ -item(); - - if ($item && access::can("edit", $item) && $item->is_album()) { - $menu->get("options_menu") - ->append(Menu::factory("link") - ->id("organize") - ->label(t("Organize Album")) - ->css_id("gOrganizeLink") - ->url(url::site("organize/index/{$item->id}"))); - } - } -} diff --git a/modules/recaptcha/helpers/recaptcha_event.php b/modules/recaptcha/helpers/recaptcha_event.php index 932ddee6..d23a0c74 100644 --- a/modules/recaptcha/helpers/recaptcha_event.php +++ b/modules/recaptcha/helpers/recaptcha_event.php @@ -23,4 +23,12 @@ class recaptcha_event_Core { $form->add_comment->recaptcha("recaptcha")->label("")->id("gRecaptcha"); } } + + static function admin_menu($menu, $theme) { + $menu->get("settings_menu") + ->append(Menu::factory("link") + ->id("recaptcha") + ->label(t("reCAPTCHA")) + ->url(url::site("admin/recaptcha"))); + } } diff --git a/modules/recaptcha/helpers/recaptcha_menu.php b/modules/recaptcha/helpers/recaptcha_menu.php deleted file mode 100644 index 047abf8f..00000000 --- a/modules/recaptcha/helpers/recaptcha_menu.php +++ /dev/null @@ -1,28 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("recaptcha") - ->label(t("reCAPTCHA")) - ->url(url::site("admin/recaptcha"))); - } -} diff --git a/modules/server_add/helpers/server_add_event.php b/modules/server_add/helpers/server_add_event.php new file mode 100644 index 00000000..b53e72d1 --- /dev/null +++ b/modules/server_add/helpers/server_add_event.php @@ -0,0 +1,64 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("server_add") + ->label(t("Server Add")) + ->url(url::site("admin/server_add"))); + } + + static function site_menu($menu, $theme) { + $item = $theme->item(); + $paths = unserialize(module::get_var("server_add", "authorized_paths")); + + if ($item && user::active()->admin && $item->is_album() && !empty($paths)) { + // This is a little tricky. Normally there's an "Add Photo" menu option, but we want to + // turn that into a dropdown if there are two different ways to add things. Do that in a + // portable way for now. If we find ourselves duplicating this pattern, we should make an + // API method for this. + $server_add = Menu::factory("dialog") + ->id("server_add") + ->label(t("Add from server")) + ->url(url::site("server_add/browse/$item->id")); + $add_photos_item = $menu->get("add_photos_item"); + $add_photos_menu = $menu->get("add_photos_menu"); + + if ($add_photos_item && !$add_photos_menu) { + // Assuming that $add_menu is unset, create add_menu and add our item + $menu->add_after( + "add_photos_item", + Menu::factory("submenu") + ->id("add_photos_menu") + ->label($add_photos_item->label) + ->append(Menu::factory("dialog") + ->id("add_photos_submenu_item") + ->label(t("Simple Uploader")) + ->url($add_photos_item->url)) + ->append($server_add)); + $menu->remove("add_photos_item"); + } else if ($add_photos_menu) { + // Append to the existing sub-menu + $add_photos_menu->append($server_add); + } + } + } +} diff --git a/modules/server_add/helpers/server_add_menu.php b/modules/server_add/helpers/server_add_menu.php deleted file mode 100644 index 0f01eb64..00000000 --- a/modules/server_add/helpers/server_add_menu.php +++ /dev/null @@ -1,64 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("server_add") - ->label(t("Server Add")) - ->url(url::site("admin/server_add"))); - } - - static function site($menu, $theme) { - $item = $theme->item(); - $paths = unserialize(module::get_var("server_add", "authorized_paths")); - - if ($item && user::active()->admin && $item->is_album() && !empty($paths)) { - // This is a little tricky. Normally there's an "Add Photo" menu option, but we want to - // turn that into a dropdown if there are two different ways to add things. Do that in a - // portable way for now. If we find ourselves duplicating this pattern, we should make an - // API method for this. - $server_add = Menu::factory("dialog") - ->id("server_add") - ->label(t("Add from server")) - ->url(url::site("server_add/browse/$item->id")); - $add_photos_item = $menu->get("add_photos_item"); - $add_photos_menu = $menu->get("add_photos_menu"); - - if ($add_photos_item && !$add_photos_menu) { - // Assuming that $add_menu is unset, create add_menu and add our item - $menu->add_after( - "add_photos_item", - Menu::factory("submenu") - ->id("add_photos_menu") - ->label($add_photos_item->label) - ->append(Menu::factory("dialog") - ->id("add_photos_submenu_item") - ->label(t("Simple Uploader")) - ->url($add_photos_item->url)) - ->append($server_add)); - $menu->remove("add_photos_item"); - } else if ($add_photos_menu) { - // Append to the existing sub-menu - $add_photos_menu->append($server_add); - } - } - } -} diff --git a/modules/slideshow/helpers/slideshow_event.php b/modules/slideshow/helpers/slideshow_event.php index c6cd7dc7..cf79f71a 100644 --- a/modules/slideshow/helpers/slideshow_event.php +++ b/modules/slideshow/helpers/slideshow_event.php @@ -29,4 +29,34 @@ class slideshow_event_Core { site_status::clear("slideshow_needs_rss"); } } + + static function album_menu($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("slideshow") + ->label(t("View slideshow")) + ->url("javascript:PicLensLite.start(" . + "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") + ->css_id("gSlideshowLink")); + } + + static function photo_menu($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("slideshow") + ->label(t("View slideshow")) + ->url("javascript:PicLensLite.start(" . + "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") + ->css_id("gSlideshowLink")); + } + + static function tag_menu($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("slideshow") + ->label(t("View slideshow")) + ->url("javascript:PicLensLite.start(" . + "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") + ->css_id("gSlideshowLink")); + } } diff --git a/modules/slideshow/helpers/slideshow_menu.php b/modules/slideshow/helpers/slideshow_menu.php deleted file mode 100644 index ee975d88..00000000 --- a/modules/slideshow/helpers/slideshow_menu.php +++ /dev/null @@ -1,51 +0,0 @@ -append(Menu::factory("link") - ->id("slideshow") - ->label(t("View slideshow")) - ->url("javascript:PicLensLite.start(" . - "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") - ->css_id("gSlideshowLink")); - } - - static function photo($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("slideshow") - ->label(t("View slideshow")) - ->url("javascript:PicLensLite.start(" . - "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") - ->css_id("gSlideshowLink")); - } - - static function tag($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("slideshow") - ->label(t("View slideshow")) - ->url("javascript:PicLensLite.start(" . - "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") - ->css_id("gSlideshowLink")); - } - -} diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index 0fe8a393..f5fa6d4c 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -85,4 +85,12 @@ class tag_event_Core { } tag::compact(); } + + static function admin_menu($menu, $theme) { + $menu->get("content_menu") + ->append(Menu::factory("link") + ->id("tags") + ->label(t("Tags")) + ->url(url::site("admin/tags"))); + } } diff --git a/modules/tag/helpers/tag_menu.php b/modules/tag/helpers/tag_menu.php deleted file mode 100644 index e1b61a93..00000000 --- a/modules/tag/helpers/tag_menu.php +++ /dev/null @@ -1,28 +0,0 @@ -get("content_menu") - ->append(Menu::factory("link") - ->id("tags") - ->label(t("Tags")) - ->url(url::site("admin/tags"))); - } -} diff --git a/modules/user/helpers/user_event.php b/modules/user/helpers/user_event.php index 6515fbfb..4bde224b 100644 --- a/modules/user/helpers/user_event.php +++ b/modules/user/helpers/user_event.php @@ -30,4 +30,12 @@ class user_event_Core { I18n::instance()->locale($locale); } } + + static function admin_menu($menu, $theme) { + $menu->add_after("appearance_menu", + Menu::factory("link") + ->id("users_groups") + ->label(t("Users/Groups")) + ->url(url::site("admin/users"))); + } } diff --git a/modules/user/helpers/user_menu.php b/modules/user/helpers/user_menu.php deleted file mode 100644 index 05e401f9..00000000 --- a/modules/user/helpers/user_menu.php +++ /dev/null @@ -1,28 +0,0 @@ -add_after("appearance_menu", - Menu::factory("link") - ->id("users_groups") - ->label(t("Users/Groups")) - ->url(url::site("admin/users"))); - } -} diff --git a/modules/watermark/helpers/watermark_event.php b/modules/watermark/helpers/watermark_event.php new file mode 100644 index 00000000..45b410f9 --- /dev/null +++ b/modules/watermark/helpers/watermark_event.php @@ -0,0 +1,29 @@ +get("content_menu") + ->append( + Menu::factory("link") + ->id("watermarks") + ->label(t("Watermarks")) + ->url(url::site("admin/watermarks"))); + } +} diff --git a/modules/watermark/helpers/watermark_menu.php b/modules/watermark/helpers/watermark_menu.php deleted file mode 100644 index bc3a4fed..00000000 --- a/modules/watermark/helpers/watermark_menu.php +++ /dev/null @@ -1,29 +0,0 @@ -get("content_menu") - ->append( - Menu::factory("link") - ->id("watermarks") - ->label(t("Watermarks")) - ->url(url::site("admin/watermarks"))); - } -} -- cgit v1.2.3 From 7ad0808a117fd1db4e94da8d7763ccca1d69350a Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 2 Aug 2009 12:09:00 -0700 Subject: Change the API for getting to the original state of an ORM. Old API: $obj->original("field_name") New API: $obj->original()->field_name This allows us to revert the varous xxx_updated events back to passing an original ORM as well as the the updated one. This makes for a cleaner event API. Old API: comment_updated($comment) { $comment->original("field_name") } Old API: comment_updated($old, $new) { $old->field_name } --- modules/akismet/helpers/akismet_event.php | 6 +++--- modules/comment/models/comment.php | 8 ++++---- modules/gallery/libraries/MY_ORM.php | 12 ++++++------ modules/gallery/models/item.php | 2 +- modules/gallery/tests/Item_Model_Test.php | 2 +- modules/notification/helpers/notification_event.php | 8 ++++---- modules/search/helpers/search_event.php | 4 ++-- modules/user/models/group.php | 2 +- modules/user/models/user.php | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) (limited to 'modules/notification/helpers') diff --git a/modules/akismet/helpers/akismet_event.php b/modules/akismet/helpers/akismet_event.php index d6cde222..cec6d95d 100644 --- a/modules/akismet/helpers/akismet_event.php +++ b/modules/akismet/helpers/akismet_event.php @@ -40,14 +40,14 @@ class akismet_event_Core { $comment->save(); } - static function comment_updated($comment) { + static function comment_updated($original, $new) { if (!module::get_var("akismet", "api_key")) { return; } - if ($comment->original("state") != "spam" && $comment->state == "spam") { + if ($original->state != "spam" && $new->state == "spam") { akismet::submit_spam($new); - } else if ($comment->original("state") == "spam" && $comment->state != "spam") { + } else if ($original->state == "spam" && $new->state != "spam") { akismet::submit_ham($new); } } diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index d052a39c..83d0888a 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -64,17 +64,17 @@ class Comment_Model extends ORM { $created = true; } } + $visible_change = $this->original()->state == "published" || $this->state == "published"; parent::save(); if (isset($created)) { module::event("comment_created", $this); } else { - module::event("comment_updated", $this); + module::event("comment_updated", $this->original(), $this); } - // We only notify on the related items if we're making a visible change, which means moving in - // or out of a published state - if ($this->original("state") == "published" || $this->state == "published") { + // We only notify on the related items if we're making a visible change. + if ($visible_change) { module::event("item_related_update", $this->item()); } diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php index 1d3c1ef3..de8adc1d 100644 --- a/modules/gallery/libraries/MY_ORM.php +++ b/modules/gallery/libraries/MY_ORM.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class ORM extends ORM_Core { - // Track the original value of this ORM instance so that we can look it up in ORM::original() + // Track the original value of this ORM so that we can look it up in ORM::original() protected $original = null; public function open_paren() { @@ -34,13 +34,13 @@ class ORM extends ORM_Core { public function save() { model_cache::clear(); $result = parent::save(); - $this->original = $this->object; + $this->original = clone $this; return $result; } public function __set($column, $value) { if (!isset($this->original)) { - $this->original = $this->object; + $this->original = clone $this; } return parent::__set($column, $value); @@ -48,14 +48,14 @@ class ORM extends ORM_Core { public function __unset($column) { if (!isset($this->original)) { - $this->original = $this->object; + $this->original = clone $this; } return parent::__unset($column); } - public function original($column) { - return $this->original[$column]; + public function original() { + return $this->original; } } diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index b3c7998b..f3e6b8f3 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -365,7 +365,7 @@ class Item_Model extends ORM_MPTT { } parent::save(); if (isset($send_event)) { - module::event("item_updated", $this); + module::event("item_updated", $this->original(), $this); } return $this; } diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index c2773097..0940d076 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -147,7 +147,7 @@ class Item_Model_Test extends Unit_Test_Case { $item->save(); $item->title = "NEW_VALUE"; - $this->assert_same("ORIGINAL_VALUE", $item->original("title")); + $this->assert_same("ORIGINAL_VALUE", $item->original()->title); $this->assert_same("NEW_VALUE", $item->title); } } diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index c6e770a7..d1b76e93 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -18,8 +18,8 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class notification_event_Core { - static function item_updated($item) { - notification::send_item_updated($item); + static function item_updated($original, $new) { + notification::send_item_updated($new); } static function item_created($item) { @@ -40,8 +40,8 @@ class notification_event_Core { } } - static function comment_updated($item) { - if ($item->state == "published" && $item->original("state") != "published") { + static function comment_updated($original, $new) { + if ($new->state == "published" && $original->state != "published") { notification::send_comment_published($new); } } diff --git a/modules/search/helpers/search_event.php b/modules/search/helpers/search_event.php index 764fdd18..b65763af 100644 --- a/modules/search/helpers/search_event.php +++ b/modules/search/helpers/search_event.php @@ -22,8 +22,8 @@ class search_event_Core { search::update($item); } - static function item_updated($item) { - search::update($item); + static function item_updated($original, $new) { + search::update($new); } static function item_deleted($item) { diff --git a/modules/user/models/group.php b/modules/user/models/group.php index bb3fb58b..8af78012 100644 --- a/modules/user/models/group.php +++ b/modules/user/models/group.php @@ -41,7 +41,7 @@ class Group_Model extends ORM { if (isset($created)) { module::event("group_created", $this); } else { - module::event("group_updated", $this); + module::event("group_updated", $this->original(), $this); } return $this; } diff --git a/modules/user/models/user.php b/modules/user/models/user.php index def65a6f..4b43adff 100644 --- a/modules/user/models/user.php +++ b/modules/user/models/user.php @@ -68,7 +68,7 @@ class User_Model extends ORM { if (isset($created)) { module::event("user_created", $this); } else { - module::event("user_updated", $this); + module::event("user_updated", $this->original(), $this); } return $this; } -- cgit v1.2.3 From 4828db003f3ee505eb9e6d056cdb142da34b78ff Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 27 Aug 2009 15:47:54 -0700 Subject: Remove 'ENGINE=InnoDB' specification from tables that we create. Use the system's default table specification. Fixes ticket #597. --- installer/install.sql | 44 +++++++++++----------- modules/comment/helpers/comment_installer.php | 2 +- modules/digibug/helpers/digibug_installer.php | 2 +- modules/exif/helpers/exif_installer.php | 2 +- modules/g2_import/helpers/g2_import_installer.php | 2 +- modules/gallery/controllers/packager.php | 4 ++ modules/gallery/helpers/gallery_installer.php | 32 ++++++++-------- .../helpers/notification_installer.php | 4 +- modules/search/helpers/search_installer.php | 2 +- .../server_add/helpers/server_add_installer.php | 4 +- modules/tag/helpers/tag_installer.php | 4 +- modules/user/helpers/user_installer.php | 6 +-- modules/watermark/helpers/watermark_installer.php | 2 +- 13 files changed, 57 insertions(+), 53 deletions(-) (limited to 'modules/notification/helpers') diff --git a/installer/install.sql b/installer/install.sql index 48b504ba..21464379 100755 --- a/installer/install.sql +++ b/installer/install.sql @@ -11,7 +11,7 @@ CREATE TABLE {access_caches} ( `edit_2` binary(1) NOT NULL default '0', `add_2` binary(1) NOT NULL default '0', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +) 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}; @@ -29,7 +29,7 @@ CREATE TABLE {access_intents} ( `edit_2` binary(1) default NULL, `add_2` binary(1) default NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +) 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}; @@ -43,7 +43,7 @@ CREATE TABLE {caches} ( `cache` longblob, PRIMARY KEY (`id`), KEY `tags` (`tags`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {comments}; SET @saved_cs_client = @@character_set_client; @@ -72,7 +72,7 @@ CREATE TABLE {comments} ( `text` text, `updated` int(9) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {graphics_rules}; SET @saved_cs_client = @@character_set_client; @@ -86,7 +86,7 @@ CREATE TABLE {graphics_rules} ( `priority` int(9) NOT NULL, `target` varchar(32) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +) 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'); @@ -99,7 +99,7 @@ CREATE TABLE {groups} ( `special` tinyint(1) default '0', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +) 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); @@ -111,7 +111,7 @@ CREATE TABLE {groups_users} ( `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; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; INSERT INTO {groups_users} VALUES (1,1); INSERT INTO {groups_users} VALUES (1,2); @@ -129,7 +129,7 @@ CREATE TABLE {incoming_translations} ( PRIMARY KEY (`id`), UNIQUE KEY `key` (`key`,`locale`), KEY `locale_key` (`locale`,`key`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {items}; SET @saved_cs_client = @@character_set_client; @@ -171,7 +171,7 @@ CREATE TABLE {items} ( KEY `type` (`type`), KEY `random` (`rand_key`), KEY `weight` (`weight`) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +) 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}; @@ -184,7 +184,7 @@ CREATE TABLE {items_tags} ( PRIMARY KEY (`id`), KEY `tag_id` (`tag_id`,`id`), KEY `item_id` (`item_id`,`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {logs}; SET @saved_cs_client = @@character_set_client; @@ -200,7 +200,7 @@ CREATE TABLE {logs} ( `url` varchar(255) default NULL, `user_id` int(9) default '0', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {messages}; SET @saved_cs_client = @@character_set_client; @@ -212,7 +212,7 @@ CREATE TABLE {messages} ( `value` varchar(255) default NULL, PRIMARY KEY (`id`), UNIQUE KEY `key` (`key`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {modules}; SET @saved_cs_client = @@character_set_client; @@ -224,7 +224,7 @@ CREATE TABLE {modules} ( `version` int(9) default NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; +) AUTO_INCREMENT=10 DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; INSERT INTO {modules} VALUES (1,1,'gallery',10); INSERT INTO {modules} VALUES (2,1,'user',1); @@ -248,7 +248,7 @@ CREATE TABLE {outgoing_translations} ( PRIMARY KEY (`id`), UNIQUE KEY `key` (`key`,`locale`), KEY `locale_key` (`locale`,`key`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {permissions}; SET @saved_cs_client = @@character_set_client; @@ -259,7 +259,7 @@ CREATE TABLE {permissions} ( `name` varchar(64) default NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; +) 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'); @@ -276,7 +276,7 @@ CREATE TABLE {search_records} ( PRIMARY KEY (`id`), KEY `item_id` (`item_id`), FULLTEXT KEY `data` (`data`) -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +) 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}; @@ -287,7 +287,7 @@ CREATE TABLE {sessions} ( `data` text NOT NULL, `last_activity` int(10) unsigned NOT NULL, PRIMARY KEY (`session_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {tags}; SET @saved_cs_client = @@character_set_client; @@ -298,7 +298,7 @@ CREATE TABLE {tags} ( `count` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {tasks}; SET @saved_cs_client = @@character_set_client; @@ -316,7 +316,7 @@ CREATE TABLE {tasks} ( `updated` int(9) default NULL, PRIMARY KEY (`id`), KEY `owner_id` (`owner_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) DEFAULT CHARSET=utf8; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS {themes}; SET @saved_cs_client = @@character_set_client; @@ -327,7 +327,7 @@ CREATE TABLE {themes} ( `version` int(9) default NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +) 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); @@ -350,7 +350,7 @@ CREATE TABLE {users} ( PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`), UNIQUE KEY `hash` (`hash`) -) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; +) 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); @@ -364,7 +364,7 @@ CREATE TABLE {vars} ( `value` text, PRIMARY KEY (`id`), UNIQUE KEY `module_name` (`module_name`,`name`) -) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8; +) 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'); diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php index edf2427c..80594c16 100644 --- a/modules/comment/helpers/comment_installer.php +++ b/modules/comment/helpers/comment_installer.php @@ -44,7 +44,7 @@ class comment_installer { `text` text, `updated` int(9) NOT NULL, PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); block_manager::add("dashboard_center", "comment", "recent_comments"); module::set_var("comment", "spam_caught", 0); diff --git a/modules/digibug/helpers/digibug_installer.php b/modules/digibug/helpers/digibug_installer.php index 1cd78b44..7e8145d2 100644 --- a/modules/digibug/helpers/digibug_installer.php +++ b/modules/digibug/helpers/digibug_installer.php @@ -26,7 +26,7 @@ class digibug_installer { `request_date` TIMESTAMP NOT NULL DEFAULT current_timestamp, `item_id` int(9) NOT NULL, PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); module::set_var("digibug", "company_id", "3153"); module::set_var("digibug", "event_id", "8491"); diff --git a/modules/exif/helpers/exif_installer.php b/modules/exif/helpers/exif_installer.php index 0233f2bb..66226061 100644 --- a/modules/exif/helpers/exif_installer.php +++ b/modules/exif/helpers/exif_installer.php @@ -28,7 +28,7 @@ class exif_installer { `dirty` BOOLEAN default 1, PRIMARY KEY (`id`), KEY(`item_id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); module::set_version("exif", 1); } diff --git a/modules/g2_import/helpers/g2_import_installer.php b/modules/g2_import/helpers/g2_import_installer.php index 0f87da6c..feacb518 100644 --- a/modules/g2_import/helpers/g2_import_installer.php +++ b/modules/g2_import/helpers/g2_import_installer.php @@ -26,7 +26,7 @@ class g2_import_installer { `g3_id` int(9) NOT NULL, PRIMARY KEY (`id`), KEY (`g2_id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); module::set_version("g2_import", 1); mkdir(VARPATH . "modules/g2_import"); diff --git a/modules/gallery/controllers/packager.php b/modules/gallery/controllers/packager.php index 7b4d68f6..fbb1d07d 100644 --- a/modules/gallery/controllers/packager.php +++ b/modules/gallery/controllers/packager.php @@ -123,6 +123,10 @@ class Packager_Controller extends Controller { // Normalize dates $line = preg_replace("/,$root_created_timestamp,/", ",UNIX_TIMESTAMP(),", $line); $line = preg_replace("/,$root_updated_timestamp,/", ",UNIX_TIMESTAMP(),", $line); + + // Remove ENGINE= specifications + $line = preg_replace("/ENGINE=\S+ /", "", $line); + $buf .= $line; } $fd = fopen($sql_file, "wb"); diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index d12dad70..a212ef85 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -24,13 +24,13 @@ class gallery_installer { `id` int(9) NOT NULL auto_increment, `item_id` int(9), PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $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;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {caches} ( `id` int(9) NOT NULL auto_increment, @@ -40,7 +40,7 @@ class gallery_installer { `cache` longblob, PRIMARY KEY (`id`), KEY (`tags`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {graphics_rules} ( `id` int(9) NOT NULL auto_increment, @@ -51,7 +51,7 @@ class gallery_installer { `priority` int(9) NOT NULL, `target` varchar(32) NOT NULL, PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {incoming_translations} ( `id` int(9) NOT NULL auto_increment, @@ -63,7 +63,7 @@ class gallery_installer { PRIMARY KEY (`id`), UNIQUE KEY(`key`, `locale`), KEY `locale_key` (`locale`, `key`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {items} ( `id` int(9) NOT NULL auto_increment, @@ -100,7 +100,7 @@ class gallery_installer { KEY `type` (`type`), KEY `random` (`rand_key`), KEY `weight` (`weight` DESC)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {logs} ( `id` int(9) NOT NULL auto_increment, @@ -113,7 +113,7 @@ class gallery_installer { `url` varchar(255) default NULL, `user_id` int(9) default 0, PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {messages} ( `id` int(9) NOT NULL auto_increment, @@ -122,7 +122,7 @@ class gallery_installer { `value` varchar(255) default NULL, PRIMARY KEY (`id`), UNIQUE KEY(`key`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {modules} ( `id` int(9) NOT NULL auto_increment, @@ -131,7 +131,7 @@ class gallery_installer { `version` int(9) default NULL, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {outgoing_translations} ( `id` int(9) NOT NULL auto_increment, @@ -143,7 +143,7 @@ class gallery_installer { PRIMARY KEY (`id`), UNIQUE KEY(`key`, `locale`), KEY `locale_key` (`locale`, `key`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {permissions} ( `id` int(9) NOT NULL auto_increment, @@ -151,14 +151,14 @@ class gallery_installer { `name` varchar(64) default NULL, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("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;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {tasks} ( `id` int(9) NOT NULL auto_increment, @@ -173,7 +173,7 @@ class gallery_installer { `updated` int(9) default NULL, PRIMARY KEY (`id`), KEY (`owner_id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {themes} ( `id` int(9) NOT NULL auto_increment, @@ -181,7 +181,7 @@ class gallery_installer { `version` int(9) default NULL, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE {vars} ( `id` int(9) NOT NULL auto_increment, @@ -190,7 +190,7 @@ class gallery_installer { `value` text, PRIMARY KEY (`id`), UNIQUE KEY(`module_name`, `name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); foreach (array("albums", "logs", "modules", "resizes", "thumbs", "tmp", "uploads") as $dir) { @mkdir(VARPATH . $dir); @@ -284,7 +284,7 @@ class gallery_installer { `cache` text, PRIMARY KEY (`id`), KEY (`tags`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); module::set_version("gallery", $version = 4); } diff --git a/modules/notification/helpers/notification_installer.php b/modules/notification/helpers/notification_installer.php index 3d450258..aa2e09f7 100644 --- a/modules/notification/helpers/notification_installer.php +++ b/modules/notification/helpers/notification_installer.php @@ -27,14 +27,14 @@ class notification_installer { PRIMARY KEY (`id`), UNIQUE KEY (`item_id`, `user_id`), UNIQUE KEY (`user_id`, `item_id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE IF NOT EXISTS {pending_notifications} ( `id` int(9) NOT NULL auto_increment, `email` varchar(128) NOT NULL, `subject` varchar(255) NOT NULL, `text` text, PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); module::set_version("notification", 1); } diff --git a/modules/search/helpers/search_installer.php b/modules/search/helpers/search_installer.php index cd253be4..10d8211f 100644 --- a/modules/search/helpers/search_installer.php +++ b/modules/search/helpers/search_installer.php @@ -28,7 +28,7 @@ class search_installer { PRIMARY KEY (`id`), KEY(`item_id`), FULLTEXT INDEX (`data`)) - ENGINE=MyISAM DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); module::set_version("search", 1); } diff --git a/modules/server_add/helpers/server_add_installer.php b/modules/server_add/helpers/server_add_installer.php index cd278eb7..c3c1572d 100644 --- a/modules/server_add/helpers/server_add_installer.php +++ b/modules/server_add/helpers/server_add_installer.php @@ -27,7 +27,7 @@ class server_add_installer { `parent_id` int(9), `task_id` int(9) NOT NULL, PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); module::set_version("server_add", 3); server_add::check_config(); } @@ -40,7 +40,7 @@ class server_add_installer { `task_id` int(9) NOT NULL, `file` varchar(255) NOT NULL, PRIMARY KEY (`id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); module::set_version("server_add", $version = 2); } diff --git a/modules/tag/helpers/tag_installer.php b/modules/tag/helpers/tag_installer.php index 3c16e3f3..bcb830e4 100644 --- a/modules/tag/helpers/tag_installer.php +++ b/modules/tag/helpers/tag_installer.php @@ -26,7 +26,7 @@ class tag_installer { `count` int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE IF NOT EXISTS {items_tags} ( `id` int(9) NOT NULL auto_increment, @@ -35,7 +35,7 @@ class tag_installer { PRIMARY KEY (`id`), KEY(`tag_id`, `id`), KEY(`item_id`, `id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); module::set_version("tag", 1); } diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php index 1959d038..8ef4f13d 100644 --- a/modules/user/helpers/user_installer.php +++ b/modules/user/helpers/user_installer.php @@ -36,7 +36,7 @@ class user_installer { PRIMARY KEY (`id`), UNIQUE KEY(`hash`), UNIQUE KEY(`name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE IF NOT EXISTS {groups} ( `id` int(9) NOT NULL auto_increment, @@ -44,14 +44,14 @@ class user_installer { `special` BOOLEAN default 0, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $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`), UNIQUE KEY(`user_id`, `group_id`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); $everybody = group::create("Everybody"); $everybody->special = true; diff --git a/modules/watermark/helpers/watermark_installer.php b/modules/watermark/helpers/watermark_installer.php index 705b89d4..b3e91044 100644 --- a/modules/watermark/helpers/watermark_installer.php +++ b/modules/watermark/helpers/watermark_installer.php @@ -30,7 +30,7 @@ class watermark_installer { `mime_type` varchar(64) default NULL, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) - ENGINE=InnoDB DEFAULT CHARSET=utf8;"); + DEFAULT CHARSET=utf8;"); @mkdir(VARPATH . "modules/watermark"); module::set_version("watermark", 1); -- cgit v1.2.3 From 430b57578b048366f054743e47de1b66cebb574e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 28 Aug 2009 10:27:02 -0700 Subject: Wrap all the notification helpers call with a try catch that swallows the exceptions, so the exceptions don't interrupt the upstream processes --- .../notification/helpers/notification_event.php | 75 ++++++++++++++-------- 1 file changed, 47 insertions(+), 28 deletions(-) (limited to 'modules/notification/helpers') diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index d1b76e93..fd667ae8 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -18,60 +18,79 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class notification_event_Core { + // The assumption is that the exception was logged at a lower level, but we + // don't want to screw up the processing that was generating the notification + // so we don't pass the exception up the call stack static function item_updated($original, $new) { - notification::send_item_updated($new); + try { + notification::send_item_updated($new); + } catch (Exception $e) {} } static function item_created($item) { - notification::send_item_add($item); + try { + notification::send_item_add($item); + } catch (Exception $e) {} } static function item_deleted($item) { - notification::send_item_deleted($item); + try { + notification::send_item_deleted($item); - if (notification::is_watching($item)) { - notification::remove_watch($item); - } + if (notification::is_watching($item)) { + notification::remove_watch($item); + } + } catch (Exception $e) {} } static function comment_created($comment) { - if ($comment->state == "published") { - notification::send_comment_published($comment); - } + try { + if ($comment->state == "published") { + notification::send_comment_published($comment); + } + } catch (Exception $e) {} } static function comment_updated($original, $new) { - if ($new->state == "published" && $original->state != "published") { - notification::send_comment_published($new); - } + try { + if ($new->state == "published" && $original->state != "published") { + notification::send_comment_published($new); + } + } catch (Exception $e) {} } static function user_before_delete($user) { - ORM::factory("subscription") - ->where("user_id", $user->id) - ->delete_all(); + try { + ORM::factory("subscription") + ->where("user_id", $user->id) + ->delete_all(); + } catch (Exception $e) {} } static function batch_complete() { - notification::send_pending_notifications(); + try { + notification::send_pending_notifications(); + } catch (Exception $e) {} } static function site_menu($menu, $theme) { - if (!user::active()->guest) { - $item = $theme->item(); + try { + if (!user::active()->guest) { + $item = $theme->item(); - if ($item && $item->is_album() && access::can("view", $item)) { - $watching = notification::is_watching($item); + if ($item && $item->is_album() && access::can("view", $item)) { + $watching = notification::is_watching($item); - $label = $watching ? t("Remove notifications") : t("Enable notifications"); + $label = $watching ? t("Remove notifications") : t("Enable notifications"); - $menu->get("options_menu") - ->append(Menu::factory("link") - ->id("watch") - ->label($label) - ->css_id("gNotifyLink") - ->url(url::site("notification/watch/$item->id?csrf=" . access::csrf_token()))); + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("watch") + ->label($label) + ->css_id("gNotifyLink") + ->url(url::site("notification/watch/$item->id?csrf=" . access::csrf_token()))); + } } - } + } catch (Exception $e) {} } } \ No newline at end of file -- cgit v1.2.3 From 5133f93290e3ab0052909c27dcec05983c819ebe Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 28 Aug 2009 11:51:41 -0700 Subject: Don't record mail failures when we throw the exception, record them when we catch the exception instead. --- modules/gallery/libraries/Sendmail.php | 2 - .../notification/helpers/notification_event.php | 54 +++++++++++++--------- 2 files changed, 33 insertions(+), 23 deletions(-) (limited to 'modules/notification/helpers') diff --git a/modules/gallery/libraries/Sendmail.php b/modules/gallery/libraries/Sendmail.php index d6229e07..7bc21a67 100644 --- a/modules/gallery/libraries/Sendmail.php +++ b/modules/gallery/libraries/Sendmail.php @@ -86,8 +86,6 @@ class Sendmail_Core { $headers = implode($this->header_separator, $headers); $message = wordwrap($this->message, $this->line_length, "\n"); if (!$this->mail($to, $this->subject, $message, $headers)) { - Kohana::log("error", wordwrap("Sending mail failed:\nTo: $to\n $this->subject\n" . - "Headers: $headers\n $this->message")); throw new Exception("@todo SEND_MAIL_FAILED"); } return $this; diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index fd667ae8..8fbeda92 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -24,13 +24,17 @@ class notification_event_Core { static function item_updated($original, $new) { try { notification::send_item_updated($new); - } catch (Exception $e) {} + } catch (Exception $e) { + Kohana::log("error", "@todo notification_event::item_updated() failed"); + } } static function item_created($item) { try { notification::send_item_add($item); - } catch (Exception $e) {} + } catch (Exception $e) { + Kohana::log("error", "@todo notification_event::item_created() failed"); + } } static function item_deleted($item) { @@ -40,7 +44,9 @@ class notification_event_Core { if (notification::is_watching($item)) { notification::remove_watch($item); } - } catch (Exception $e) {} + } catch (Exception $e) { + Kohana::log("error", "@todo notification_event::item_deleted() failed"); + } } static function comment_created($comment) { @@ -48,7 +54,9 @@ class notification_event_Core { if ($comment->state == "published") { notification::send_comment_published($comment); } - } catch (Exception $e) {} + } catch (Exception $e) { + Kohana::log("error", "@todo notification_event::comment_created() failed"); + } } static function comment_updated($original, $new) { @@ -56,7 +64,9 @@ class notification_event_Core { if ($new->state == "published" && $original->state != "published") { notification::send_comment_published($new); } - } catch (Exception $e) {} + } catch (Exception $e) { + Kohana::log("error", "@todo notification_event::comment_updated() failed"); + } } static function user_before_delete($user) { @@ -64,33 +74,35 @@ class notification_event_Core { ORM::factory("subscription") ->where("user_id", $user->id) ->delete_all(); - } catch (Exception $e) {} + } catch (Exception $e) { + Kohana::log("error", "@todo notification_event::user_before_delete() failed"); + } } static function batch_complete() { try { notification::send_pending_notifications(); - } catch (Exception $e) {} + } catch (Exception $e) { + Kohana::log("error", "@todo notification_event::batch_complete() failed"); + } } static function site_menu($menu, $theme) { - try { - if (!user::active()->guest) { - $item = $theme->item(); + if (!user::active()->guest) { + $item = $theme->item(); - if ($item && $item->is_album() && access::can("view", $item)) { - $watching = notification::is_watching($item); + if ($item && $item->is_album() && access::can("view", $item)) { + $watching = notification::is_watching($item); - $label = $watching ? t("Remove notifications") : t("Enable notifications"); + $label = $watching ? t("Remove notifications") : t("Enable notifications"); - $menu->get("options_menu") - ->append(Menu::factory("link") - ->id("watch") - ->label($label) - ->css_id("gNotifyLink") - ->url(url::site("notification/watch/$item->id?csrf=" . access::csrf_token()))); - } + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("watch") + ->label($label) + ->css_id("gNotifyLink") + ->url(url::site("notification/watch/$item->id?csrf=" . access::csrf_token()))); } - } catch (Exception $e) {} + } } } \ No newline at end of file -- cgit v1.2.3 From 6dcfdb6432d556f43736d60de8f310f247868bfa Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 28 Aug 2009 12:42:37 -0700 Subject: Fix a bug in notification where were using get() instead of current() to get the first item in an ORM result set. --- modules/notification/helpers/notification.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/notification/helpers') diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 92c40d4f..d95b3060 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -153,7 +153,7 @@ class notification { ->where("email", $email) ->find_all(); if ($result->count() == 1) { - $pending = $result->get(); + $pending = $result->current(); Sendmail::factory() ->to($email) ->subject($pending->subject) -- cgit v1.2.3 From acce8cbafd1987c72b8e3c7be54e91473ab2a525 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 29 Aug 2009 08:47:44 -0700 Subject: Log the actual exception details, before swallowing the exception. --- modules/notification/helpers/notification_event.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules/notification/helpers') diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index 8fbeda92..c50b04c4 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -26,6 +26,7 @@ class notification_event_Core { notification::send_item_updated($new); } catch (Exception $e) { Kohana::log("error", "@todo notification_event::item_updated() failed"); + Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -34,6 +35,7 @@ class notification_event_Core { notification::send_item_add($item); } catch (Exception $e) { Kohana::log("error", "@todo notification_event::item_created() failed"); + Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -46,6 +48,7 @@ class notification_event_Core { } } catch (Exception $e) { Kohana::log("error", "@todo notification_event::item_deleted() failed"); + Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -56,6 +59,7 @@ class notification_event_Core { } } catch (Exception $e) { Kohana::log("error", "@todo notification_event::comment_created() failed"); + Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -66,6 +70,7 @@ class notification_event_Core { } } catch (Exception $e) { Kohana::log("error", "@todo notification_event::comment_updated() failed"); + Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -76,6 +81,7 @@ class notification_event_Core { ->delete_all(); } catch (Exception $e) { Kohana::log("error", "@todo notification_event::user_before_delete() failed"); + Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } @@ -84,6 +90,7 @@ class notification_event_Core { notification::send_pending_notifications(); } catch (Exception $e) { Kohana::log("error", "@todo notification_event::batch_complete() failed"); + Kohana::Log("error", $e->getMessage() . "\n" . $e->getTraceAsString()); } } -- cgit v1.2.3 From 2ca20e8ab17de6d53200c8ace0595f7a6e27bd27 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 8 Sep 2009 21:19:00 -0700 Subject: Check for subscribers *before* going through the process of creating and rendering the email message. Fixes ticket #724. --- modules/notification/helpers/notification.php | 39 ++++++++++++++++++++------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'modules/notification/helpers') diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index d95b3060..88d92b16 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -87,6 +87,11 @@ class notification { } static function send_item_updated($item) { + $subscribers = self::get_subscribers($item); + if (!$subscribers) { + return; + } + $v = new View("item_updated.html"); $v->item = $item; $v->subject = $item->is_album() ? @@ -95,10 +100,15 @@ class notification { t("Photo %title updated", array("title" => $item->original("title"))) : t("Movie %title updated", array("title" => $item->original("title")))); - self::_notify_subscribers($item, $v->render(), $v->subject); + self::_notify($subscribers, $item, $v->render(), $v->subject); } static function send_item_add($item) { + $subscribers = self::get_subscribers($item); + if (!$subscribers) { + return; + } + $parent = $item->parent(); $v = new View("item_added.html"); $v->item = $item; @@ -111,10 +121,15 @@ class notification { t("Movie %title added to %parent_title", array("title" => $item->title, "parent_title" => $parent->title))); - self::_notify_subscribers($item, $v->render(), $v->subject); + self::_notify($subscribers, $item, $v->render(), $v->subject); } static function send_item_deleted($item) { + $subscribers = self::get_subscribers($item); + if (!$subscribers) { + return; + } + $parent = $item->parent(); $v = new View("item_deleted.html"); $v->item = $item; @@ -127,11 +142,16 @@ class notification { : t("Movie %title removed from %parent_title", array("title" => $item->title, "parent_title" => $parent->title))); - self::_notify_subscribers($item, $v->render(), $v->subject); + self::_notify($subscribers, $item, $v->render(), $v->subject); } static function send_comment_published($comment) { $item = $comment->item(); + $subscribers = self::get_subscribers($item); + if (!$subscribers) { + return; + } + $v = new View("comment_published.html"); $v->comment = $comment; $v->subject = $item->is_album() ? @@ -140,7 +160,7 @@ class notification { t("A new comment was published for photo %title", array("title" => $item->title)) : t("A new comment was published for movie %title", array("title" => $item->title))); - self::_notify_subscribers($item, $v->render(), $v->subject); + self::_notify($subscribers, $item, $v->render(), $v->subject); } static function send_pending_notifications() { @@ -179,23 +199,22 @@ class notification { } } - private static function _notify_subscribers($item, $text, $subject) { - $users = self::get_subscribers($item); - if (!empty($users)) { + private static function _notify($subscribers, $item, $text, $subject) { + if (!empty($subscribers)) { if (!batch::in_progress()) { Sendmail::factory() - ->to($users) + ->to($subscribers) ->subject($subject) ->header("Mime-Version", "1.0") ->header("Content-type", "text/html; charset=utf-8") ->message($text) ->send(); } else { - foreach ($users as $user) { + foreach ($subscribers as $subscriber) { $pending = ORM::factory("pending_notification"); $pending->subject = $subject; $pending->text = $text; - $pending->email = $user; + $pending->email = $subscriber; $pending->save(); } } -- cgit v1.2.3