From 72132d950570d702d1f18326f076d3e52a220989 Mon Sep 17 00:00:00 2001 From: Peter Deltchev Date: Wed, 4 Nov 2015 18:47:11 -0800 Subject: [PATCH] Added a "secret" unclassified track type for MLPMA tracks. --- app/Commands/EditTrackCommand.php | 5 +- .../PublishUnclassifiedMlpmaTracks.php | 54 +++++++++++++++++++ app/Console/Kernel.php | 1 + .../Api/Web/TaxonomiesController.php | 4 +- app/Track.php | 11 ++++ app/TrackType.php | 1 + ..._11_05_004145_AddUnclassifiedTrackType.php | 31 +++++++++++ 7 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 app/Console/Commands/PublishUnclassifiedMlpmaTracks.php create mode 100644 database/migrations/2015_11_05_004145_AddUnclassifiedTrackType.php diff --git a/app/Commands/EditTrackCommand.php b/app/Commands/EditTrackCommand.php index f1629632..a8b97c13 100644 --- a/app/Commands/EditTrackCommand.php +++ b/app/Commands/EditTrackCommand.php @@ -23,6 +23,7 @@ namespace Poniverse\Ponyfm\Commands; use Poniverse\Ponyfm\Album; use Poniverse\Ponyfm\Image; use Poniverse\Ponyfm\Track; +use Poniverse\Ponyfm\TrackType; use Poniverse\Ponyfm\User; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; @@ -65,7 +66,7 @@ class EditTrackCommand extends CommandBase 'license_id' => 'required|exists:licenses,id', 'genre_id' => 'required|exists:genres,id', 'cover' => 'image|mimes:png|min_width:350|min_height:350', - 'track_type_id' => 'required|exists:track_types,id', + 'track_type_id' => 'required|exists:track_types,id|not_in:'.TrackType::UNCLASSIFIED_TRACK, 'songs' => 'required_when:track_type,2|exists:songs,id', 'cover_id' => 'exists:images,id', 'album_id' => 'exists:albums,id' @@ -121,7 +122,7 @@ class EditTrackCommand extends CommandBase $track->album_id = null; } - if ($track->track_type_id == 2) { + if ($track->track_type_id == TrackType::OFFICIAL_TRACK_REMIX) { $track->showSongs()->sync(explode(',', $this->_input['show_song_ids'])); } else { $track->showSongs()->sync([]); diff --git a/app/Console/Commands/PublishUnclassifiedMlpmaTracks.php b/app/Console/Commands/PublishUnclassifiedMlpmaTracks.php new file mode 100644 index 00000000..a9096f7f --- /dev/null +++ b/app/Console/Commands/PublishUnclassifiedMlpmaTracks.php @@ -0,0 +1,54 @@ + + whereNull('published_at') + ->update([ + 'track_type_id' => TrackType::UNCLASSIFIED_TRACK, + 'published_at' => DB::raw('released_at'), + 'updated_at' => Carbon::now(), + ]); + + $this->info("Updated ${affectedTracks} tracks."); + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 94c282af..884d8855 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -35,6 +35,7 @@ class Kernel extends ConsoleKernel \Poniverse\Ponyfm\Console\Commands\RefreshCache::class, \Poniverse\Ponyfm\Console\Commands\ImportMLPMA::class, \Poniverse\Ponyfm\Console\Commands\ClassifyMLPMA::class, + \Poniverse\Ponyfm\Console\Commands\PublishUnclassifiedMlpmaTracks::class, \Poniverse\Ponyfm\Console\Commands\RebuildTags::class, \Poniverse\Ponyfm\Console\Commands\FixYearZeroLogs::class, \Poniverse\Ponyfm\Console\Commands\BootstrapLocalEnvironment::class, diff --git a/app/Http/Controllers/Api/Web/TaxonomiesController.php b/app/Http/Controllers/Api/Web/TaxonomiesController.php index 8085f3e9..a2107bf7 100644 --- a/app/Http/Controllers/Api/Web/TaxonomiesController.php +++ b/app/Http/Controllers/Api/Web/TaxonomiesController.php @@ -36,7 +36,9 @@ class TaxonomiesController extends ApiControllerBase 'genres' => Genre::select('genres.*', DB::raw('(SELECT COUNT(id) FROM tracks WHERE tracks.genre_id = genres.id AND tracks.published_at IS NOT NULL) AS track_count'))->orderBy('name')->get()->toArray(), 'track_types' => TrackType::select('track_types.*', - DB::raw('(SELECT COUNT(id) FROM tracks WHERE tracks.track_type_id = track_types.id AND tracks.published_at IS NOT NULL) AS track_count'))->get()->toArray(), + DB::raw('(SELECT COUNT(id) FROM tracks WHERE tracks.track_type_id = track_types.id AND tracks.published_at IS NOT NULL) AS track_count')) + ->where('id', '!=', TrackType::UNCLASSIFIED_TRACK) + ->get()->toArray(), 'show_songs' => ShowSong::select('title', 'id', 'slug', DB::raw('(SELECT COUNT(tracks.id) FROM show_song_track INNER JOIN tracks ON tracks.id = show_song_track.track_id WHERE show_song_track.show_song_id = show_songs.id AND tracks.published_at IS NOT NULL) AS track_count'))->get()->toArray() ], 200); diff --git a/app/Track.php b/app/Track.php index 027ed6a3..6781c885 100644 --- a/app/Track.php +++ b/app/Track.php @@ -20,6 +20,7 @@ namespace Poniverse\Ponyfm; +use Illuminate\Database\Query\Builder; use Poniverse\Ponyfm\Traits\SlugTrait; use Exception; use External; @@ -137,6 +138,16 @@ class Track extends Model ]); } + /** + * Limits results to MLP Music Archive tracks. + * + * @param $query + */ + public function scopeMlpma($query) + { + $query->join('mlpma_tracks', 'tracks.id', '=', 'mlpma_tracks.track_id'); + } + public static function popular($count, $allowExplicit = false) { $trackIds = Cache::remember('popular_tracks' . $count . '-' . ($allowExplicit ? 'explicit' : 'safe'), 5, diff --git a/app/TrackType.php b/app/TrackType.php index 59edd27a..23589e63 100644 --- a/app/TrackType.php +++ b/app/TrackType.php @@ -31,4 +31,5 @@ class TrackType extends Model const FAN_TRACK_REMIX = 3; const PONIFIED_TRACK = 4; const OFFICIAL_AUDIO_REMIX = 5; + const UNCLASSIFIED_TRACK = 6; } diff --git a/database/migrations/2015_11_05_004145_AddUnclassifiedTrackType.php b/database/migrations/2015_11_05_004145_AddUnclassifiedTrackType.php new file mode 100644 index 00000000..9244388f --- /dev/null +++ b/database/migrations/2015_11_05_004145_AddUnclassifiedTrackType.php @@ -0,0 +1,31 @@ +insert([ + 'id' => 6, + 'title' => 'Unclassified', + 'editor_title' => 'an unclassified track' + ]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + DB::table('track_types')->where('id', 6)->delete(); + } +}