diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-01-26 13:26:26 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-01-26 13:26:26 -0800 |
commit | e0d31add9f88f191a647c297e16ea2590a3103de (patch) | |
tree | 4f190f45bb4bb1ac8e131bdf3d0635fca8c27cb2 | |
parent | e315ce348bee75290e65e2376cc4f34b0f285cea (diff) | |
parent | accd00464e2d7e1d1fd0e24e1ee583a7baa73611 (diff) |
Merge branch 'master' of git@github.com:gallery/gallery3
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 12 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_task.php | 74 |
2 files changed, 81 insertions, 5 deletions
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 6b70513a..b35ae3c4 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -381,18 +381,22 @@ class gallery_event_Core { static function show_user_profile($data) { $v = new View("user_profile_info.html"); - $fields = array("name" => t("Name"), "locale" => t("Locale"), "email" => t("Email"), - "full_name" => t("Full name"), "url" => "Web site"); + $fields = array("name" => t("Name"), "locale" => t("Language Preference"), + "email" => t("Email"), "full_name" => t("Full name"), "url" => "Web site"); if (!$data->display_all) { $fields = array("name" => t("Name"), "full_name" => t("Full name"), "url" => "Web site"); } $v->fields = array(); foreach ($fields as $field => $label) { if (!empty($data->user->$field)) { - $v->fields[(string)$label->for_html()] = $data->user->$field; + $value = $data->user->$field; + if ($field == "locale") { + $value = locales::display_name($value); + } + $v->fields[(string) $label] = html::clean($value); } } - $data->content[] = (object)array("title" => t("User information"), "view" => $v); + $data->content[] = (object) array("title" => t("User information"), "view" => $v); } } diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index b3b79e06..5402b5d1 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -37,6 +37,11 @@ class gallery_task_Core { ->description(t("Download new and updated translated strings")) ->severity(log::SUCCESS); + $tasks[] = Task_Definition::factory() + ->callback("gallery_task::file_cleanup") + ->name(t("Remove old files")) + ->description(t("Remove files from the logs and tmp directory")) + ->severity(log::SUCCESS); return $tasks; } @@ -116,7 +121,7 @@ class gallery_task_Core { } } - static function update_l10n(&$task) { + static function update_l10n($task) { $errors = array(); try { $start = microtime(true); @@ -218,4 +223,71 @@ class gallery_task_Core { $task->log($errors); } } + + /** + * Task that removes old files from var/logs and var/tmp. + * @param Task_Model the task + */ + static function file_cleanup($task) { + $errors = array(); + try { + $start = microtime(true); + $data = Cache::instance()->get("file_cleanup_cache:{$task->id}"); + if ($data) { + $files = unserialize($data); + } + $i = 0; + + switch ($task->get("mode", "init")) { + case "init": // 0% + $threshold = time() - 1209600; // older than 2 weeks + foreach(array("logs", "tmp") as $dir) { + $dir = VARPATH . $dir; + if ($dh = opendir($dir)) { + while (($file = readdir($dh)) !== false) { + if ($file[0] == ".") { + continue; + } + + if (filemtime("$dir/$file") <= $threshold) { + $files[] = "$dir/$file"; + } + } + } + } + $task->set("mode", "delete_files"); + $task->set("current", 0); + $task->set("total", count($files)); + Cache::instance()->set("file_cleanup_cache:{$task->id}", serialize($files)); + if (count($files) == 0) { + break; + } + case "delete_files": + $current = $task->get("current"); + $total = $task->get("total"); + while ($current < $total && microtime(true) - $start < 1) { + @unlink($files[$current]); + $task->log(t("%file removed", array("file" => $files[$current++]))); + } + $task->percent_complete = $current / $total * 100; + $task->set("current", $current); + } + + $task->status = t("Removed: %count files. Total: %total_count.", + array("count" => $current, "total_count" => $total)); + + if ($total == $current) { + $task->done = true; + $task->state = "success"; + } + } catch (Exception $e) { + $task->done = true; + $task->state = "error"; + $task->status = $e->getMessage(); + $errors[] = $e->__toString(); + } + if ($errors) { + $task->log($errors); + } + } }
\ No newline at end of file |