diff --git a/app/Console/Commands/RebuildFilesizes.php b/app/Console/Commands/RebuildFilesizes.php index 3d81a34a..8b0e99ae 100644 --- a/app/Console/Commands/RebuildFilesizes.php +++ b/app/Console/Commands/RebuildFilesizes.php @@ -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'); diff --git a/app/TrackFile.php b/app/TrackFile.php index 46c67190..63556f4e 100644 --- a/app/TrackFile.php +++ b/app/TrackFile.php @@ -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; } }