Пример #1
0
 public function index()
 {
     g2_import::lower_error_reporting();
     if (g2_import::is_configured()) {
         g2_import::init();
     }
     if (class_exists("GalleryCoreApi")) {
         $g2_stats = g2_import::stats();
         $g2_sizes = g2_import::common_sizes();
     }
     $view = new Admin_View("admin.html");
     $view->page_title = t("Gallery 2 import");
     $view->content = new View("admin_g2_import.html");
     $view->content->form = $this->_get_import_form();
     $view->content->version = "";
     if (g2_import::is_initialized()) {
         $view->content->g2_stats = $g2_stats;
         $view->content->g2_sizes = $g2_sizes;
         $view->content->thumb_size = module::get_var("gallery", "thumb_size");
         $view->content->resize_size = module::get_var("gallery", "resize_size");
         $view->content->version = g2_import::version();
     } else {
         if (g2_import::is_configured()) {
             $view->content->form->configure_g2_import->embed_path->add_error("invalid", 1);
         }
     }
     g2_import::restore_error_reporting();
     print $view;
 }
Пример #2
0
 static function init()
 {
     if (g2_import::$init) {
         return;
     }
     $embed_path = module::get_var("g2_import", "embed_path");
     if (empty($embed_path)) {
         throw new Exception("@todo G2_IMPORT_NOT_CONFIGURED");
     }
     g2_import::$init = g2_import::init_embed($embed_path);
 }
Пример #3
0
 public function index()
 {
     if (g2_import::is_configured()) {
         g2_import::init();
         $g2_stats = g2_import::stats();
         $g2_sizes = g2_import::common_sizes();
     }
     $view = new Admin_View("admin.html");
     $view->content = new View("admin_g2_import.html");
     $view->content->form = $this->_get_import_form();
     if (g2_import::is_initialized()) {
         $view->content->g2_stats = $g2_stats;
         $view->content->g2_sizes = $g2_sizes;
         $view->content->thumb_size = module::get_var("gallery", "thumb_size");
         $view->content->resize_size = module::get_var("gallery", "resize_size");
     }
     print $view;
 }
Пример #4
0
 public function index()
 {
     g2_import::lower_error_reporting();
     if (g2_import::is_configured()) {
         g2_import::init();
     }
     $view = new Admin_View("admin.html");
     $view->page_title = t("Gallery 2 import");
     $view->content = new View("admin_g2_import.html");
     if (class_exists("GalleryCoreApi")) {
         $view->content->g2_stats = $g2_stats = g2_import::g2_stats();
         $view->content->g3_stats = $g3_stats = g2_import::g3_stats();
         $view->content->g2_sizes = g2_import::common_sizes();
         $view->content->g2_version = g2_import::version();
         // Don't count tags because we don't track them in g2_map
         $view->content->g2_resource_count = $g2_stats["users"] + $g2_stats["groups"] + $g2_stats["albums"] + $g2_stats["photos"] + $g2_stats["movies"] + $g2_stats["comments"];
         $view->content->g3_resource_count = $g3_stats["user"] + $g3_stats["group"] + $g3_stats["album"] + $g3_stats["item"] + $g3_stats["comment"] + $g3_stats["tag"];
     }
     $view->content->form = $this->_get_import_form();
     $view->content->version = "";
     $view->content->thumb_size = module::get_var("gallery", "thumb_size");
     $view->content->resize_size = module::get_var("gallery", "resize_size");
     if (g2_import::is_initialized()) {
         if ((bool) ini_get("eaccelerator.enable") || (bool) ini_get("xcache.cacher")) {
             message::warning(t("The eAccelerator and XCache PHP performance extensions are known to cause issues.  If you're using either of those and are having problems, please disable them while you do your import.  Add the following lines: <pre>%lines</pre> to gallery3/.htaccess and remove them when the import is done.", array("lines" => "\n\n  php_value eaccelerator.enable 0\n  php_value xcache.cacher off\n  php_value xcache.optimizer off\n\n")));
         }
         foreach (array("notification", "search", "exif") as $module_id) {
             if (module::is_active($module_id)) {
                 message::warning(t("<a href=\"%url\">Deactivating</a> the <b>%module_id</b> module during your import will make it faster", array("url" => url::site("admin/modules"), "module_id" => $module_id)));
             }
         }
         if (module::is_active("akismet")) {
             message::warning(t("The Akismet module may mark some or all of your imported comments as spam.  <a href=\"%url\">Deactivate</a> it to avoid that outcome.", array("url" => url::site("admin/modules"))));
         }
     } else {
         if (g2_import::is_configured()) {
             $view->content->form->configure_g2_import->embed_path->add_error("invalid", 1);
         }
     }
     g2_import::restore_error_reporting();
     print $view;
 }
