From c6dc6aae3290f15ef681744c14c172fcee8063c3 Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Sat, 23 Sep 2017 08:36:15 +0100 Subject: [PATCH] EQBeats import script and db migration --- app/Commands/UploadTrackCommand.php | 2 +- .../{ImportPonify.php => ImportEQBeats.php} | 19 ++++---- .../Controllers/Api/Web/TracksController.php | 10 ++-- .../2017_09_22_082723_CreateEQBeatsTracks.php | 48 +++++++++++++++++++ 4 files changed, 64 insertions(+), 15 deletions(-) rename app/Console/Commands/{ImportPonify.php => ImportEQBeats.php} (98%) create mode 100644 database/migrations/2017_09_22_082723_CreateEQBeatsTracks.php diff --git a/app/Commands/UploadTrackCommand.php b/app/Commands/UploadTrackCommand.php index 0648aa77..2ccee33c 100644 --- a/app/Commands/UploadTrackCommand.php +++ b/app/Commands/UploadTrackCommand.php @@ -101,7 +101,7 @@ class UploadTrackCommand extends CommandBase if ($this->_file !== null) { $trackFile = $this->_file; - $source = 'ponify'; + $source = 'eqbeats'; } else { $trackFile = Request::file('track', null); } diff --git a/app/Console/Commands/ImportPonify.php b/app/Console/Commands/ImportEQBeats.php similarity index 98% rename from app/Console/Commands/ImportPonify.php rename to app/Console/Commands/ImportEQBeats.php index 97a9b6ae..ee338488 100644 --- a/app/Console/Commands/ImportPonify.php +++ b/app/Console/Commands/ImportEQBeats.php @@ -19,22 +19,23 @@ use Illuminate\Console\Command; use Illuminate\Support\Str; use Symfony\Component\HttpFoundation\File\UploadedFile; -class ImportPonify extends Command +class ImportEQBeats extends Command { /** * The name and signature of the console command. * * @var string */ - protected $signature = 'ponify:import - {--startAt=1 : Track to start importing from. Useful for resuming an interrupted import.}'; + protected $signature = 'eqbeats:import + {--startAt=1 : Track to start importing from. Useful for resuming an interrupted import.} + {archiveFolder : Absolute location of archive to import}'; /** * The console command description. * * @var string */ - protected $description = 'Imports the Ponify archive'; + protected $description = 'Imports the EQBeats archive'; /** * File extensions to ignore when importing the archive. @@ -84,7 +85,7 @@ class ImportPonify extends Command pcntl_signal(SIGINT, [$this, 'handleInterrupt']); - $ponifyPath = Config::get('ponyfm.ponify_directory'); + $archivePath = $this->argument('archiveFolder'); $tmpPath = Config::get('ponyfm.files_directory').'/tmp'; if (!File::exists($tmpPath)) { @@ -99,12 +100,12 @@ class ImportPonify extends Command //========================================================================================================== // Get the list of files and artists //========================================================================================================== - $this->comment('Enumerating Ponify files...'); - $files = File::allFiles($ponifyPath); + $this->comment('Enumerating files...'); + $files = File::allFiles($archivePath); $this->info(sizeof($files) . ' files found!'); $this->comment('Enumerating artists...'); - $artists = File::directories($ponifyPath); + $artists = File::directories($archivePath); $this->info(sizeof($artists) . ' artists found!'); $this->comment('Importing tracks...'); @@ -496,7 +497,7 @@ class ImportPonify extends Command $track->save(); // If we made it to here, the track is intact! Log the import. - DB::table('ponify_tracks') + DB::table('eqbeats_tracks') ->insert([ 'track_id' => $result->getResponse()['id'], 'path' => $file->getRelativePath(), diff --git a/app/Http/Controllers/Api/Web/TracksController.php b/app/Http/Controllers/Api/Web/TracksController.php index a743763f..ae07c300 100644 --- a/app/Http/Controllers/Api/Web/TracksController.php +++ b/app/Http/Controllers/Api/Web/TracksController.php @@ -352,11 +352,11 @@ class TracksController extends ApiControllerBase } }); - if ($archive == "mlpma") { - $query->join('mlpma_tracks', 'tracks.id', '=', 'mlpma_tracks.track_id'); - } elseif ($archive == "ponify") { - $query->join('ponify_tracks', 'tracks.id', '=', 'ponify_tracks.track_id'); - } + $archives = ['mlpma', 'ponify', 'eqbeats']; + $akey = array_search($archive, $archives); + + if (!$akey) + $query->join($archive . '_tracks', 'tracks.id', '=', $archive . 'tracks.track_id'); } if (Request::has('songs')) { diff --git a/database/migrations/2017_09_22_082723_CreateEQBeatsTracks.php b/database/migrations/2017_09_22_082723_CreateEQBeatsTracks.php new file mode 100644 index 00000000..81815184 --- /dev/null +++ b/database/migrations/2017_09_22_082723_CreateEQBeatsTracks.php @@ -0,0 +1,48 @@ +increments('id'); + $table->integer('track_id')->unsigned()->index(); + $table->string('path')->index(); + $table->string('filename')->index(); + $table->string('extension')->index(); + $table->dateTime('imported_at'); + $table->text('parsed_tags'); + $table->text('raw_tags'); + }); + + Schema::table('eqbeats_tracks', function(Blueprint $table) + { + $table->foreign('track_id')->references('id')->on('tracks')->onUpdate('RESTRICT')->onDelete('RESTRICT'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('eqbeats_tracks', function(Blueprint $table) + { + $table->dropForeign('eqbeats_tracks_track_id_foreign'); + }); + + Schema::drop('eqbeats_tracks'); + } +}