diff --git a/app/database/migrations/2015_05_25_011121_create_track_files_table.php b/app/database/migrations/2015_05_25_011121_create_track_files_table.php new file mode 100644 index 00000000..0984c119 --- /dev/null +++ b/app/database/migrations/2015_05_25_011121_create_track_files_table.php @@ -0,0 +1,54 @@ +increments('id'); + $table->integer('track_id')->unsigned()->indexed(); + $table->boolean('is_master')->default(false)->indexed(); + $table->string('format')->indexed(); + + $table->foreign('track_id')->references('id')->on('tracks'); + $table->timestamps(); + }); + + foreach (Track::all() as $track){ + 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() + { + Schema::drop('track_files'); + } + +} \ No newline at end of file diff --git a/app/models/Commands/UploadTrackCommand.php b/app/models/Commands/UploadTrackCommand.php index ab6f5248..afa136c3 100644 --- a/app/models/Commands/UploadTrackCommand.php +++ b/app/models/Commands/UploadTrackCommand.php @@ -3,6 +3,7 @@ namespace Commands; use Entities\Track; + use Entities\TrackFile; use Illuminate\Support\Facades\Log; class UploadTrackCommand extends CommandBase { @@ -53,6 +54,11 @@ $processes = []; foreach (Track::$Formats as $name => $format) { + $trackFile = new TrackFile(); + $trackFile->is_master = $name === 'FLAC' ? true : false; + $trackFile->format = $name; + $track->trackFiles()->save($trackFile); + $target = $destination . '/' . $track->getFilenameFor($name); $command = $format['command']; diff --git a/app/models/Entities/Track.php b/app/models/Entities/Track.php index 7cd14329..9dcfe3b7 100644 --- a/app/models/Entities/Track.php +++ b/app/models/Entities/Track.php @@ -297,6 +297,10 @@ return $this->belongsTo('Entities\Album'); } + public function trackFiles() { + return $this->hasMany('Entities\TrackFile'); + } + public function getYear() { return date('Y', strtotime($this->release_date)); } @@ -424,6 +428,7 @@ } public function updateTags() { + $this->trackFiles()->touch(); foreach (self::$Formats as $format => $data) { $this->{$data['tag_method']}($format); } diff --git a/app/models/Entities/TrackFile.php b/app/models/Entities/TrackFile.php new file mode 100644 index 00000000..d0ce999e --- /dev/null +++ b/app/models/Entities/TrackFile.php @@ -0,0 +1,7 @@ +belongsTo('Entities\Track'); + } +} \ No newline at end of file