From 6b4d874a5d198626c5ef9cbe94fea8bb18f6a89a Mon Sep 17 00:00:00 2001 From: Peter Deltchev Date: Wed, 28 Oct 2015 09:40:07 -0700 Subject: [PATCH] Added track_files records for deleted tracks. --- ...2015_10_26_231224_AddTrackSourceColumn.php | 18 +++++ ...8_162655_AddTrackFilesForDeletedTracks.php | 68 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 database/migrations/2015_10_28_162655_AddTrackFilesForDeletedTracks.php diff --git a/database/migrations/2015_10_26_231224_AddTrackSourceColumn.php b/database/migrations/2015_10_26_231224_AddTrackSourceColumn.php index c9631c15..dfa4ec01 100644 --- a/database/migrations/2015_10_26_231224_AddTrackSourceColumn.php +++ b/database/migrations/2015_10_26_231224_AddTrackSourceColumn.php @@ -1,5 +1,23 @@ . + */ + use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; diff --git a/database/migrations/2015_10_28_162655_AddTrackFilesForDeletedTracks.php b/database/migrations/2015_10_28_162655_AddTrackFilesForDeletedTracks.php new file mode 100644 index 00000000..0763ef03 --- /dev/null +++ b/database/migrations/2015_10_28_162655_AddTrackFilesForDeletedTracks.php @@ -0,0 +1,68 @@ +. + */ + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Migrations\Migration; +use Poniverse\Ponyfm\Track; + +class AddTrackFilesForDeletedTracks extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + // 2015_05_25_011121_create_track_files_table.php only created + // track_files records for non-deleted tracks. This migration + // adds them for deleted tracks, too. + + $tracks = Track::with('trackFiles') + ->onlyTrashed() + ->get(); + + foreach ($tracks as $track) { + if ($track->trackFiles->count() === 0 && $track->source !== 'mlpma') { + foreach (Track::$Formats as $name => $item) { + DB::table('track_files')->insert( + [ + 'track_id' => $track->id, + 'is_master' => $name === 'FLAC' ? true : false, + 'format' => $name, + 'created_at' => $track->created_at, + 'updated_at' => Carbon\Carbon::now() + ] + ); + } + } + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // There's no need to undo this one! + } +}