       edegalAlbum =
         path: path.join(parent.path, slug)
         breadcrumb: breadcrumb
-        thumbnail: PLACEHOLDER_IMAGE
         title: coppermineAlbum.title
         description: coppermineAlbum.description
         subalbums: []
         pictures: []
 
-      parent.subalbums.push _.pick edegalAlbum, 'path', 'title', 'thumbnail'
-      convertPictures(coppermineAlbum.aid, edegalAlbum, indent + 1).then -> saveAlbum(edegalAlbum)
+      convertPictures(coppermineAlbum.aid, edegalAlbum, indent + 1).then ->
+        setThumbnail edegalAlbum
+        parent.subalbums.push _.pick edegalAlbum, 'path', 'title', 'thumbnail'
+        saveAlbum edegalAlbum
 
 convertPictures = (albumId, parent, indent=0) ->
   query('SELECT pid, filename, filepath, title, caption FROM cpg11d_pictures WHERE aid = ? ORDER BY position', [albumId]).spread (pictures) ->

Q = require 'q'
_ = require 'underscore'
path = require 'path'
originalSlugify = require 'slug'

{albums, createIndexes, dropAlbums, getAlbum, saveAlbum} = require '../server/db.coffee'


    title: parent.title
  ]

setThumbnail = (album) ->
  album.thumbnail = 
    album.thumbnail ?
    _.first(album.pictures)?.thumbnail ?
    _.first(album.subalbums)?.thumbnail ?
    PLACEHOLDER_IMAGE

convertCoppermine = ->
  Q.all([
    dropAlbums().fail(-> null)
