From 52ecdcdff2ffd37760c0d0edbe7cd2fcc62a47fc Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 27 Jun 2009 23:24:23 -0700 Subject: Implemented a Database driver for the Kohana Cache library. Rather then writing our own caching algorithm, we can leverage the Kohana library. This has the added advantage of allowing the administrator to replace the default caching with a 3rd party caching algorithm. --- modules/gallery/models/cache.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 modules/gallery/models/cache.php (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/cache.php b/modules/gallery/models/cache.php new file mode 100644 index 00000000..99e19a6e --- /dev/null +++ b/modules/gallery/models/cache.php @@ -0,0 +1,20 @@ + Date: Tue, 30 Jun 2009 08:21:00 -0700 Subject: Fix for #319. Created a new view "movieplayer.html.php", which is rendered by Item_Model::movie_img(). Changed movie.html.php to use movie_img to render the movie player link. --- modules/gallery/models/item.php | 15 +++++++-------- modules/gallery/views/movieplayer.html.php | 15 +++++++++++++++ themes/default/views/movie.html.php | 18 +----------------- 3 files changed, 23 insertions(+), 25 deletions(-) create mode 100644 modules/gallery/views/movieplayer.html.php (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 430119b5..51037073 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -492,14 +492,13 @@ class Item_Model extends ORM_MPTT { * @return string */ public function movie_img($extra_attrs) { - $attrs = array_merge($extra_attrs, - array("id" => "player", - "style" => "display:block;width:400px;height:300px") - ); - return html::anchor($this->file_url(true), "", $attrs) . - ""; + $v = new View("movieplayer.html"); + $v->attrs = array_merge($extra_attrs, + array("style" => "display:block;width:{$this->width}px;height:{$this->height}px")); + if (empty($v->attrs["id"])) { + $v->attrs["id"] = "gMovieId-{$this->id}"; + } + return $v; } /** diff --git a/modules/gallery/views/movieplayer.html.php b/modules/gallery/views/movieplayer.html.php new file mode 100644 index 00000000..e8cabd31 --- /dev/null +++ b/modules/gallery/views/movieplayer.html.php @@ -0,0 +1,15 @@ + +file_url(true), "", $attrs) ?> + diff --git a/themes/default/views/movie.html.php b/themes/default/views/movie.html.php index 134e3571..c2fb0e30 100644 --- a/themes/default/views/movie.html.php +++ b/themes/default/views/movie.html.php @@ -12,23 +12,7 @@ - - - + movie_img(array("class" => "gMovie", "id" => "gMovieId-{$item->id}")) ?>

title) ?>

