diff options
author | Shad Laws <shad@shadlaws.com> | 2013-05-14 04:48:27 -0700 |
---|---|---|
committer | Shad Laws <shad@shadlaws.com> | 2013-05-14 04:48:27 -0700 |
commit | 2713389c010b586255f7ae3cde0988cabd70a4ef (patch) | |
tree | 085476c00b55ecdde2f41b4fd259b2855ea2987b /modules/gallery | |
parent | 4d8fbd1b9d61463ed255b3a73e6e6b3574d97923 (diff) | |
parent | 2ebe38b148da8830f2b4064bb738633c511c97cc (diff) |
Merge pull request #367 from shadlaws/fix_2069_master
#2069 - Change "Fix your Gallery" task go faster and be more comprehensive.
Diffstat (limited to 'modules/gallery')
-rw-r--r-- | modules/gallery/helpers/gallery_task.php | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php index a79cb2d5..ac98831b 100644 --- a/modules/gallery/helpers/gallery_task.php +++ b/modules/gallery/helpers/gallery_task.php @@ -398,42 +398,60 @@ class gallery_task_Core { switch ($state) { case self::FIX_STATE_START_MPTT: $task->set("ptr", $ptr = 1); - $task->set("stack", item::root()->id . ":L"); + $task->set("stack", item::root()->id . ":album:1:L"); $state = self::FIX_STATE_RUN_MPTT; break; case self::FIX_STATE_RUN_MPTT: $ptr = $task->get("ptr"); $stack = explode(" ", $task->get("stack")); - list ($id, $ptr_mode) = explode(":", array_pop($stack)); + list ($id, $type, $level, $ptr_mode) = explode(":", array_pop($stack)); if ($ptr_mode == "L") { - $stack[] = "$id:R"; - db::build() - ->update("items") - ->set("left_ptr", $ptr++) - ->where("id", "=", $id) - ->execute(); + if ($type == "album") { + // Albums could be parent nodes. + $stack[] = "$id:$type:$level:R"; + db::build() + ->update("items") + ->set("left_ptr", $ptr++) + ->where("id", "=", $id) + ->execute(); - foreach (db::build() - ->select(array("id")) - ->from("items") - ->where("parent_id", "=", $id) - ->order_by("left_ptr", "ASC") - ->execute() as $child) { - array_push($stack, "{$child->id}:L"); + $level++; + foreach (db::build() + ->select(array("id", "type")) + ->from("items") + ->where("parent_id", "=", $id) + ->order_by("left_ptr", "DESC") // DESC since array_pop effectively reverses them + ->execute() as $child) { + $stack[] = "{$child->id}:{$child->type}:$level:L"; + } + $completed++; + } else { + // Non-albums must be leaf nodes. + db::build() + ->update("items") + ->set("left_ptr", $ptr++) + ->set("right_ptr", $ptr++) + ->set("level", $level) + ->set("relative_path_cache", null) + ->set("relative_url_cache", null) + ->where("id", "=", $id) + ->execute(); + $completed += 2; // we updated two pointers } } else if ($ptr_mode == "R") { db::build() ->update("items") ->set("right_ptr", $ptr++) + ->set("level", $level) ->set("relative_path_cache", null) ->set("relative_url_cache", null) ->where("id", "=", $id) ->execute(); + $completed++; } $task->set("ptr", $ptr); $task->set("stack", implode(" ", $stack)); - $completed++; if (empty($stack)) { $state = self::FIX_STATE_START_DUPE_SLUGS; |