#4: The file size updating method no longer overwrites file size estimates for un-cached files with null.

This commit is contained in:
Peter Deltchev 2015-11-09 22:40:09 -08:00
parent 2d93ed0ef4
commit 4214dde7b0
2 changed files with 14 additions and 8 deletions

View file

@ -20,6 +20,7 @@
namespace Poniverse\Ponyfm\Console\Commands;
use File;
use Illuminate\Console\Command;
use Poniverse\Ponyfm\TrackFile;
@ -67,8 +68,10 @@ class RebuildFilesizes extends Command
$this->info('========== Start Chunk ==========');
foreach ($trackFiles as $trackFile) {
$size = $trackFile->updateFilesize();
if ($size !== null) {
/** @var TrackFile $trackFile */
if (File::exists($trackFile->getFile())) {
$size = $trackFile->updateFilesize();
$this->info('ID ' . $trackFile->id . ' processed - ' . $size . ' bytes');
} else {
$this->info('ID ' . $trackFile->id . ' skipped');

View file

@ -126,19 +126,22 @@ class TrackFile extends Model
return 'track_file-' . $this->id . '-' . $key;
}
/**
* If this file exists, update its estimated filesize in the database.
*
* @return int $size
*/
public function updateFilesize()
{
$file = $this->getFile();
if (File::exists($file)) {
$size = File::size($file);
} else {
$size = null;
$this->filesize = $size;
$this->update();
}
$this->filesize = $size;
$this->update();
return $size;
return $this->filesize;
}
}