From f5987db73522402ed1ed15f6d17e563f0e9d4ce3 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Thu, 29 Oct 2015 16:26:01 +0000 Subject: [PATCH] Add file size addition during uploading --- app/Commands/UploadTrackCommand.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/Commands/UploadTrackCommand.php b/app/Commands/UploadTrackCommand.php index 0679352e..ca14bc09 100644 --- a/app/Commands/UploadTrackCommand.php +++ b/app/Commands/UploadTrackCommand.php @@ -143,18 +143,25 @@ class UploadTrackCommand extends CommandBase } $track->trackFiles()->save($trackFile); - if ($trackFile->is_cacheable == false) { - $target = $destination . '/' . $trackFile->getFilename(); + // Encode track file + $target = $destination . '/' . $trackFile->getFilename(); - $command = $format['command']; - $command = str_replace('{$source}', '"' . $source . '"', $command); - $command = str_replace('{$target}', '"' . $target . '"', $command); + $command = $format['command']; + $command = str_replace('{$source}', '"' . $source . '"', $command); + $command = str_replace('{$target}', '"' . $target . '"', $command); - Log::info('Encoding ' . $track->id . ' into ' . $target); - $this->notify('Encoding ' . $name, $index / count(Track::$Formats) * 100); + Log::info('Encoding ' . $track->id . ' into ' . $target); + $this->notify('Encoding ' . $name, $index / count(Track::$Formats) * 100); - $process = new Process($command); - $process->mustRun(); + $process = new Process($command); + $process->mustRun(); + + // Update file size for track file + $trackFile->updateFilesize(); + + // Delete track file if it is cacheable + if ($trackFile->is_cacheable == true) { + \Illuminate\Support\Facades\File::delete($trackFile->getFile()); } }