diff options
| author | Bharat Mediratta <bharat@menalto.com> | 2011-04-24 22:51:14 -0700 | 
|---|---|---|
| committer | Bharat Mediratta <bharat@menalto.com> | 2011-04-24 22:51:14 -0700 | 
| commit | 953be781dc91254599224fa6e95fcc435e787975 (patch) | |
| tree | 6338b2938a81ae0e78360acba01093d9bc2bd097 /modules/g2_import/helpers | |
| parent | 701c1fb12f2f254d8d7e7756a09cb5e825123a2f (diff) | |
Refactor the meat of g2_import::import_album() off into a separate
function so taht we can call it on the root album as well.  Fixes
Diffstat (limited to 'modules/g2_import/helpers')
| -rw-r--r-- | modules/g2_import/helpers/g2_import.php | 94 | ||||
| -rw-r--r-- | modules/g2_import/helpers/g2_import_task.php | 6 | 
2 files changed, 57 insertions, 43 deletions
| diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 50ab8a23..22a054ac 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -448,50 +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"); -      // 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]; -      } +      g2_import::set_album_values($album, $g2_album);        try {          $album->save(); @@ -514,6 +472,56 @@ 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) { 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) { | 
