T125: Implemented TrackFile model to facilitate lossy master files.

This commit is contained in:
Peter Deltchev 2015-05-25 09:40:17 -07:00
parent 76fe042652
commit 2e146df697
4 changed files with 72 additions and 0 deletions

View file

@ -0,0 +1,54 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Entities\Track;
use Entities\TrackFile;
class CreateTrackFilesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Fill in the table
DB::transaction(function(){
Schema::create('track_files', function($table){
$table->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');
}
}

View file

@ -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'];

View file

@ -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);
}

View file

@ -0,0 +1,7 @@
<?php namespace Entities;
class TrackFile extends \Eloquent {
public function track() {
return $this->belongsTo('Entities\Track');
}
}