summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/controllers/scaffold.php10
-rw-r--r--core/controllers/simple_uploader.php8
-rw-r--r--core/helpers/batch.php24
-rw-r--r--modules/local_import/controllers/local_import.php11
-rw-r--r--modules/local_import/js/local_import.js10
-rw-r--r--modules/notification/helpers/notification.php109
-rw-r--r--modules/notification/helpers/notification_event.php22
-rw-r--r--modules/notification/helpers/notification_installer.php10
-rw-r--r--modules/notification/models/pending_notification.php21
-rw-r--r--modules/notification/views/batch_add.html.php11
10 files changed, 138 insertions, 98 deletions
diff --git a/core/controllers/scaffold.php b/core/controllers/scaffold.php
index bd4c1f22..76b4ff71 100644
--- a/core/controllers/scaffold.php
+++ b/core/controllers/scaffold.php
@@ -201,8 +201,7 @@ class Scaffold_Controller extends Template_Controller {
throw new Exception("@todo BAD_ALBUM");
}
- batch::operation("add", $parent);
-
+ batch::start();
cookie::set("add_photos_path", $path);
$photo_count = 0;
foreach (glob("$path/*.[Jj][Pp][Gg]") as $file) {
@@ -210,7 +209,7 @@ class Scaffold_Controller extends Template_Controller {
photo::create($parent, $file, basename($file), basename($file));
$photo_count++;
}
- batch::end_operation("add");
+ batch::stop();
if ($photo_count > 0) {
log::success("content", "(scaffold) Added $photo_count photos",
@@ -227,8 +226,7 @@ class Scaffold_Controller extends Template_Controller {
$test_images = glob(APPPATH . "tests/images/*.[Jj][Pp][Gg]");
- batch::operation("add", ORM::factory("item", 1));
-
+ batch::start();
$album_count = $photo_count = 0;
for ($i = 0; $i < $count; $i++) {
set_time_limit(30);
@@ -252,7 +250,7 @@ class Scaffold_Controller extends Template_Controller {
$photo_count++;
}
}
- batch::end_operation("add");
+ batch::stop();
if ($photo_count > 0) {
log::success("content", "(scaffold) Added $photo_count photos");
diff --git a/core/controllers/simple_uploader.php b/core/controllers/simple_uploader.php
index 38eb5c38..0e2368e2 100644
--- a/core/controllers/simple_uploader.php
+++ b/core/controllers/simple_uploader.php
@@ -40,6 +40,10 @@ class Simple_Uploader_Controller extends Controller {
print $v;
}
+ public function start() {
+ batch::start();
+ }
+
public function add_photo($id) {
$album = ORM::factory("item", $id);
access::required("edit", $album);
@@ -48,7 +52,6 @@ class Simple_Uploader_Controller extends Controller {
$file_validation = new Validation($_FILES);
$file_validation->add_rules("file", "upload::valid", "upload::type[gif,jpg,png,flv,mp4]");
if ($file_validation->validate()) {
- batch::operation("add", $album);
$temp_filename = upload::save("file");
$title = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds
$path_info = pathinfo($temp_filename);
@@ -65,8 +68,7 @@ class Simple_Uploader_Controller extends Controller {
}
public function finish() {
- batch::end_operation("add");
-
+ batch::stop();
print json_encode(array("result" => "success"));
}
}
diff --git a/core/helpers/batch.php b/core/helpers/batch.php
index 98523f30..23c9e196 100644
--- a/core/helpers/batch.php
+++ b/core/helpers/batch.php
@@ -17,24 +17,24 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-
class batch_Core {
- static function operation($name, $item) {
- if (!self::in_progress($name)) {
- Session::instance()->set("operation_$name", "1");
- module::event("operation", $name, $item);
- }
+ static function start() {
+ $session = Session::instance();
+ $session->set("batch_level", $session->get("batch_level", 0) + 1);
}
- static function end_operation($name) {
- if (self::in_progress($name)) {
- module::event("end_operation", $name);
- Session::instance()->set("operation_$name", null);
+ static function stop($name) {
+ $session = Session::instance();
+ $batch_level = $session->get("batch_level", 0) - 1;
+ if ($batch_level > 0) {
+ $session->set("batch_level", $batch_level);
+ } else {
+ $session->delete("batch_level");
+ module::event("batch_complete");
}
}
static function in_progress($name) {
- $value = Session::instance()->get("operation_$name", null);
- return !empty($value);
+ return Session::instance()->get("batch_level", 0) > 0;
}
}
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>