Пример #1
0
 /**
  * Tidy up the library by deleting empty albums and artists.
  */
 public function tidy()
 {
     $inUseAlbums = Song::select('album_id')->groupBy('album_id')->get()->pluck('album_id')->toArray();
     $inUseAlbums[] = Album::UNKNOWN_ID;
     Album::deleteWhereIDsNotIn($inUseAlbums);
     $inUseArtists = Album::select('artist_id')->groupBy('artist_id')->get()->pluck('artist_id')->toArray();
     $contributingArtists = Song::distinct()->select('contributing_artist_id')->groupBy('contributing_artist_id')->get()->pluck('contributing_artist_id')->toArray();
     $inUseArtists = array_merge($inUseArtists, $contributingArtists);
     $inUseArtists[] = Artist::UNKNOWN_ID;
     $inUseArtists[] = Artist::VARIOUS_ID;
     Artist::deleteWhereIDsNotIn(array_filter($inUseArtists));
 }