diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/local_import/controllers/local_import.php | 11 | ||||
-rw-r--r-- | modules/local_import/js/local_import.js | 10 | ||||
-rw-r--r-- | modules/notification/helpers/notification.php | 109 | ||||
-rw-r--r-- | modules/notification/helpers/notification_event.php | 22 | ||||
-rw-r--r-- | modules/notification/helpers/notification_installer.php | 10 | ||||
-rw-r--r-- | modules/notification/models/pending_notification.php | 21 | ||||
-rw-r--r-- | modules/notification/views/batch_add.html.php | 11 |
7 files changed, 117 insertions, 77 deletions
diff --git a/modules/local_import/controllers/local_import.php b/modules/local_import/controllers/local_import.php index 64483fb0..8a6ee78a 100644 --- a/modules/local_import/controllers/local_import.php +++ b/modules/local_import/controllers/local_import.php @@ -53,6 +53,10 @@ class Local_Import_Controller extends Controller { print $tree; } + function start() { + batch::start(); + } + function add_photo($id) { access::verify_csrf(); @@ -69,11 +73,9 @@ class Local_Import_Controller extends Controller { throw new Exception("@todo BAD_PATH"); } - batch::operation("add", $parent); - $source_path = $path[0]; // The first path corresponds to the source directory so we can just skip it. - for ($i = 1; $i < count($path); $i++) { + for ($i = 1; $i < count($path); $i++) { $source_path .= "/$path[$i]"; $pathinfo = pathinfo($source_path); set_time_limit(30); @@ -97,8 +99,7 @@ class Local_Import_Controller extends Controller { } public function finish() { - batch::end_operation("add"); - + batch::stop(); print json_encode(array("result" => "success")); } diff --git a/modules/local_import/js/local_import.js b/modules/local_import/js/local_import.js index ba9f63b0..c9645bfc 100644 --- a/modules/local_import/js/local_import.js +++ b/modules/local_import/js/local_import.js @@ -66,10 +66,18 @@ function do_import(submit, event) { var check_list = $("#gLocalImport :checkbox[checked]"); process_length = check_list.length; current = 0; + var base_url = $("#gLocalImport form :hidden[name='base_url']")[0].value; + $.ajax({async: false, + success: function(data, textStatus) { + document.location.reload(); + }, + dataType: "json", + type: "POST", + url: base_url + "local_import/start" + }); $.each(check_list, function () { process_checkbox(this); }); - var base_url = $("#gLocalImport form :hidden[name='base_url']")[0].value; $.ajax({async: false, success: function(data, textStatus) { document.location.reload(); diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 4d095888..6d8ffd64 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -83,24 +83,23 @@ class notification { } static function send_item_updated($old, $new) { - $body = new View("item_updated.html"); - $body->old = $old; - $body->new = $new; - $body->subject = $old->is_album() ? + $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, $body, $body->subject); + self::_notify_subscribers($old, $v->render(), $v->subject); } static function send_item_add($item) { - $body = new View("item_added.html"); - $body->item = $item; - $parent = $item->parent(); - $subject = $item->is_album() ? + $v = new View("item_added.html"); + $v->item = $item; + $v->subject = $item->is_album() ? t("Album %title added to %parent_title", array("title" => $item->title, "parent_title" => $parent->title)) : ($item->is_photo() ? @@ -109,25 +108,14 @@ class notification { : t("Movie %title added to %parent_title", array("title" => $item->title, "parent_title" => $parent->title))); - self::_notify_subscribers($item, $body, $subject); - } - - static function send_batch_add($parent_id) { - $parent = ORM::factory("item", $parent_id); - if ($parent->loaded) { - $body = new View("batch_add.html"); - $body->item = $parent; - - $subject = t("Album %title updated", array("title" => $parent->title)); - self::_notify_subscribers($parent, $body, $subject); - } + self::_notify_subscribers($item, $v->render(), $v->subject); } static function send_item_deleted($item) { - $body = new View("item_deleted.html"); - $body->item = $item; $parent = $item->parent(); - $subject = $item->is_album() ? + $v = new View("item_deleted.html"); + $v->item = $item; + $v->subject = $item->is_album() ? t("Album %title removed from %parent_title", array("title" => $item->title, "parent_title" => $parent->title)) : ($item->is_photo() ? @@ -136,37 +124,78 @@ class notification { : t("Movie %title removed from %parent_title", array("title" => $item->title, "parent_title" => $parent->title))); - self::_notify_subscribers($item, $body, $subject); + self::_notify_subscribers($item, $v->render(), $v->subject); } static function send_comment_published($comment) { - $body = new View("comment_published.html"); - $body->comment = $comment; - $item = $comment->item(); - $subject = $item->is_album() ? + $v = new View("comment_published.html"); + $v->comment = $comment; + $v->subject = $item->is_album() ? t("A new comment was published for album %title", array("title" => $item->title)) : ($item->is_photo() ? 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, $body, $subject); + self::_notify_subscribers($item, $v->render(), $v->subject); } - static function process_notifications() { - Kohana::log("error", "processing notifications in shutdown"); + static function send_pending_notifications() { + foreach (Database::instance() + ->select("DISTINCT email") + ->from("pending_notifications") + ->get() as $row) { + $email = $row->email; + $result = ORM::factory("pending_notification") + ->where("email", $email) + ->find_all(); + if ($result->count == 1) { + $pending = $result->get(); + Sendmail::factory() + ->to($email) + ->subject($pending->subject) + ->header("Mime-Version", "1.0") + ->header("Content-type", "text/html; charset=utf-8") + ->message($pending->body) + ->send(); + $pending->delete(); + } else { + $text = ""; + foreach ($result as $pending) { + $text .= $pending->text; + $pending->delete(); + } + Sendmail::factory() + ->to($email) + ->subject(t("Multiple events have occurred")) // @todo fix this terrible subject line + ->header("Mime-Version", "1.0") + ->header("Content-type", "text/html; charset=utf-8") + ->message($text) + ->send(); + } + } } - private static function _notify_subscribers($item, $body, $subject) { + private static function _notify_subscribers($item, $text, $subject) { $users = self::get_subscribers($item); if (!empty($users)) { - Sendmail::factory() - ->to($users) - ->subject($subject) - ->header("Mime-Version", "1.0") - ->header("Content-type", "text/html; charset=utf-8") - ->message($body->render()) - ->send(); + if (!batch::in_progress()) { + Sendmail::factory() + ->to($users) + ->subject($subject) + ->header("Mime-Version", "1.0") + ->header("Content-type", "text/html; charset=utf-8") + ->message($text) + ->send(); + } else { + foreach ($users as $user) { + $pending = ORM::factory("pending_notification"); + $pending->subject = $subject; + $pending->text = $text; + $pending->email = $user; + $pending->save(); + } + } } } } diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index dde328d8..4ea0be05 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -52,23 +52,7 @@ class notification_event_Core { ->delete_all(); } - static function operation($name, $item) { - if ($name == "add") { - $id = Session::instance()->get("notification_batch_item_id"); - if ($id && $item->id != $id) { - notification::send_batch_add($id); - } - Session::instance()->set("notification_batch_item_id", $item->id); - } + static function batch_complete() { + notification::send_pending_notifications(); } - - static function end_operation($name) { - if ($name == "add") { - $id = Session::instance()->get_once("notification_batch_item_id"); - if ($id) { - notification::send_batch_add($id); - } - } - } - -} +}
\ No newline at end of file diff --git a/modules/notification/helpers/notification_installer.php b/modules/notification/helpers/notification_installer.php index 473ae169..01b5a1c8 100644 --- a/modules/notification/helpers/notification_installer.php +++ b/modules/notification/helpers/notification_installer.php @@ -31,6 +31,13 @@ class notification_installer { UNIQUE KEY (`item_id`, `user_id`), UNIQUE KEY (`user_id`, `item_id`)) ENGINE=InnoDB 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;"); module::set_version("notification", 1); } @@ -39,7 +46,8 @@ class notification_installer { static function uninstall() { $db = Database::instance(); $db->query("DROP TABLE IF EXISTS {subscriptions};"); - + $db->query("DROP TABLE IF EXISTS {pending_notifications};"); + module::delete("notification"); } } diff --git a/modules/notification/models/pending_notification.php b/modules/notification/models/pending_notification.php new file mode 100644 index 00000000..d3fb3cf8 --- /dev/null +++ b/modules/notification/models/pending_notification.php @@ -0,0 +1,21 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Pending_Notification_Model extends ORM { +}
\ No newline at end of file diff --git a/modules/notification/views/batch_add.html.php b/modules/notification/views/batch_add.html.php deleted file mode 100644 index b13fcf01..00000000 --- a/modules/notification/views/batch_add.html.php +++ /dev/null @@ -1,11 +0,0 @@ -<?php defined("SYSPATH") or die("No direct script access.") ?> -<html> -<head> - <title><?= $subject ?> </title> -</head> -<body> - <h2><?= sprintf(t("New Photos, Movies or Albums have been added to %s."), $parent_title); ?></h2> - <p><?= sprintf(t("Click on the link below to view the additions"), $parent_title); ?></p> - <p><a href="<?= $url ?>"><?= t(here) ?></a><p> -</body> -</html> |