summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/controllers/admin_maintenance.php47
-rw-r--r--modules/gallery/helpers/gallery_block.php2
-rw-r--r--modules/gallery/helpers/gallery_task.php223
-rw-r--r--modules/gallery/helpers/l10n_client.php12
-rw-r--r--modules/gallery/helpers/task.php19
-rw-r--r--modules/gallery/models/task.php40
-rw-r--r--modules/gallery/views/admin_maintenance.html.php20
-rw-r--r--modules/gallery/views/admin_maintenance_show_log.html.php19
-rw-r--r--modules/gallery/views/kohana_error_page.php10
-rw-r--r--modules/gallery/views/upgrader.html.php2
10 files changed, 274 insertions, 120 deletions
diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php
index 7c5934a3..543961a1 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,6 +81,8 @@ 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")));
@@ -86,6 +90,40 @@ class Admin_Maintenance_Controller extends Admin_Controller {
}
/**
+ * 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=gallery3_task_log.txt");
+ print $task->get_log();
+ }
+
+ /**
* Cancel a task.
* @param string $task_id
*/
@@ -123,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/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php
index a10f2bbf..b7816954 100644
--- a/modules/gallery/helpers/gallery_block.php
+++ b/modules/gallery/helpers/gallery_block.php
@@ -33,7 +33,7 @@ class gallery_block_Core {
switch($block_id) {
case "welcome":
$block->css_id = "gWelcome";
- $block->title = t("Welcome to Gallery3");
+ $block->title = t("Welcome to Gallery 3");
$block->content = new View("admin_block_welcome.html");
break;
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index 1152cda2..9ce2c4a0 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -45,131 +45,154 @@ class gallery_task_Core {
* @param Task_Model the task
*/
static function rebuild_dirty_images($task) {
- $result = graphics::find_dirty_images_query();
- $completed = $task->get("completed", 0);
- $ignored = $task->get("ignored", array());
- $remaining = $result->count() - count($ignored);
-
- $i = 0;
- foreach ($result as $row) {
- if (array_key_exists($row->id, $ignored)) {
- continue;
- }
+ $message = array();
+ try {
+ $result = graphics::find_dirty_images_query();
+ $completed = $task->get("completed", 0);
+ $ignored = $task->get("ignored", array());
+ $remaining = $result->count() - count($ignored);
+
+ $i = 0;
+ foreach ($result as $row) {
+ if (array_key_exists($row->id, $ignored)) {
+ continue;
+ }
- $item = ORM::factory("item", $row->id);
- if ($item->loaded) {
- $success = graphics::generate($item);
- if (!$success) {
- $ignored[$item->id] = 1;
+ $item = ORM::factory("item", $row->id);
+ if ($item->loaded) {
+ $success = graphics::generate($item);
+ if (!$success) {
+ $ignored[$item->id] = 1;
+ $message[] = t("Unable to rebuild images for '%title'",
+ array("title" => p::purify($item->title)));
+ } else {
+ $message[] = t("Successfully rebuilt images for '%title'",
+ array("title" => p::purify($item->title)));
+ }
}
- }
- $completed++;
- $remaining--;
+ $completed++;
+ $remaining--;
- if (++$i == 2) {
- break;
+ if (++$i == 2) {
+ break;
+ }
}
- }
- $task->status = t2("Updated: 1 image. Total: %total_count.",
- "Updated: %count images. Total: %total_count.",
- $completed,
- array("total_count" => ($remaining + $completed)));
+ $task->status = t2("Updated: 1 image. Total: %total_count.",
+ "Updated: %count images. Total: %total_count.",
+ $completed,
+ array("total_count" => ($remaining + $completed)));
- if ($completed + $remaining > 0) {
- $task->percent_complete = (int)(100 * $completed / ($completed + $remaining));
- } else {
- $task->percent_complete = 100;
- }
+ if ($completed + $remaining > 0) {
+ $task->percent_complete = (int)(100 * $completed / ($completed + $remaining));
+ } else {
+ $task->percent_complete = 100;
+ }
- $task->set("completed", $completed);
- $task->set("ignored", $ignored);
- if ($remaining == 0) {
+ $task->set("completed", $completed);
+ $task->set("ignored", $ignored);
+ if ($remaining == 0) {
+ $task->done = true;
+ $task->state = "success";
+ site_status::clear("graphics_dirty");
+ }
+ } catch (Exception $e) {
$task->done = true;
- $task->state = "success";
- site_status::clear("graphics_dirty");
+ $task->state = "error";
+ $task->status = $e->getMessage();
+ $message[] = $e->__toString();
}
+ $task->log($message);
}
static function update_l10n(&$task) {
- $start = microtime(true);
- $dirs = $task->get("dirs");
- $files = $task->get("files");
- $cache = $task->get("cache", array());
- $i = 0;
-
- switch ($task->get("mode", "init")) {
- case "init": // 0%
- $dirs = array("gallery", "modules", "themes", "installer");
- $files = array();
- $task->set("mode", "find_files");
- $task->status = t("Finding files");
- break;
-
- case "find_files": // 0% - 10%
- while (($dir = array_pop($dirs)) && microtime(true) - $start < 0.5) {
- if (in_array(basename($dir), array("tests", "lib"))) {
- continue;
- }
+ $message = array();
+ try {
+ $start = microtime(true);
+ $dirs = $task->get("dirs");
+ $files = $task->get("files");
+ $cache = $task->get("cache", array());
+ $i = 0;
+
+ switch ($task->get("mode", "init")) {
+ case "init": // 0%
+ $dirs = array("gallery", "modules", "themes", "installer");
+ $files = array();
+ $task->set("mode", "find_files");
+ $task->status = t("Finding files");
+ break;
- foreach (glob(DOCROOT . "$dir/*") as $path) {
- $relative_path = str_replace(DOCROOT, "", $path);
- if (is_dir($path)) {
- $dirs[] = $relative_path;
- } else {
- $files[] = $relative_path;
+ case "find_files": // 0% - 10%
+ while (($dir = array_pop($dirs)) && microtime(true) - $start < 0.5) {
+ if (in_array(basename($dir), array("tests", "lib"))) {
+ continue;
+ }
+
+ foreach (glob(DOCROOT . "$dir/*") as $path) {
+ $relative_path = str_replace(DOCROOT, "", $path);
+ if (is_dir($path)) {
+ $dirs[] = $relative_path;
+ } else {
+ $files[] = $relative_path;
+ }
}
}
- }
- $task->status = t2("Finding files: found 1 file",
- "Finding files: found %count files", count($files));
+ $message[] = $task->status = t2("Finding files: found 1 file",
+ "Finding files: found %count files", count($files));
- if (!$dirs) {
- $task->set("mode", "scan_files");
- $task->set("total_files", count($files));
- $task->status = t("Scanning files");
- $task->percent_complete = 10;
- }
- break;
-
- case "scan_files": // 10% - 90%
- while (($file = array_pop($files)) && microtime(true) - $start < 0.5) {
- $file = DOCROOT . $file;
- switch (pathinfo($file, PATHINFO_EXTENSION)) {
- case "php":
- l10n_scanner::scan_php_file($file, $cache);
- break;
+ if (!$dirs) {
+ $task->set("mode", "scan_files");
+ $task->set("total_files", count($files));
+ $task->status = t("Scanning files");
+ $task->percent_complete = 10;
+ }
+ break;
- case "info":
- l10n_scanner::scan_info_file($file, $cache);
- break;
+ case "scan_files": // 10% - 90%
+ while (($file = array_pop($files)) && microtime(true) - $start < 0.5) {
+ $file = DOCROOT . $file;
+ switch (pathinfo($file, PATHINFO_EXTENSION)) {
+ case "php":
+ l10n_scanner::scan_php_file($file, $cache);
+ break;
+
+ case "info":
+ l10n_scanner::scan_info_file($file, $cache);
+ break;
+ }
}
- }
- $total_files = $task->get("total_files");
- $task->status = t2("Scanning files: scanned 1 file",
- "Scanning files: scanned %count files", $total_files - count($files));
+ $total_files = $task->get("total_files");
+ $message[] = $task->status = t2("Scanning files: scanned 1 file",
+ "Scanning files: scanned %count files", $total_files - count($files));
- $task->percent_complete = 10 + 80 * ($total_files - count($files)) / $total_files;
- if (empty($files)) {
- $task->set("mode", "fetch_updates");
- $task->status = t("Fetching updates");
- $task->percent_complete = 90;
+ $task->percent_complete = 10 + 80 * ($total_files - count($files)) / $total_files;
+ if (empty($files)) {
+ $task->set("mode", "fetch_updates");
+ $task->status = t("Fetching updates");
+ $task->percent_complete = 90;
+ }
+ break;
+
+ case "fetch_updates": // 90% - 100%
+ $message = array_merge($message, l10n_client::fetch_updates());
+ $task->done = true;
+ $task->state = "success";
+ $task->status = t("Translations installed/updated");
+ $task->percent_complete = 100;
}
- break;
- case "fetch_updates": // 90% - 100%
- l10n_client::fetch_updates();
+ $task->set("files", $files);
+ $task->set("dirs", $dirs);
+ $task->set("cache", $cache);
+ } catch (Exception $e) {
$task->done = true;
- $task->state = "success";
- $task->status = t("Translations installed/updated");
- $task->percent_complete = 100;
+ $task->state = "error";
+ $task->status = $e->getMessage();
+ $message[] = $e->__toString();
}
-
- $task->set("files", $files);
- $task->set("dirs", $dirs);
- $task->set("cache", $cache);
+ $task->log($message);
}
} \ No newline at end of file
diff --git a/modules/gallery/helpers/l10n_client.php b/modules/gallery/helpers/l10n_client.php
index e153532c..6d4da0eb 100644
--- a/modules/gallery/helpers/l10n_client.php
+++ b/modules/gallery/helpers/l10n_client.php
@@ -67,6 +67,9 @@ class l10n_client_Core {
return true;
}
+ /**
+ * @return an array of messages that will be written to the task log
+ */
static function fetch_updates() {
$request->locales = array();
$request->messages = new stdClass();
@@ -101,8 +104,7 @@ class l10n_client_Core {
throw new Exception("@todo TRANSLATIONS_FETCH_REQUEST_FAILED " . $response_status);
}
if (empty($response_data)) {
- log::info("translations", "Translations fetch request resulted in an empty response");
- return;
+ return array(t("Translations fetch request resulted in an empty response"));
}
$response = json_decode($response_data);
@@ -112,9 +114,8 @@ class l10n_client_Core {
// {key:<key_2>, ...}
// ]
$count = count($response);
- log::info("translations",
- t2("Installed 1 new / updated translation message",
- "Installed %count new / updated translation messages", $count));
+ $message[] = t2("Installed 1 new / updated translation message",
+ "Installed %count new / updated translation messages", $count);
foreach ($response as $message_data) {
// @todo Better input validation
@@ -152,6 +153,7 @@ class l10n_client_Core {
$entry->translation = $translation;
$entry->save();
}
+ return $message;
}
static function submit_translations() {
diff --git a/modules/gallery/helpers/task.php b/modules/gallery/helpers/task.php
index a8a004ab..6a9f63c2 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;
@@ -74,9 +76,20 @@ class task_Core {
throw new Exception("@todo MISSING_TASK");
}
- $task->state = "running";
- call_user_func_array($task->callback, array(&$task));
- $task->save();
+ try {
+ $task->state = "running";
+ call_user_func_array($task->callback, array(&$task));
+ if ($task->done) {
+ $task->log($task->status);
+ }
+ $task->save();
+ } catch (Exception $e) {
+ $task->log($e->__toString());
+ $task->state = "error";
+ $task->done = true;
+ $task->status = $e->getMessage();
+ $task->save();
+ }
return $task;
}
diff --git a/modules/gallery/models/task.php b/modules/gallery/models/task.php
index 9e3ae5c6..b7e255a2 100644
--- a/modules/gallery/models/task.php
+++ b/modules/gallery/models/task.php
@@ -40,7 +40,47 @@ class Task_Model extends ORM {
return parent::save();
}
+ public function delete() {
+ Cache::instance()->delete($this->_cache_key());
+ return parent::delete();
+ }
+
public function owner() {
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);
+
+ if (is_array($msg)) {
+ $msg = implode("\n", $msg);
+ }
+
+ // Save for 30 days.
+ $log .= !empty($log) ? "\n" : "";
+ Cache::instance()->set($key, "$log{$msg}",
+ array("task", "log", "import"), 2592000);
+ }
+
+ /**
+ * 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");
+ }
} \ 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..cd1cc02e 100644
--- a/modules/gallery/views/admin_maintenance.html.php
+++ b/modules/gallery/views/admin_maintenance.html.php
@@ -29,7 +29,7 @@
</td>
<td>
<a href="<?= url::site("admin/maintenance/start/$task->callback?csrf=$csrf") ?>"
- class="gDialogLink">
+ class="gDialogLink gButtonLink ui-icon-left ui-state-default ui-corner-all">
<?= t("run") ?>
</a>
</td>
@@ -94,11 +94,13 @@
</td>
<td>
<? if ($task->state == "stalled"): ?>
- <a class="gDialogLink" href="<?= url::site("admin/maintenance/resume/$task->id?csrf=$csrf") ?>">
+ <a class="gDialogLink gButtonLink ui-icon-left ui-state-default ui-corner-all"
+ href="<?= url::site("admin/maintenance/resume/$task->id?csrf=$csrf") ?>">
<?= t("resume") ?>
</a>
<? endif ?>
- <a href="<?= url::site("admin/maintenance/cancel/$task->id?csrf=$csrf") ?>">
+ <a href="<?= url::site("admin/maintenance/cancel/$task->id?csrf=$csrf") ?>"
+ class="gButtonLink ui-icon-left ui-state-default ui-corner-all right">
<?= t("cancel") ?>
</a>
</td>
@@ -161,17 +163,23 @@
</td>
<td>
<? if ($task->done): ?>
- <a href="<?= url::site("admin/maintenance/remove/$task->id?csrf=$csrf") ?>">
+ <a href="<?= url::site("admin/maintenance/remove/$task->id?csrf=$csrf") ?>" class="gButtonLink ui-state-default ui-corner-all">
<?= t("remove") ?>
</a>
+ <? if ($task->get_log()): ?>
+ <a href="<?= url::site("admin/maintenance/show_log/$task->id?csrf=$csrf") ?>" class="gDialogLink gButtonLink ui-state-default ui-corner-all">
+ <?= t("browse log") ?>
+ </a>
+ <? endif ?>
<? else: ?>
- <a class="gDialogLink" href="<?= url::site("admin/maintenance/resume/$task->id?csrf=$csrf") ?>">
+ <a href="<?= url::site("admin/maintenance/resume/$task->id?csrf=$csrf") ?>" class="gDialogLink gButtonLink" ui-state-default ui-corner-all>
<?= t("resume") ?>
</a>
- <a href="<?= url::site("admin/maintenance/cancel/$task->id?csrf=$csrf") ?>">
+ <a href="<?= url::site("admin/maintenance/cancel/$task->id?csrf=$csrf") ?>" class="gButtonLink ui-state-default ui-corner-all">
<?= t("cancel") ?>
</a>
<? endif ?>
+ </ul>
</td>
</tr>
<? endforeach ?>
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..9d850986
--- /dev/null
+++ b/modules/gallery/views/admin_maintenance_show_log.html.php
@@ -0,0 +1,19 @@
+<?php defined("SYSPATH") or die("No direct script access.") ?>
+<script type="text/javascript">
+ dismiss = function() {
+ window.location.reload();
+ }
+ download = function(){
+ // send request
+ $('<form action="<?= url::site("admin/maintenance/save_log/$task->id?csrf=$csrf") ?>" method="post"></form>').
+appendTo('body').submit().remove();
+ };
+</script>
+<div id="gTaskLogDialog">
+ <h1> <?= $task->name ?> </h1>
+ <div class="gTaskLog">
+ <pre><?= p::purify($task->get_log()) ?></pre>
+ </div>
+ <button id="gCloseButton" class="ui-state-default ui-corner-all" onclick="dismiss()"><?= t("Close") ?></button>
+ <button id="gSaveButton" class="ui-state-default ui-corner-all" onclick="download()"><?= t("Save") ?></button>
+</div>
diff --git a/modules/gallery/views/kohana_error_page.php b/modules/gallery/views/kohana_error_page.php
index 6bf48549..9361514d 100644
--- a/modules/gallery/views/kohana_error_page.php
+++ b/modules/gallery/views/kohana_error_page.php
@@ -53,7 +53,6 @@
margin: 0px;
}
</style>
- <script src="<?= url::file("lib/jquery.js") ?>" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title><?= t("Something went wrong!") ?></title>
</head>
@@ -78,8 +77,13 @@
<h2>
<?= t("Hey wait, you're an admin! We can tell you stuff.") ?>
</h2>
- <a id="toggle" href=""
- onclick="javascript:$('#stuff').slideDown('slow'); $('#toggle').slideUp(); return false">
+ <script type="text/javascript">
+ var show_details = function() {
+ document.getElementById("stuff").style.display = "block";
+ document.getElementById("toggle").style.display = "none";
+ }
+ </script>
+ <a id="toggle" href="#" onclick="javascript:show_details(); return false;">
<b><?= t("Ok.. tell me stuff!") ?></b>
</a>
<div id="stuff" style="display: none">
diff --git a/modules/gallery/views/upgrader.html.php b/modules/gallery/views/upgrader.html.php
index f9e242a8..37578855 100644
--- a/modules/gallery/views/upgrader.html.php
+++ b/modules/gallery/views/upgrader.html.php
@@ -1,7 +1,7 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<html>
<head>
- <title><?= t("Gallery3 Upgrader") ?></title>
+ <title><?= t("Gallery 3 Upgrader") ?></title>
<link rel="stylesheet" type="text/css" href="<?= url::file("modules/gallery/css/upgrader.css") ?>"
media="screen,print,projection" />
<script src="<?= url::file("lib/jquery.js") ?>" type="text/javascript"></script>