Esempio n. 1
0
 /**
  * Return a set of statistics about the number of users, groups, albums, photos, movies and
  * comments available for import from the Gallery 2 instance.
  */
 static function stats()
 {
     global $gallery;
     $root_album_id = g2(GalleryCoreApi::getDefaultAlbumId());
     $stats["users"] = g2(GalleryCoreApi::fetchUserCount());
     $stats["groups"] = g2(GalleryCoreApi::fetchGroupCount());
     $stats["albums"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryAlbumItem"));
     $stats["photos"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryPhotoItem"));
     $stats["movies"] = g2(GalleryCoreApi::fetchItemIdCount("GalleryMovieItem"));
     if (g2_import::g2_module_active("comment") && module::is_active("comment")) {
         GalleryCoreApi::requireOnce("modules/comment/classes/GalleryCommentHelper.class");
         list(, $stats["comments"]) = g2(GalleryCommentHelper::fetchAllComments($root_album_id, 1));
     } else {
         $stats["comments"] = 0;
     }
     if (g2_import::g2_module_active("tags") && module::is_active("tag")) {
         $result = g2($gallery->search("SELECT COUNT(DISTINCT([TagItemMap::itemId])) FROM [TagItemMap]"))->nextResult();
         $stats["tags"] = $result[0];
     } else {
         $stats["tags"] = 0;
     }
     return $stats;
 }
Esempio n. 2
0
/**
 * Get all of the options set in $_REQUEST and/or $_SESSION
 */
function g2ic_get_request_and_session_options()
{
    global $g2ic_options;
    // Get the root album
    // Check for G2 Core API >= 7.5.  getDefaultAlbumId only available at 7.5 or above
    if (GalleryUtilities::isCompatibleWithApi(array(7, 5), GalleryCoreApi::getApiVersion())) {
        list($error, $g2ic_options['root_album']) = GalleryCoreApi::getDefaultAlbumId();
    } else {
        list($error, $g2ic_options['root_album']) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum');
    }
    g2ic_magic_quotes_remove($_REQUEST);
    // Is this a TinyMCE window?
    if (isset($_REQUEST['g2ic_tinymce'])) {
        $g2ic_options['tinymce'] = $_REQUEST['g2ic_tinymce'];
        $_SESSION['g2ic_tinymce'] = $_REQUEST['g2ic_tinymce'];
    } else {
        if (isset($_SESSION['g2ic_tinymce'])) {
            $g2ic_options['tinymce'] = $_SESSION['g2ic_tinymce'];
        } else {
            $g2ic_options['tinymce'] = 0;
        }
    }
    // Get the form name (if set) for insertion (not TinyMCE or FCKEditor)
    if (isset($_REQUEST['g2ic_form'])) {
        $g2ic_options['form'] = $_REQUEST['g2ic_form'];
        $_SESSION['g2ic_form'] = $_REQUEST['g2ic_form'];
    } else {
        if (isset($_SESSION['g2ic_form'])) {
            $g2ic_options['form'] = $_SESSION['g2ic_form'];
        } else {
            $g2ic_options['form'] = '';
        }
    }
    // Get the field name (if set) for insertion (not TinyMCE or FCKEditor)
    if (isset($_REQUEST['g2ic_field'])) {
        $g2ic_options['field'] = $_REQUEST['g2ic_field'];
        $_SESSION['g2ic_field'] = $_REQUEST['g2ic_field'];
    } else {
        if (isset($_SESSION['g2ic_field'])) {
            $g2ic_options['field'] = $_SESSION['g2ic_field'];
        } else {
            $g2ic_options['field'] = '';
        }
    }
    // Get the last album visited
    if (isset($_SESSION['g2ic_last_album_visited'])) {
        $g2ic_options['last_album'] = $_SESSION['g2ic_last_album_visited'];
    } else {
        $g2ic_options['last_album'] = $g2ic_options['root_album'];
    }
    // Get the current album
    if (isset($_REQUEST['current_album'])) {
        $g2ic_options['current_album'] = $_REQUEST['current_album'];
    } else {
        $g2ic_options['current_album'] = $g2ic_options['last_album'];
    }
    // Get the current page
    if (isset($_REQUEST['g2ic_page']) and is_numeric($_REQUEST['g2ic_page'])) {
        $g2ic_options['current_page'] = floor($_REQUEST['g2ic_page']);
    } else {
        $g2ic_options['current_page'] = 1;
    }
    // Get the current sort method
    if (isset($_REQUEST['sortby'])) {
        $g2ic_options['sortby'] = $_REQUEST['sortby'];
    }
    // Determine whether to display the titles or keep them hidden
    if (isset($_REQUEST['display'])) {
        if ($_REQUEST['display'] == 'filenames') {
            $g2ic_options['display_filenames'] = TRUE;
        }
    }
    // Determine how many images to display per page
    if (isset($_REQUEST['images_per_page'])) {
        $g2ic_options['images_per_page'] = $_REQUEST['images_per_page'];
    }
    return;
}
Esempio n. 3
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);
 }
Esempio n. 4
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();
 }