Пример #5
0
 static function import($task)
 {
     $start = microtime(true);
     g2_import::init();
     $stats = $task->get("stats");
     $done = $task->get("done");
     $total = $task->get("total");
     $completed = $task->get("completed");
     $mode = $task->get("mode");
     $queue = $task->get("queue");
     if (!isset($mode)) {
         $stats = g2_import::stats();
         $stats["items"] = $stats["photos"] + $stats["movies"];
         unset($stats["photos"]);
         unset($stats["movies"]);
         $stats["highlights"] = $stats["albums"];
         $task->set("stats", $stats);
         $task->set("total", $total = array_sum(array_values($stats)));
         $completed = 0;
         $mode = 0;
         $done = array();
         foreach (array_keys($stats) as $key) {
             $done[$key] = 0;
         }
         $task->set("done", $done);
         $root_g2_id = g2(GalleryCoreApi::getDefaultAlbumId());
         $root = ORM::factory("g2_map")->where("g2_id", "=", $root_g2_id)->find();
         if (!$root->loaded()) {
             $root->g2_id = $root_g2_id;
             $root->g3_id = 1;
             $root->save();
         }
     }
     $modes = array("groups", "users", "albums", "items", "comments", "tags", "highlights", "done");
     while (!$task->done && microtime(true) - $start < 1.5) {
         if ($done[$modes[$mode]] == $stats[$modes[$mode]]) {
             // Nothing left to do for this mode.  Advance.
             $mode++;
             $task->set("last_id", 0);
             $queue = array();
             // Start the loop from the beginning again.  This way if we get to a mode that requires no
             // actions (eg, if the G2 comments module isn't installed) we won't try to do any comments
             // queries.. in the next iteration we'll just skip over that mode.
             if ($modes[$mode] != "done") {
                 continue;
             }
         }
         switch ($modes[$mode]) {
             case "groups":
                 if (empty($queue)) {
                     $task->set("queue", $queue = array_keys(g2(GalleryCoreApi::fetchGroupNames())));
                 }
                 $log_message = g2_import::import_group($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing groups (%count of %total)", array("count" => $done["groups"] + 1, "total" => $stats["groups"]));
                 break;
             case "users":
                 if (empty($queue)) {
                     $task->set("queue", $queue = array_keys(g2(GalleryCoreApi::fetchUsersForGroup(GROUP_EVERYBODY))));
                 }
                 $log_message = g2_import::import_user($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing users (%count of %total)", array("count" => $done["users"] + 1, "total" => $stats["users"]));
                 break;
             case "albums":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree()));
                 }
                 $log_message = g2_import::import_album($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing albums (%count of %total)", array("count" => $done["albums"] + 1, "total" => $stats["albums"]));
                 break;
             case "items":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_item_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_item($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing photos (%count of %total)", array("count" => $done["items"] + 1, "total" => $stats["items"]));
                 break;
             case "comments":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_comment_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_comment($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing comments (%count of %total)", array("count" => $done["comments"] + 1, "total" => $stats["comments"]));
                 break;
             case "tags":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_tag_item_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_tags_for_item($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing tags (%count of %total)", array("count" => $done["tags"] + 1, "total" => $stats["tags"]));
                 break;
             case "highlights":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree()));
                 }
                 $log_message = g2_import::set_album_highlight($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Album highlights (%count of %total)", array("count" => $done["tags"] + 1, "total" => $stats["albums"]));
                 break;
             case "done":
                 $task->status = t("Import complete");
                 $task->done = true;
                 $task->state = "success";
                 break;
         }
         if (!$task->done) {
             $done[$modes[$mode]]++;
             $completed++;
         }
     }
     $task->percent_complete = 100 * ($completed / $total);
     $task->set("completed", $completed);
     $task->set("mode", $mode);
     $task->set("queue", $queue);
     $task->set("done", $done);
 }
Пример #6
0
 static function import($task)
 {
     g2_import::lower_error_reporting();
     $start = microtime(true);
     g2_import::init();
     $stats = $task->get("stats");
     $done = $task->get("done");
     $total = $task->get("total");
     $completed = $task->get("completed");
     $mode = $task->get("mode");
     $queue = $task->get("queue");
     if (!isset($mode)) {
         $stats = g2_import::g2_stats();
         $stats["items"] = $stats["photos"] + $stats["movies"];
         unset($stats["photos"]);
         unset($stats["movies"]);
         $stats["highlights"] = $stats["albums"];
         $task->set("stats", $stats);
         $task->set("total", $total = array_sum(array_values($stats)));
         $completed = 0;
         $mode = 0;
         $done = array();
         foreach (array_keys($stats) as $key) {
             $done[$key] = 0;
         }
         $task->set("done", $done);
         // Ensure G2 ACLs are compacted to speed up import.
         g2(GalleryCoreApi::compactAccessLists());
     }
     $modes = array("groups", "users", "albums", "items", "comments", "tags", "highlights", "done");
     while (!$task->done && microtime(true) - $start < 1.5) {
         if ($done[$modes[$mode]] == $stats[$modes[$mode]]) {
             // Nothing left to do for this mode.  Advance.
             $mode++;
             $task->set("last_id", 0);
             $queue = array();
             // Start the loop from the beginning again.  This way if we get to a mode that requires no
             // actions (eg, if the G2 comments module isn't installed) we won't try to do any comments
             // queries.. in the next iteration we'll just skip over that mode.
             if ($modes[$mode] != "done") {
                 continue;
             }
         }
         switch ($modes[$mode]) {
             case "groups":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_group_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_group($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing groups (%count of %total)", array("count" => $done["groups"] + 1, "total" => $stats["groups"]));
                 break;
             case "users":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_user_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_user($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing users (%count of %total)", array("count" => $done["users"] + 1, "total" => $stats["users"]));
                 break;
             case "albums":
                 if (empty($queue)) {
                     $g2_root_id = g2(GalleryCoreApi::getDefaultAlbumId());
                     $tree = g2(GalleryCoreApi::fetchAlbumTree());
                     $task->set("queue", $queue = array($g2_root_id => $tree));
                     // Update the root album to reflect the Gallery2 root album.
                     $root_album = item::root();
                     g2_import::set_album_values($root_album, g2(GalleryCoreApi::loadEntitiesById($g2_root_id)));
                     $root_album->save();
                 }
                 $log_message = g2_import::import_album($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing albums (%count of %total)", array("count" => $done["albums"] + 1, "total" => $stats["albums"]));
                 break;
             case "items":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_item_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_item($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing photos (%count of %total)", array("count" => $done["items"] + 1, "total" => $stats["items"]));
                 break;
             case "comments":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_comment_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_comment($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing comments (%count of %total)", array("count" => $done["comments"] + 1, "total" => $stats["comments"]));
                 break;
             case "tags":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_tag_item_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_tags_for_item($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing tags (%count of %total)", array("count" => $done["tags"] + 1, "total" => $stats["tags"]));
                 break;
             case "highlights":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree()));
                 }
                 $log_message = g2_import::set_album_highlight($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Album highlights (%count of %total)", array("count" => $done["highlights"] + 1, "total" => $stats["highlights"]));
                 break;
             case "done":
                 $task->status = t("Import complete");
                 $task->done = true;
                 $task->state = "success";
                 break;
         }
         if (!$task->done) {
             $done[$modes[$mode]]++;
             $completed++;
         }
     }
     $task->percent_complete = 100 * ($completed / $total);
     $task->set("completed", $completed);
     $task->set("mode", $mode);
     $task->set("queue", $queue);
     $task->set("done", $done);
     g2_import::restore_error_reporting();
 }