From c3000c623034a6a70ebc16cfcc2ba187eb18c97b Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 27 Jul 2018 13:10:21 +0200 Subject: [PATCH] Use human_filesize helper function in ProcessAdditional class --- .../processing/post/ProcessAdditional.php | 44 ++----------------- Changelog | 1 + app/Extensions/helper/helpers.php | 2 +- 3 files changed, 5 insertions(+), 42 deletions(-) diff --git a/Blacklight/processing/post/ProcessAdditional.php b/Blacklight/processing/post/ProcessAdditional.php index 45136ad04..9f109da82 100755 --- a/Blacklight/processing/post/ProcessAdditional.php +++ b/Blacklight/processing/post/ProcessAdditional.php @@ -668,7 +668,7 @@ class ProcessAdditional foreach ($this->_releases as $this->_release) { $this->_echo( PHP_EOL.'['.$this->_release->id.']['. - $this->_readableBytesString($this->_release->size).']', + human_filesize($this->_release->size, 1).']', 'primaryOver', false ); @@ -2207,12 +2207,8 @@ class ProcessAdditional protected function _processNfoFile($fileLocation): void { $data = @file_get_contents($fileLocation); - if ($data !== false) { - if ($this->_nfo->isNFO($data, $this->_release->guid) === true) { - if ($this->_nfo->addAlternateNfo($data, (array) $this->_release, $this->_nntp) === true) { - $this->_releaseHasNoNFO = false; - } - } + if ($data !== false && $this->_nfo->isNFO($data, $this->_release->guid) === true && $this->_nfo->addAlternateNfo($data, (array) $this->_release, $this->_nntp) === true) { + $this->_releaseHasNoNFO = false; } } @@ -2241,40 +2237,6 @@ class ProcessAdditional } } - /** - * Convert bytes to KB/MB/GB/TB and return in human readable format. - * - * @example 240640 would return 235KB - * - * @param int $bytes - * - * @return string - */ - protected function _readableBytesString($bytes): ?string - { - $kb = 1024; - $mb = 1048576; - $gb = 1073741824; - $tb = $kb * $gb; - if ($bytes < $kb) { - return $bytes.'B'; - } - - if ($bytes < $mb) { - return round($bytes / $kb, 1).'KB'; - } - - if ($bytes < $gb) { - return round($bytes / $mb, 1).'MB'; - } - - if ($bytes < $tb) { - return round($bytes / $gb, 1).'GB'; - } - - return round($bytes / $tb, 1).'TB'; - } - /** * Comparison function for uSort, for sorting NZB files. * diff --git a/Changelog b/Changelog index cdeec7396..0210633d2 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-07-27 DariusIII + * Chg: Use human_filesize helper function in ProcessAdditional class * Chg: Update phpunit.xml, move install test to front of testsuite block * Fix: Fix checks for roles that can preview 2018-07-26 DariusIII diff --git a/app/Extensions/helper/helpers.php b/app/Extensions/helper/helpers.php index c8ead232d..64b22b1da 100644 --- a/app/Extensions/helper/helpers.php +++ b/app/Extensions/helper/helpers.php @@ -215,7 +215,7 @@ if (! function_exists('makeFieldLinks')) { $size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; $factor = floor((\strlen($bytes) - 1) / 3); - return round(sprintf("%.{$decimals}f", $bytes / (1024 ** $factor))).@$size[$factor]; + return round(sprintf("%.{$decimals}f", $bytes / (1024 ** $factor)), $decimals).@$size[$factor]; } } }