From 47fbb56fa25fc98d4e0695ed08b7fbaec916c003 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 8 Jul 2009 08:22:40 -0700 Subject: Added task logging to the Rebuild Images task. --- modules/gallery/helpers/gallery_task.php | 83 ++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 35 deletions(-) (limited to 'modules/gallery/helpers/gallery_task.php') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 1152cda2..c673411d 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -45,50 +45,63 @@ 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; - } + 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))); + } + $task->log($message); } - } - $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(); + $task->log($e->__toString()); } } -- cgit v1.2.3 From ac797e609c8c319ca77f9b746a7cecad8dd69004 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 8 Jul 2009 09:08:15 -0700 Subject: Add task logging to the Update translations --- modules/gallery/helpers/gallery_task.php | 150 ++++++++++++++++--------------- modules/gallery/helpers/l10n_client.php | 9 +- 2 files changed, 84 insertions(+), 75 deletions(-) (limited to 'modules/gallery/helpers/gallery_task.php') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index c673411d..9ce2c4a0 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -45,6 +45,7 @@ class gallery_task_Core { * @param Task_Model the task */ static function rebuild_dirty_images($task) { + $message = array(); try { $result = graphics::find_dirty_images_query(); $completed = $task->get("completed", 0); @@ -62,13 +63,12 @@ class gallery_task_Core { $success = graphics::generate($item); if (!$success) { $ignored[$item->id] = 1; - $message = t("Unable to rebuild images for '%title'", + $message[] = t("Unable to rebuild images for '%title'", array("title" => p::purify($item->title))); } else { - $message = t("Successfully rebuilt images for '%title'", + $message[] = t("Successfully rebuilt images for '%title'", array("title" => p::purify($item->title))); } - $task->log($message); } $completed++; @@ -101,88 +101,98 @@ class gallery_task_Core { $task->done = true; $task->state = "error"; $task->status = $e->getMessage(); - $task->log($e->__toString()); + $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; - foreach (glob(DOCROOT . "$dir/*") as $path) { - $relative_path = str_replace(DOCROOT, "", $path); - if (is_dir($path)) { - $dirs[] = $relative_path; - } else { - $files[] = $relative_path; + 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; } - } - } - $task->status = t2("Finding files: found 1 file", - "Finding files: found %count files", count($files)); + foreach (glob(DOCROOT . "$dir/*") as $path) { + $relative_path = str_replace(DOCROOT, "", $path); + if (is_dir($path)) { + $dirs[] = $relative_path; + } else { + $files[] = $relative_path; + } + } + } - 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; + $message[] = $task->status = t2("Finding files: found 1 file", + "Finding files: found %count files", count($files)); - case "info": - l10n_scanner::scan_info_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 "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..5b14abec 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -101,8 +101,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 +111,8 @@ class l10n_client_Core { // {key:, ...} // ] $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 +150,7 @@ class l10n_client_Core { $entry->translation = $translation; $entry->save(); } + return $message; } static function submit_translations() { -- cgit v1.2.3 From b3f91167c14e98bbb35f62d7003efb0a82f142eb Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sun, 19 Jul 2009 13:55:22 -0700 Subject: Remove excess success logging. In the rebuild images case, it can make a huge log file. In the l10n_client case, it's not really necessary to know that level of detail and it makes for a weird API. --- modules/gallery/helpers/gallery_task.php | 34 ++++++++++++++++++-------------- modules/gallery/helpers/l10n_client.php | 5 ----- 2 files changed, 19 insertions(+), 20 deletions(-) (limited to 'modules/gallery/helpers/gallery_task.php') diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index 9ce2c4a0..9edc3acd 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -45,7 +45,7 @@ class gallery_task_Core { * @param Task_Model the task */ static function rebuild_dirty_images($task) { - $message = array(); + $errors = array(); try { $result = graphics::find_dirty_images_query(); $completed = $task->get("completed", 0); @@ -63,11 +63,11 @@ class gallery_task_Core { $success = graphics::generate($item); if (!$success) { $ignored[$item->id] = 1; - $message[] = t("Unable to rebuild images for '%title'", - array("title" => p::purify($item->title))); + $errors[] = 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))); + $errors[] = t("Successfully rebuilt images for '%title'", + array("title" => p::purify($item->title))); } } @@ -101,13 +101,15 @@ class gallery_task_Core { $task->done = true; $task->state = "error"; $task->status = $e->getMessage(); - $message[] = $e->__toString(); + $errors[] = $e->__toString(); + } + if ($errors) { + $task->log($errors); } - $task->log($message); } static function update_l10n(&$task) { - $message = array(); + $errors = array(); try { $start = microtime(true); $dirs = $task->get("dirs"); @@ -139,8 +141,8 @@ class gallery_task_Core { } } - $message[] = $task->status = t2("Finding files: found 1 file", - "Finding files: found %count files", count($files)); + $task->status = t2("Finding files: found 1 file", + "Finding files: found %count files", count($files)); if (!$dirs) { $task->set("mode", "scan_files"); @@ -165,8 +167,8 @@ class gallery_task_Core { } $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->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)) { @@ -177,7 +179,7 @@ class gallery_task_Core { break; case "fetch_updates": // 90% - 100% - $message = array_merge($message, l10n_client::fetch_updates()); + l10n_client::fetch_updates(); $task->done = true; $task->state = "success"; $task->status = t("Translations installed/updated"); @@ -191,8 +193,10 @@ class gallery_task_Core { $task->done = true; $task->state = "error"; $task->status = $e->getMessage(); - $message[] = $e->__toString(); + $errors[] = $e->__toString(); + } + if ($errors) { + $task->log($errors); } - $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 b576b4e1..3460cc65 100644 --- a/modules/gallery/helpers/l10n_client.php +++ b/modules/gallery/helpers/l10n_client.php @@ -113,10 +113,6 @@ class l10n_client_Core { // [{key:, translation: , rev:, locale:}, // {key:, ...} // ] - $count = count($response); - $message[] = t2("Installed 1 new / updated translation message", - "Installed %count new / updated translation messages", $count); - foreach ($response as $message_data) { // @todo Better input validation if (empty($message_data->key) || empty($message_data->translation) || @@ -153,7 +149,6 @@ class l10n_client_Core { $entry->translation = $translation; $entry->save(); } - return $message; } static function submit_translations() { -- cgit v1.2.3