Albums: Update folder album slug when path changes
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
5096e6201d
commit
5645cb1d0e
3 changed files with 10 additions and 7 deletions
|
@ -119,8 +119,8 @@ func NewAlbum(albumTitle, albumType string) *Album {
|
|||
}
|
||||
|
||||
// NewFolderAlbum creates a new folder album.
|
||||
func NewFolderAlbum(albumTitle, albumSlug, albumPath, albumFilter string) *Album {
|
||||
if albumTitle == "" || albumSlug == "" || albumFilter == "" {
|
||||
func NewFolderAlbum(albumTitle, albumPath, albumFilter string) *Album {
|
||||
if albumTitle == "" || albumPath == "" || albumFilter == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ func NewFolderAlbum(albumTitle, albumSlug, albumPath, albumFilter string) *Album
|
|||
AlbumOrder: SortOrderAdded,
|
||||
AlbumType: AlbumFolder,
|
||||
AlbumTitle: albumTitle,
|
||||
AlbumSlug: albumSlug,
|
||||
AlbumSlug: slug.Make(albumPath),
|
||||
AlbumPath: albumPath,
|
||||
AlbumFilter: albumFilter,
|
||||
CreatedAt: now,
|
||||
|
@ -322,7 +322,10 @@ func (m *Album) Update(attr string, value interface{}) error {
|
|||
|
||||
// UpdatePath sets a unique path for an albums.
|
||||
func (m *Album) UpdatePath(albumPath string) error {
|
||||
if err := m.Update("AlbumPath", albumPath); err != nil {
|
||||
if err := UnscopedDb().Model(m).UpdateColumns(map[string]interface{}{
|
||||
"AlbumPath": albumPath,
|
||||
"AlbumSlug": slug.Make(albumPath),
|
||||
}).Error; err != nil {
|
||||
return err
|
||||
} else if err := UnscopedDb().Exec("UPDATE albums SET album_path = NULL WHERE album_path = ? AND id <> ?", albumPath, m.ID).Error; err != nil {
|
||||
return err
|
||||
|
|
|
@ -165,7 +165,7 @@ func TestAddPhotoToAlbums(t *testing.T) {
|
|||
|
||||
func TestNewFolderAlbum(t *testing.T) {
|
||||
t.Run("name Christmas 2018", func(t *testing.T) {
|
||||
album := NewFolderAlbum("Dogs", "dogs", "dogs", "label:dog")
|
||||
album := NewFolderAlbum("Dogs", "dogs", "label:dog")
|
||||
assert.Equal(t, "Dogs", album.AlbumTitle)
|
||||
assert.Equal(t, "dogs", album.AlbumSlug)
|
||||
assert.Equal(t, AlbumFolder, album.AlbumType)
|
||||
|
@ -173,7 +173,7 @@ func TestNewFolderAlbum(t *testing.T) {
|
|||
assert.Equal(t, "label:dog", album.AlbumFilter)
|
||||
})
|
||||
t.Run("title empty", func(t *testing.T) {
|
||||
album := NewFolderAlbum("", "dogs", "dogs", "label:dog")
|
||||
album := NewFolderAlbum("", "dogs", "label:dog")
|
||||
assert.Nil(t, album)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func (m *Moments) Start() (err error) {
|
|||
} else {
|
||||
log.Tracef("moments: %s already exists (%s)", txt.Quote(a.AlbumTitle), a.AlbumFilter)
|
||||
}
|
||||
} else if a := entity.NewFolderAlbum(mom.Title(), mom.Slug(), mom.Path, f.Serialize()); a != nil {
|
||||
} else if a := entity.NewFolderAlbum(mom.Title(), mom.Path, f.Serialize()); a != nil {
|
||||
a.AlbumYear = mom.FolderYear
|
||||
a.AlbumMonth = mom.FolderMonth
|
||||
a.AlbumDay = mom.FolderDay
|
||||
|
|
Loading…
Reference in a new issue