From fad6c4783ebec8591e1b61bddcc7bd5f17d8cf0e Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 9 Jul 2009 10:46:27 -0700 Subject: Add status output to make it clearer what's happening when you add files. --- modules/server_add/controllers/server_add.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'modules/server_add/controllers') diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 288e6342..638a4d63 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -86,6 +86,7 @@ class Server_Add_Controller extends Admin_Controller { print json_encode( array("result" => "started", + "status" => $task->status, "url" => url::site("server_add/run/$task->id?csrf=" . access::csrf_token()))); } @@ -99,6 +100,7 @@ class Server_Add_Controller extends Admin_Controller { $task = task::run($task_id); print json_encode(array("done" => $task->done, + "status" => $task->status, "percent_complete" => $task->percent_complete)); } @@ -117,6 +119,7 @@ class Server_Add_Controller extends Admin_Controller { case "init": $task->set("mode", "build-file-list"); $task->set("queue", array_keys($selections)); + $task->status = t("Starting up"); $task->percent_complete = 0; batch::start(); break; @@ -126,7 +129,6 @@ class Server_Add_Controller extends Admin_Controller { // Don't use an iterator here because we can't get enough control over it when we're dealing // with a deep hierarchy and we don't want to go over our time quota. $queue = $task->get("queue"); - Kohana::log("alert",print_r($queue,1)); while ($queue && microtime(true) - $start < 0.5) { $file = array_shift($queue); $entry = ORM::factory("server_add_file"); @@ -144,6 +146,10 @@ class Server_Add_Controller extends Admin_Controller { // over 10% in percent_complete. $task->set("queue", $queue); $task->percent_complete = min($task->percent_complete + 0.1, 10); + $task->status = t2("Found one file", "Found %count files", + Database::instance() + ->where("task_id", $task->id) + ->count_records("server_add_files")); if (!$queue) { $task->set("mode", "add-files"); @@ -202,6 +208,7 @@ class Server_Add_Controller extends Admin_Controller { } else if (in_array($extension, array("flv", "mp4"))) { movie::create($parent, $entry->file, $name, $title, null, user::active()->id); } else { + $task->log("Skipping unknown file type: $relative_path"); // Unsupported type // @todo: $task->log this } @@ -211,8 +218,10 @@ class Server_Add_Controller extends Admin_Controller { $entry->delete(); } $task->set("completed_files", $completed_files); + $task->status = t("Adding photos (%completed of %total)", + array("completed" => $completed_files, + "total" => $total_files)); $task->percent_complete = 10 + 100 * ($completed_files / $total_files); - Kohana::log("alert",print_r($task->as_array(),1)); break; case "done": -- cgit v1.2.3 From 6fbb1e2dafdaa51c1a8fd5479819ff787c758c59 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 9 Jul 2009 14:03:07 -0700 Subject: Avoid blowing the task data column by only adding directories to the queue instead of directories and files. --- modules/server_add/controllers/server_add.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'modules/server_add/controllers') diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 638a4d63..cf7077a8 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -131,14 +131,21 @@ class Server_Add_Controller extends Admin_Controller { $queue = $task->get("queue"); while ($queue && microtime(true) - $start < 0.5) { $file = array_shift($queue); - $entry = ORM::factory("server_add_file"); - $entry->task_id = $task->id; - $entry->file = $file; - $entry->save(); - if (is_dir($file)) { - $queue = array_merge( - $queue, empty($selections[$file]) ? glob("$file/*") : $selections[$file]); + $children = empty($selections[$file]) ? glob("$file/*") : $selections[$file]; + } else { + $children = array($file); + } + + foreach ($children as $child) { + $entry = ORM::factory("server_add_file"); + $entry->task_id = $task->id; + $entry->file = $child; + $entry->save(); + + if (is_dir($child)) { + $queue[] = $child; + } } } // We have no idea how long this can take because we have no idea how deep the tree @@ -218,7 +225,7 @@ class Server_Add_Controller extends Admin_Controller { $entry->delete(); } $task->set("completed_files", $completed_files); - $task->status = t("Adding photos (%completed of %total)", + $task->status = t("Adding photos and albums (%completed of %total)", array("completed" => $completed_files, "total" => $total_files)); $task->percent_complete = 10 + 100 * ($completed_files / $total_files); -- cgit v1.2.3 From 5cf267cc4c4af79389276d786914cbb2b7a2ec25 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 10 Jul 2009 08:01:32 -0700 Subject: Fix a bug where we were not properly locating the parent album when adding a new album or photo. Simplify the data structure that we pass down to server_add_tree.html.php so that we just pass a file list and let it do whatever it wants with it. --- modules/server_add/controllers/server_add.php | 44 ++++++++++++++++------- modules/server_add/views/server_add_tree.html.php | 6 ++-- 2 files changed, 35 insertions(+), 15 deletions(-) (limited to 'modules/server_add/controllers') diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index cf7077a8..446c5074 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -21,7 +21,7 @@ class Server_Add_Controller extends Admin_Controller { public function browse($id) { $paths = unserialize(module::get_var("server_add", "authorized_paths")); foreach (array_keys($paths) as $path) { - $files[$path] = basename($path); + $files[] = $path; } $item = ORM::factory("item", $id); @@ -54,7 +54,7 @@ class Server_Add_Controller extends Admin_Controller { } } - $tree->files[$file] = basename($file); + $tree->files[] = $file; } print $tree; } @@ -119,8 +119,8 @@ class Server_Add_Controller extends Admin_Controller { case "init": $task->set("mode", "build-file-list"); $task->set("queue", array_keys($selections)); - $task->status = t("Starting up"); $task->percent_complete = 0; + $task->status = t("Starting up"); batch::start(); break; @@ -132,6 +132,11 @@ class Server_Add_Controller extends Admin_Controller { while ($queue && microtime(true) - $start < 0.5) { $file = array_shift($queue); if (is_dir($file)) { + $entry = ORM::factory("server_add_file"); + $entry->task_id = $task->id; + $entry->file = $file; + $entry->save(); + $children = empty($selections[$file]) ? glob("$file/*") : $selections[$file]; } else { $children = array($file); @@ -187,6 +192,7 @@ class Server_Add_Controller extends Admin_Controller { $item = model_cache::get("item", $item_id); foreach ($entries as $entry) { + Kohana::log("alert",print_r($albums,1)); if (microtime(true) - $start > 0.5) { break; } @@ -195,19 +201,33 @@ class Server_Add_Controller extends Admin_Controller { $name = basename($relative_path); $title = item::convert_filename_to_title($name); if (is_dir($entry->file)) { - if (isset($albums[$relative_path]) && $parent_id = $albums[$relative_path]) { + $parent_path = dirname($relative_path); + Kohana::log("alert",print_r("rp: $relative_path -> $parent_path",1)); + if (isset($albums[$parent_path]) && $parent_id = $albums[$parent_path]) { $parent = ORM::factory("item", $parent_id); - } else { - $album = album::create($item, $name, $title, null, user::active()->id); - $albums[$relative_path] = $album->id; - $task->set("albums", $albums); - } - } else { - if (strpos($relative_path, "/") !== false) { - $parent = ORM::factory("item", $albums[dirname($relative_path)]); } else { $parent = $item; } + $album = album::create($parent, $name, $title, null, user::active()->id); + $albums[$relative_path] = $album->id; + $task->set("albums", $albums); + } else { + // Find the nearest selected parent. We check to see if any of the candidate parents + // were selected in the UI and if so, we use that. Otherwise, we fall back to making + // the parent the current item. + $parent_path = $relative_path; + $parent = null; + do { + if (strpos($parent_path, "/") !== false) { + if (array_key_exists($parent_path, $albums)) { + $parent = ORM::factory("item", $albums[$parent_path]); + } else { + $parent_path = dirname($parent_path); + } + } else { + $parent = $item; + } + } while (!$parent); $extension = strtolower(pathinfo($name, PATHINFO_EXTENSION)); if (in_array($extension, array("gif", "png", "jpg", "jpeg"))) { diff --git a/modules/server_add/views/server_add_tree.html.php b/modules/server_add/views/server_add_tree.html.php index f8205a8b..74bc40e0 100644 --- a/modules/server_add/views/server_add_tree.html.php +++ b/modules/server_add/views/server_add_tree.html.php @@ -1,13 +1,13 @@ - $name): ?> +
  • "> -- cgit v1.2.3 From b3785e176145b10c84b3b27850679b13ab54bc81 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 10 Jul 2009 08:04:37 -0700 Subject: Remove debug code. --- modules/server_add/controllers/server_add.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'modules/server_add/controllers') diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php index 446c5074..08e01858 100644 --- a/modules/server_add/controllers/server_add.php +++ b/modules/server_add/controllers/server_add.php @@ -192,7 +192,6 @@ class Server_Add_Controller extends Admin_Controller { $item = model_cache::get("item", $item_id); foreach ($entries as $entry) { - Kohana::log("alert",print_r($albums,1)); if (microtime(true) - $start > 0.5) { break; } @@ -202,7 +201,6 @@ class Server_Add_Controller extends Admin_Controller { $title = item::convert_filename_to_title($name); if (is_dir($entry->file)) { $parent_path = dirname($relative_path); - Kohana::log("alert",print_r("rp: $relative_path -> $parent_path",1)); if (isset($albums[$parent_path]) && $parent_id = $albums[$parent_path]) { $parent = ORM::factory("item", $parent_id); } else { -- cgit v1.2.3