diff options
Diffstat (limited to 'modules/g2_import/helpers')
| -rw-r--r-- | modules/g2_import/helpers/g2_import.php | 102 | ||||
| -rw-r--r-- | modules/g2_import/helpers/g2_import_event.php | 2 | ||||
| -rw-r--r-- | modules/g2_import/helpers/g2_import_task.php | 6 | 
3 files changed, 62 insertions, 48 deletions
| diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 23fb29e5..22a054ac 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -448,49 +448,8 @@ class g2_import_Core {        $album = ORM::factory("item");        $album->type = "album";        $album->parent_id = self::map($g2_album->getParentId()); -      $album->name = $g2_album->getPathComponent(); -      $album->title = self::_decode_html_special_chars($g2_album->getTitle()); -      $album->title or $album->title = $album->name; -      $album->description = self::_decode_html_special_chars(self::extract_description($g2_album)); -      $album->owner_id = self::map($g2_album->getOwnerId()); -      try { -        $album->view_count = (int) g2(GalleryCoreApi::fetchItemViewCount($g2_album_id)); -      } catch (Exception $e) { -        // @todo log -        $album->view_count = 0; -      } -      $album->created = $g2_album->getCreationTimestamp(); -      $order_map = array( -        "originationTimestamp" => "captured", -        "creationTimestamp" => "created", -        "description" => "description", -        "modificationTimestamp" => "updated", -        "orderWeight" => "weight", -        "pathComponent" => "name", -        "summary" => "description", -        "title" => "title", -        "viewCount" => "view_count"); -      $direction_map = array( -        1 => "ASC", -        ORDER_ASCENDING => "ASC", -        ORDER_DESCENDING => "DESC"); -      // Only consider G2's first sort order -      $g2_order = explode("|", $g2_album->getOrderBy() . ""); -      $g2_order = $g2_order[0]; -      if (empty($g2_order)) { -        $g2_order = g2(GalleryCoreApi::getPluginParameter('module', 'core', 'default.orderBy')); -      } -      $g2_order_direction = explode("|", $g2_album->getOrderDirection() . ""); -      $g2_order_direction = $g2_order_direction[0]; -      if (empty($g2_order_direction)) { -        $g2_order_direction = -          g2(GalleryCoreApi::getPluginParameter('module', 'core', 'default.orderDirection')); -      } -      if (array_key_exists($g2_order, $order_map)) { -        $album->sort_column = $order_map[$g2_order]; -        $album->sort_order = $direction_map[$g2_order_direction]; -      } +      g2_import::set_album_values($album, $g2_album);        try {          $album->save(); @@ -513,17 +472,66 @@ class g2_import_Core {    }    /** +   * Transfer over all the values from a G2 album to a G3 album. +   */ +  static function set_album_values($album, $g2_album) { +    $album->name = $g2_album->getPathComponent(); +    $album->title = self::_decode_html_special_chars($g2_album->getTitle()); +    $album->title or $album->title = $album->name; +    $album->description = self::_decode_html_special_chars(self::extract_description($g2_album)); +    $album->owner_id = self::map($g2_album->getOwnerId()); +    try { +      $album->view_count = (int) g2(GalleryCoreApi::fetchItemViewCount($g2_album_id)); +    } catch (Exception $e) { +      // @todo log +      $album->view_count = 0; +    } +    $album->created = $g2_album->getCreationTimestamp(); + +    $order_map = array( +      "originationTimestamp" => "captured", +      "creationTimestamp" => "created", +      "description" => "description", +      "modificationTimestamp" => "updated", +      "orderWeight" => "weight", +      "pathComponent" => "name", +      "summary" => "description", +      "title" => "title", +      "viewCount" => "view_count"); +    $direction_map = array( +      1 => "ASC", +      ORDER_ASCENDING => "ASC", +      ORDER_DESCENDING => "DESC"); +    // G2 sorts can either be <sort> or <presort>|<sort>.  Right now we can't +    // map presorts so ignore them. +    $g2_order = explode("|", $g2_album->getOrderBy() . ""); +    $g2_order = end($g2_order); +    if (empty($g2_order)) { +      $g2_order = g2(GalleryCoreApi::getPluginParameter('module', 'core', 'default.orderBy')); +    } +    $g2_order_direction = explode("|", $g2_album->getOrderDirection() . ""); +    $g2_order_direction = $g2_order_direction[0]; +    if (empty($g2_order_direction)) { +      $g2_order_direction = +        g2(GalleryCoreApi::getPluginParameter('module', 'core', 'default.orderDirection')); +    } +    if (array_key_exists($g2_order, $order_map)) { +      $album->sort_column = $order_map[$g2_order]; +      $album->sort_order = $direction_map[$g2_order_direction]; +    } +  } + +  /**     * Set the highlight properly for a single album     */    static function set_album_highlight(&$queue) {      // Dequeue the current album and enqueue its children      list($g2_album_id, $children) = each($queue); -    if (empty($children)) { -      return; -    }      unset($queue[$g2_album_id]); -    foreach ($children as $key => $value) { -      $queue[$key] = $value; +    if (!empty($children)) { +      foreach ($children as $key => $value) { +        $queue[$key] = $value; +      }      }      $messages = array(); diff --git a/modules/g2_import/helpers/g2_import_event.php b/modules/g2_import/helpers/g2_import_event.php index 0e078d08..0afa62d8 100644 --- a/modules/g2_import/helpers/g2_import_event.php +++ b/modules/g2_import/helpers/g2_import_event.php @@ -34,7 +34,7 @@ class g2_import_event_Core {        ->get("settings_menu")        ->append(Menu::factory("link")                 ->id("g2_import") -               ->label(t("Gallery 2 Import")) +               ->label(t("Gallery 2 import"))                 ->url(url::site("admin/g2_import")));    }  } diff --git a/modules/g2_import/helpers/g2_import_task.php b/modules/g2_import/helpers/g2_import_task.php index 5e908676..31615a55 100644 --- a/modules/g2_import/helpers/g2_import_task.php +++ b/modules/g2_import/helpers/g2_import_task.php @@ -127,6 +127,12 @@ class g2_import_task_Core {            $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) { | 
