Merge branch 'master' into test

This commit is contained in:
An Phan 2016-07-05 17:15:33 +07:00
commit 72ff0b76cc
No known key found for this signature in database
GPG key ID: 05536BB4BCDC02A2
2 changed files with 25 additions and 4 deletions

View file

@ -6,6 +6,7 @@ use Exception;
use getID3;
use getid3_lib;
use Illuminate\Support\Facades\Log;
use Media;
use SplFileInfo;
class File
@ -179,6 +180,11 @@ class File
return false;
}
// Fixes #366. If the file is new, we use all tags by simply setting $force to false.
if ($this->isNew()) {
$force = false;
}
$artist = null;
if ($this->isChanged() || $force) {
@ -240,10 +246,7 @@ class File
// Remove these values from the info array, so that we can just use the array as model's input data.
array_forget($info, ['artist', 'albumartist', 'album', 'cover', 'compilation']);
$song = Song::updateOrCreate(['id' => $this->hash], $info);
$song->save();
return $song;
return Song::updateOrCreate(['id' => $this->hash], $info);
}
/**

View file

@ -132,6 +132,24 @@ class MediaTest extends TestCase
$this->assertEquals('Booom Wroooom', $song->lyrics);
}
public function testAlwaysSyncAllTagsIfFileIsNew()
{
$media = new Media();
$media->sync($this->mediaPath);
$song = Song::orderBy('id')->first();
$song->delete();
// Selectively sync only one tag,
// but we still expect the whole song to be added back with all info
$media->sync($this->mediaPath, ['track'], true);
$this->seeInDatabase('songs', [
'id' => $song->id,
'lyrics' => $song->lyrics,
'title' => $song->title,
'track' => $song->track,
]);
}
public function testWatchSingleFileAdded()
{
$path = $this->mediaPath.'/blank.mp3';