-- cgit v1.2.3 From 04f02b49c5d524345bc916aad6e247c714177662 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 5 Jul 2009 17:38:49 -0700 Subject: Add task logging functionality. When a task runs, it creates a log that is stored in the persistant cache for 30 days. On the admin_maintenance page there is a new link for completed tasks "browse log". Clicking this will open a dialog box that has the the contents of the log displayed. The user can then view the log and close the dialog, or press the save button to download the log to their local machine. --- modules/gallery/controllers/admin_maintenance.php | 38 ++++++++++++++++++++++ modules/gallery/helpers/task.php | 2 ++ modules/gallery/models/task.php | 24 ++++++++++++++ modules/gallery/views/admin_maintenance.html.php | 5 +++ .../views/admin_maintenance_show_log.html.php | 19 +++++++++++ themes/admin_default/css/screen.css | 14 ++++++++ 6 files changed, 102 insertions(+) create mode 100644 modules/gallery/views/admin_maintenance_show_log.html.php (limited to 'modules/gallery/models') diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 7c5934a3..a65bd770 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -59,6 +59,8 @@ class Admin_Maintenance_Controller extends Admin_Controller { $view = new View("admin_maintenance_task.html"); $view->task = $task; + $task->log(t("Task %task_name started (task id %task_id)", + array("task_name" => $task->name, "task_id" => $task->id))); log::info("tasks", t("Task %task_name started (task id %task_id)", array("task_name" => $task->name, "task_id" => $task->id)), html::anchor("admin/maintenance", t("maintenance"))); @@ -79,12 +81,48 @@ class Admin_Maintenance_Controller extends Admin_Controller { $view = new View("admin_maintenance_task.html"); $view->task = $task; + $task->log(t("Task %task_name resumed (task id %task_id)", + array("task_name" => $task->name, "task_id" => $task->id))); log::info("tasks", t("Task %task_name resumed (task id %task_id)", array("task_name" => $task->name, "task_id" => $task->id)), html::anchor("admin/maintenance", t("maintenance"))); print $view; } + /** + * Show the task log + * @param string $task_id + */ + public function show_log($task_id) { + access::verify_csrf(); + + $task = ORM::factory("task", $task_id); + if (!$task->loaded) { + throw new Exception("@todo MISSING_TASK"); + } + $view = new View("admin_maintenance_show_log.html"); + $view->task = $task; + + print $view; + } + + /** + * Save the task log + * @param string $task_id + */ + public function save_log($task_id) { + access::verify_csrf(); + + $task = ORM::factory("task", $task_id); + if (!$task->loaded) { + throw new Exception("@todo MISSING_TASK"); + } + + header("Content-Type: application/text"); + header("Content-Disposition: filename=g2_import.txt"); + print $task->get_task_log(); + } + /** * Cancel a task. * @param string $task_id diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php index a8a004ab..79a7c93b 100644 --- a/modules/gallery/helpers/task.php +++ b/modules/gallery/helpers/task.php @@ -56,6 +56,8 @@ class task_Core { } $task->done = 1; $task->state = "cancelled"; + $task->log(t("Task %task_name cancelled (task id %task_id)", + array("task_name" => $task->name, "task_id" => $task->id))); $task->save(); return $task; diff --git a/modules/gallery/models/task.php b/modules/gallery/models/task.php index 9e3ae5c6..2e77a7a6 100644 --- a/modules/gallery/models/task.php +++ b/modules/gallery/models/task.php @@ -40,7 +40,31 @@ class Task_Model extends ORM { return parent::save(); } + public function delete() { + Cache::instance()->delete($this->_cache_key()); + return parent::save(); + } + public function owner() { return user::lookup($this->owner_id); } + + public function log($msg) { + $key = $this->_cache_key(); + $log = Cache::instance()->get($key); + + // Save for 30 days. + $log .= !empty($log) ? "\n" : ""; + Cache::instance()->set($key, "$log{$msg}", + array("task", "log", "import"), 2592000); + } + + public function get_task_log() { + $log_data = Cache::instance()->get($this->_cache_key()); + return $log_data !== null ? $log_data : false; + } + + private function _cache_key() { + return md5("$this->id; $this->name; $this->callback"); + } } \ No newline at end of file diff --git a/modules/gallery/views/admin_maintenance.html.php b/modules/gallery/views/admin_maintenance.html.php index c47f77f8..f50c95dd 100644 --- a/modules/gallery/views/admin_maintenance.html.php +++ b/modules/gallery/views/admin_maintenance.html.php @@ -164,6 +164,11 @@ id?csrf=$csrf") ?>"> + get_task_log()): ?> + id?csrf=$csrf") ?>"> + + + id?csrf=$csrf") ?>"> diff --git a/modules/gallery/views/admin_maintenance_show_log.html.php b/modules/gallery/views/admin_maintenance_show_log.html.php new file mode 100644 index 00000000..afd988bb --- /dev/null +++ b/modules/gallery/views/admin_maintenance_show_log.html.php @@ -0,0 +1,19 @@ + + +
+

name ?>

+
+
get_task_log()) ?>
+
+ + +
diff --git a/themes/admin_default/css/screen.css b/themes/admin_default/css/screen.css index e68620a5..d408acf0 100644 --- a/themes/admin_default/css/screen.css +++ b/themes/admin_default/css/screen.css @@ -400,6 +400,20 @@ li.gDefaultGroup h4, li.gDefaultGroup .gUser { float: left; } +#gTaskLogDialog h1 { + font-size: 1.1em; +} + +.gTaskLog { + border: 1pt solid; + font-size: .9em; + height: 400px; + margin: .5em 0; + overflow: auto; + padding: .5em +} + + /** ******************************************************************* * 7) Server Add *********************************************************************/ -- cgit v1.2.3 From 493fb27825327e14168c3c0b133c338a53457e0e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 6 Jul 2009 22:20:04 -0700 Subject: Cleanup remove task processing. Change Task_Model::delete to call parent::delete instead of parent::save. :-) Also change admin_maintenance_controller to delete via looping over all of the completed tasks and delete individually, so we can delete the associated cache entries at the same time. --- modules/gallery/controllers/admin_maintenance.php | 9 ++++++++- modules/gallery/models/task.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index a65bd770..37cc5222 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -161,7 +161,14 @@ class Admin_Maintenance_Controller extends Admin_Controller { public function remove_finished_tasks() { access::verify_csrf(); - Database::instance()->delete("tasks", array("done" => 1)); + + // Do it the long way so we can call delete and remove the cache. + $finished = ORM::factory("task") + ->where(array("done" => 1)) + ->find_all(); + foreach ($finished as $task) { + task::remove($task->id); + } message::success(t("All finished tasks removed")); url::redirect("admin/maintenance"); } diff --git a/modules/gallery/models/task.php b/modules/gallery/models/task.php index 2e77a7a6..012b88cf 100644 --- a/modules/gallery/models/task.php +++ b/modules/gallery/models/task.php @@ -42,7 +42,7 @@ class Task_Model extends ORM { public function delete() { Cache::instance()->delete($this->_cache_key()); - return parent::save(); + return parent::delete(); } public function owner() { -- cgit v1.2.3 From b0cd0a52be1d58e451daa52950deb7d5257e1162 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 7 Jul 2009 12:10:50 -0700 Subject: Allow the task::log method to take an array of lines and change g2_import.php helper to use this approach. --- modules/g2_import/helpers/g2_import.php | 36 +++++++++++++++------------------ modules/gallery/models/task.php | 4 ++++ 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 0d72c139..f9a15869 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -376,8 +376,8 @@ class g2_import_Core { } $album->save(); - $message = t("Album '%name' imported.", array("name" => $album->name)); - $message .= self::import_keywords_as_tags($g2_album->getKeywords(), $album); + $message[] = t("Album '%name' imported.", array("name" => $album->name)); + $message[] = self::import_keywords_as_tags($g2_album->getKeywords(), $album); self::set_map($g2_album_id, $album->id); // @todo import album highlights @@ -460,12 +460,12 @@ class g2_import_Core { $corrupt = 1; } - $message = ""; + $message = array(); switch ($g2_type) { case "GalleryPhotoItem": if (!in_array($g2_item->getMimeType(), array("image/jpeg", "image/gif", "image/png"))) { Kohana::log("alert", "$g2_path is an unsupported image type; using a placeholder gif"); - $message = t("'%path' is an unsupported image type, using a placeholder", + $message[] = t("'%path' is an unsupported image type, using a placeholder", array("path" => $g2_path)); $g2_path = MODPATH . "g2_import/data/broken-image.gif"; $corrupt = 1; @@ -480,12 +480,11 @@ class g2_import_Core { self::_decode_html_special_chars($g2_item->getTitle()), self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); - $message .= (strlen($message) ? "\n" : "") . - t("Imported photo: '%title'", array("title" => p::purify($item->title))); + $message[].= t("Imported photo: '%title'", array("title" => p::purify($item->title))); } catch (Exception $e) { Kohana::log( "alert", "Corrupt image $g2_path\n" . $e->__toString()); - $message .= (strlen($message) ? "\n" : "") . t("Corrupt image '%path'\n$exception", + $message[] = t("Corrupt image '%path'\n$exception", array("path" => $g2_path,"exception" => $e->__toString())); $corrupt = 1; } @@ -502,17 +501,16 @@ class g2_import_Core { self::_decode_html_special_chars($g2_item->getTitle()), self::_decode_html_special_chars(self::extract_description($g2_item)), self::map($g2_item->getOwnerId())); - $message .= (strlen($message) ? "\n" : "") . - t("Imported movie: '%title'", array("title" => p::purify($item->title))); + $message[] = t("Imported movie: '%title'", array("title" => p::purify($item->title))); } catch (Exception $e) { Kohana::log("alert", "Corrupt movie $g2_path\n" . $e->__toString()); - $message .= (strlen($message) ? "\n" : "") . t("Corrupt movie '%path'\n$exception", - array("path" => $g2_path,"exception" => $e->__toString())); + $message[] = t("Corrupt movie '%path'\n$exception", + array("path" => $g2_path,"exception" => $e->__toString())); $corrupt = 1; } } else { Kohana::log("alert", "$g2_path is an unsupported movie type"); - $message .= t("'%path' is an unsupported movie type", array("path" => $g2_path)); + $message[] = t("'%path' is an unsupported movie type", array("path" => $g2_path)); $corrupt = 1; } @@ -524,16 +522,14 @@ class g2_import_Core { } if (!empty($item)) { - $message .= (strlen($message) ? "\n" : "") . - self::import_keywords_as_tags($g2_item->getKeywords(), $item); + $message[] = self::import_keywords_as_tags($g2_item->getKeywords(), $item); } if (isset($item)) { self::set_map($g2_item_id, $item->id); $item->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_item_id)); $item->save(); - $message .= (strlen($message) ? "\n" : "") . - t("View count updated: %count", array("count" => $item->view_count)); + $message[] = t("View count updated: %count", array("count" => $item->view_count)); } if ($corrupt) { @@ -544,21 +540,21 @@ class g2_import_Core { $g2_item_url = str_replace('&g2_GALLERYSID=TMP_SESSION_ID_DI_NOISSES_PMT', '', $g2_item_url); if (!empty($item)) { - $warning = + $message[] = t("
%title from Gallery 2 could not be processed; " . "(imported as %title)", array("g2_url" => $g2_item_url, "g3_url" => $item->url(), "title" => $g2_item->getTitle())); } else { - $warning = + $message[] = t("%title from Gallery 2 could not be processed", array("g2_url" => $g2_item_url, "title" => $g2_item->getTitle())); } - $message .= (strlen($message) ? "\n" : "") . $warning; } self::$current_g2_item = null; + return $message; } /** @@ -661,7 +657,7 @@ class g2_import_Core { } } return strlen($tags) ? t("Added '%keywords' to '%title'", - array("tags" => $tags, "title" => p::purify($item->title))) : ""; + array("keywords" => $tags, "title" => p::purify($item->title))) : ""; } /** diff --git a/modules/gallery/models/task.php b/modules/gallery/models/task.php index 012b88cf..55bb8e21 100644 --- a/modules/gallery/models/task.php +++ b/modules/gallery/models/task.php @@ -53,6 +53,10 @@ class Task_Model extends ORM { $key = $this->_cache_key(); $log = Cache::instance()->get($key); + if (is_array($msg)) { + $msg = implode("\n", $msg); + } + // Save for 30 days. $log .= !empty($log) ? "\n" : ""; Cache::instance()->set($key, "$log{$msg}", -- cgit v1.2.3 From 5d9e334fe6d7c7c1cf6d39a12684e215e797b4b3 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 7 Jul 2009 12:49:21 -0700 Subject: Added a wee bit of phpDoc. Changed the name of the method get_task_log to get_log Changed the default name of the file when the log is downloaded to gallery3_task_log.txt --- modules/gallery/controllers/admin_maintenance.php | 4 ++-- modules/gallery/models/task.php | 14 +++++++++++++- modules/gallery/views/admin_maintenance.html.php | 2 +- modules/gallery/views/admin_maintenance_show_log.html.php | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php index 37cc5222..543961a1 100644 --- a/modules/gallery/controllers/admin_maintenance.php +++ b/modules/gallery/controllers/admin_maintenance.php @@ -119,8 +119,8 @@ class Admin_Maintenance_Controller extends Admin_Controller { } header("Content-Type: application/text"); - header("Content-Disposition: filename=g2_import.txt"); - print $task->get_task_log(); + header("Content-Disposition: filename=gallery3_task_log.txt"); + print $task->get_log(); } /** diff --git a/modules/gallery/models/task.php b/modules/gallery/models/task.php index 55bb8e21..b7e255a2 100644 --- a/modules/gallery/models/task.php +++ b/modules/gallery/models/task.php @@ -49,6 +49,10 @@ class Task_Model extends ORM { return user::lookup($this->owner_id); } + /** + * Log a message to the task log. + * @params $msg mixed a string or array of strings + */ public function log($msg) { $key = $this->_cache_key(); $log = Cache::instance()->get($key); @@ -63,11 +67,19 @@ class Task_Model extends ORM { array("task", "log", "import"), 2592000); } - public function get_task_log() { + /** + * Retrieve the cached log information for this task. + * @returns the log data or null if there is no log data + */ + public function get_log() { $log_data = Cache::instance()->get($this->_cache_key()); return $log_data !== null ? $log_data : false; } + /** + * Build the task cache key + * @returns the key to use in access the cache + */ private function _cache_key() { return md5("$this->id; $this->name; $this->callback"); } diff --git a/modules/gallery/views/admin_maintenance.html.php b/modules/gallery/views/admin_maintenance.html.php index f50c95dd..eecc045c 100644 --- a/modules/gallery/views/admin_maintenance.html.php +++ b/modules/gallery/views/admin_maintenance.html.php @@ -164,7 +164,7 @@ id?csrf=$csrf") ?>"> - get_task_log()): ?> + get_log()): ?> id?csrf=$csrf") ?>"> diff --git a/modules/gallery/views/admin_maintenance_show_log.html.php b/modules/gallery/views/admin_maintenance_show_log.html.php index afd988bb..9d850986 100644 --- a/modules/gallery/views/admin_maintenance_show_log.html.php +++ b/modules/gallery/views/admin_maintenance_show_log.html.php @@ -12,7 +12,7 @@ appendTo('body').submit().remove();

name ?>

-
get_task_log()) ?>
+
get_log()) ?>
-- cgit v1.2.3