예제 #1
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);
 }
예제 #2
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();
 }
예제 #3
0
파일: g2image.php 프로젝트: crosby823/pgd
/**
 * Generates album hierarchy as d.add entites of dtree
 *
 * @param int $current_album id of current album
 * @param int $parent node of the parent album
 */
function g2ic_make_html_album_tree_branches($current_album, $parent, &$node)
{
    global $g2ic_options;
    list($error, $items) = GalleryCoreApi::loadEntitiesById(array($current_album));
    if (!$error) {
        foreach ($items as $item) {
            $album_title = $item->getTitle();
            $album_title = preg_replace("/(\n|\r)/", " ", $album_title);
            // Bug #44
            if (empty($album_title)) {
                $album_title = $item->getPathComponent();
            }
        }
        $html = '        d.add(' . $node . ',' . $parent . ',"' . $album_title . '","' . '?current_album=' . $current_album . '&sortby=' . $g2ic_options['sortby'] . '&images_per_page=' . $g2ic_options['images_per_page'] . '");' . "\n";
    }
    list($error, $sub_albums) = GalleryCoreApi::fetchAlbumTree($current_album, 1);
    $albums = array_keys($sub_albums);
    if (count($albums) > 0) {
        $parent = $node;
        foreach ($albums as $album) {
            $node++;
            $html .= g2ic_make_html_album_tree_branches($album, $parent, $node);
        }
    }
    return $html;
}
예제 #4
0
 /**
  * Creates a new gallery/album under the given
  * parent album.  The name/title and description
  * will be keyed off of the given event object.
  *
  * @param string $parentAlbum
  * @param Event or Person $bean
  * @param string $name a title to specify (optional -- will use getTitle if not specified)
  * @return int id of the created/found album or null if not created
  */
 public function createAlbum($parent, $bean, $name = null)
 {
     global $mosConfig_absolute_path, $gallery;
     global $logger;
     $logger->debug(get_class($this) . "::createAlbum({$parent}, {$bean}, {$name})");
     $parentId = null;
     if ($name) {
         $pathname = strtolower(preg_replace("/ /", '_', $name));
         $title = $name;
     } else {
         $pathname = strtolower(preg_replace("/ /", '_', $bean->getTitle()));
         $title = $bean->getTitle();
     }
     $summary = '';
     $description = '';
     $keywords = '';
     $albumId = null;
     // get the parent album id
     $ret = $this->initGalleryApi();
     list($ret, $tree) = GalleryCoreApi::fetchAlbumTree();
     $name = constant("GalleryService::PARENT_" . strtoupper($parent) . "_ALBUM");
     $logger->debug("Looking for Parent Album Name:" . $name);
     foreach ($tree as $key => $value) {
         list($ret, $album) = GalleryCoreApi::loadEntitiesById($key);
         if (strtolower($album->getPathComponent()) == strtolower($name)) {
             $parentId = $key;
             // we have a matching parent
             break;
         }
     }
     $logger->debug("Found Parent Album ID:" . $parentId);
     // see if there is already an album by path
     list($ret, $current) = GalleryCoreApi::fetchChildIdByPathComponent($parentId, $pathname);
     if ($current) {
         $albumId = $current;
     } else {
         // create the new album
         list($ret, $created) = GalleryCoreApi::createAlbum($parentId, $pathname, $title, $summary, $description, $keywords);
         $albumId = $created ? $created->getId() : '';
         // now create the child highlight album
         if ($albumId) {
             list($ret, $hlCreated) = GalleryCoreApi::createAlbum($albumId, strtolower(CHILD_HIGHLIGHT_ALBUM), CHILD_HIGHTLIGHT_ALBUM, $summary, $description, $keywords);
             $highlightId = $hlCreated ? $hlCreated->getId() : "";
         }
     }
     $logger->debug("Created album with id: " . $albumId . " and highlights id: " . $highlightId);
     /* Complete our transaction */
     if ($gallery->isStorageInitialized()) {
         $storage =& $gallery->getStorage();
         $ret = $storage->commitTransaction();
     }
     return $albumId;
 }