diff --git a/Blacklight/ConsoleTools.php b/Blacklight/ConsoleTools.php index a740d5474..fe4d3d89c 100755 --- a/Blacklight/ConsoleTools.php +++ b/Blacklight/ConsoleTools.php @@ -5,13 +5,8 @@ namespace Blacklight; /** * Class ConsoleTools. */ -class ConsoleTools +class ConsoleTools extends ColorCLI { - /** - * @var \Blacklight\ColorCLI - */ - public $colorCli; - /** * @var int */ @@ -22,9 +17,8 @@ class ConsoleTools */ public function __construct() { + parent::__construct(); $this->lastMessageLength = 0; - - $this->colorCli = new ColorCLI(); } /** @@ -42,7 +36,7 @@ class ConsoleTools echo str_repeat(\chr(8), $this->lastMessageLength); $this->lastMessageLength = \strlen($message); - $this->colorCli->headerOver($message); + $this->headerOver($message); } /** @@ -60,7 +54,7 @@ class ConsoleTools echo str_repeat(\chr(8), $this->lastMessageLength); $this->lastMessageLength = \strlen($message); - $this->colorCli->primaryOver($message); + $this->primaryOver($message); } /** diff --git a/Blacklight/NameFixer.php b/Blacklight/NameFixer.php index 12c86b69a..82c83dd6f 100755 --- a/Blacklight/NameFixer.php +++ b/Blacklight/NameFixer.php @@ -172,7 +172,6 @@ class NameFixer $this->consoletools = ($options['ConsoleTools'] instanceof ConsoleTools ? $options['ConsoleTools'] : new ConsoleTools()); $this->category = ($options['Categorize'] instanceof Categorize ? $options['Categorize'] : new Categorize(['Settings' => null])); $this->sphinx = ($options['SphinxSearch'] instanceof SphinxSearch ? $options['SphinxSearch'] : new SphinxSearch()); - $this->colorCli = new ColorCLI(); } /** @@ -227,7 +226,7 @@ class NameFixer if ($total > 0) { $this->_totalReleases = $total; - $this->colorCli->primary(number_format($total).' releases to process.'); + $this->consoletools->primary(number_format($total).' releases to process.'); foreach ($releases as $rel) { $releaseRow = Release::fromQuery( @@ -256,7 +255,7 @@ class NameFixer } $this->_echoFoundCount($echo, ' NFO\'s'); } else { - $this->colorCli->info('Nothing to fix.'); + $this->consoletools->info('Nothing to fix.'); } } @@ -311,7 +310,7 @@ class NameFixer $total = \count($releases); if ($total > 0) { $this->_totalReleases = $total; - $this->colorCli->primary(number_format($total).' file names to process.'); + $this->consoletools->primary(number_format($total).' file names to process.'); foreach ($releases as $release) { $this->reset(); @@ -322,7 +321,7 @@ class NameFixer $this->_echoFoundCount($echo, ' files'); } else { - $this->colorCli->info('Nothing to fix.'); + $this->consoletools->info('Nothing to fix.'); } } @@ -377,7 +376,7 @@ class NameFixer $total = \count($releases); if ($total > 0) { $this->_totalReleases = $total; - $this->colorCli->primary(number_format($total).' CRC32\'s to process.'); + $this->consoletools->primary(number_format($total).' CRC32\'s to process.'); foreach ($releases as $release) { $this->reset(); @@ -388,7 +387,7 @@ class NameFixer $this->_echoFoundCount($echo, ' crc32\'s'); } else { - $this->colorCli->info('Nothing to fix.'); + $this->consoletools->info('Nothing to fix.'); } } @@ -441,7 +440,7 @@ class NameFixer $total = \count($releases); if ($total > 0) { $this->_totalReleases = $total; - $this->colorCli->primary(number_format($total).' xxx file names to process.'); + $this->consoletools->primary(number_format($total).' xxx file names to process.'); foreach ($releases as $release) { $this->reset(); @@ -451,7 +450,7 @@ class NameFixer } $this->_echoFoundCount($echo, ' files'); } else { - $this->colorCli->info('Nothing to fix.'); + $this->consoletools->info('Nothing to fix.'); } } @@ -506,7 +505,7 @@ class NameFixer $total = \count($releases); if ($total > 0) { $this->_totalReleases = $total; - $this->colorCli->primary(number_format($total).' srr file extensions to process.'); + $this->consoletools->primary(number_format($total).' srr file extensions to process.'); foreach ($releases as $release) { $this->reset(); @@ -516,7 +515,7 @@ class NameFixer } $this->_echoFoundCount($echo, ' files'); } else { - $this->colorCli->info('Nothing to fix.'); + $this->consoletools->info('Nothing to fix.'); } } @@ -566,7 +565,7 @@ class NameFixer if ($total > 0) { $this->_totalReleases = $total; - $this->colorCli->primary(number_format($total).' releases to process.'); + $this->consoletools->primary(number_format($total).' releases to process.'); $Nfo = new Nfo(); $nzbContents = new NZBContents( [ @@ -587,7 +586,7 @@ class NameFixer } $this->_echoFoundCount($echo, ' files'); } else { - $this->colorCli->info('Nothing to fix.'); + $this->consoletools->info('Nothing to fix.'); } } @@ -651,7 +650,7 @@ class NameFixer $total = \count($releases); if ($total > 0) { $this->_totalReleases = $total; - $this->colorCli->primary(number_format($total).' unique ids to process.'); + $this->consoletools->primary(number_format($total).' unique ids to process.'); foreach ($releases as $rel) { $this->checked++; $this->reset(); @@ -660,7 +659,7 @@ class NameFixer } $this->_echoFoundCount($echo, ' UID\'s'); } else { - $this->colorCli->info('Nothing to fix.'); + $this->consoletools->info('Nothing to fix.'); } } @@ -716,7 +715,7 @@ class NameFixer $total = \count($releases); if ($total > 0) { $this->_totalReleases = $total; - $this->colorCli->primary(number_format($total).' mediainfo movie names to process.'); + $this->consoletools->primary(number_format($total).' mediainfo movie names to process.'); foreach ($releases as $rel) { $this->checked++; $this->reset(); @@ -725,7 +724,7 @@ class NameFixer } $this->_echoFoundCount($echo, ' MediaInfo\'s'); } else { - $this->colorCli->info('Nothing to fix.'); + $this->consoletools->info('Nothing to fix.'); } } @@ -790,7 +789,7 @@ class NameFixer $total = \count($releases); if ($total > 0) { $this->_totalReleases = $total; - $this->colorCli->primary(number_format($total).' hash_16K to process.'); + $this->consoletools->primary(number_format($total).' hash_16K to process.'); foreach ($releases as $rel) { $this->checked++; $this->reset(); @@ -799,7 +798,7 @@ class NameFixer } $this->_echoFoundCount($echo, ' hashes'); } else { - $this->colorCli->info('Nothing to fix.'); + $this->consoletools->info('Nothing to fix.'); } } @@ -841,7 +840,7 @@ class NameFixer protected function _echoFoundCount($echo, $type): void { if ($echo === true) { - $this->colorCli->header( + $this->consoletools->header( PHP_EOL. number_format($this->fixed). ' releases have had their names changed out of: '. @@ -849,7 +848,7 @@ class NameFixer $type.'.' ); } else { - $this->colorCli->header( + $this->consoletools->header( PHP_EOL. number_format($this->fixed). ' releases could have their names changed. '. @@ -865,7 +864,7 @@ class NameFixer */ protected function _echoStartMessage($time, $type): void { - $this->colorCli->header( + $this->consoletools->header( sprintf( 'Fixing search names %s using %s.', ($time === 1 ? 'in the past 6 hours' : 'since the beginning'), @@ -880,7 +879,7 @@ class NameFixer protected function _echoRenamed($show): void { if ($this->checked % 500 === 0 && $show === 1) { - $this->colorCli->alternate(PHP_EOL.number_format($this->checked).' files processed.'.PHP_EOL); + $this->consoletools->alternate(PHP_EOL.number_format($this->checked).' files processed.'.PHP_EOL); } if ($show === 2) { @@ -944,25 +943,25 @@ class NameFixer echo PHP_EOL; - $this->colorCli->headerOver('New name: '). - $this->colorCli->primary(substr($newName, 0, 299)). - $this->colorCli->headerOver('Old name: '). - $this->colorCli->primary($release->searchname). - $this->colorCli->headerOver('Use name: '). - $this->colorCli->primary($release->name). - $this->colorCli->headerOver('New cat: '). - $this->colorCli->primary($newCatName). - $this->colorCli->headerOver('Old cat: '). - $this->colorCli->primary($oldCatName). - $this->colorCli->headerOver('Group: '). - $this->colorCli->primary($groupName). - $this->colorCli->headerOver('Method: '). - $this->colorCli->primary($type.$method). - $this->colorCli->headerOver('Releases ID: '). - $this->colorCli->primary($release->releases_id); + $this->consoletools->headerOver('New name: '). + $this->consoletools->primary(substr($newName, 0, 299)). + $this->consoletools->headerOver('Old name: '). + $this->consoletools->primary($release->searchname). + $this->consoletools->headerOver('Use name: '). + $this->consoletools->primary($release->name). + $this->consoletools->headerOver('New cat: '). + $this->consoletools->primary($newCatName). + $this->consoletools->headerOver('Old cat: '). + $this->consoletools->primary($oldCatName). + $this->consoletools->headerOver('Group: '). + $this->consoletools->primary($groupName). + $this->consoletools->headerOver('Method: '). + $this->consoletools->primary($type.$method). + $this->consoletools->headerOver('Releases ID: '). + $this->consoletools->primary($release->releases_id); if (! empty($release->filename)) { - $this->colorCli->headerOver('Filename: '). - $this->colorCli->primary($release->filename); + $this->consoletools->headerOver('Filename: '). + $this->consoletools->primary($release->filename); } if ($type !== 'PAR2, ') { @@ -1195,8 +1194,8 @@ class NameFixer $limit = 'LIMIT 1000000'; } - $this->colorCli->header(PHP_EOL.'Match PreFiles '.$args[1].' Started at '.now()); - $this->colorCli->primary('Matching predb filename to cleaned release_files.name.'); + $this->consoletools->header(PHP_EOL.'Match PreFiles '.$args[1].' Started at '.now()); + $this->consoletools->primary('Matching predb filename to cleaned release_files.name.'); $counter = $counted = 0; $timestart = now(); @@ -1225,7 +1224,7 @@ class NameFixer $total = \count($query); if ($total > 0) { - $this->colorCli->header(PHP_EOL.number_format($total).' releases to process.'); + $this->consoletools->header(PHP_EOL.number_format($total).' releases to process.'); foreach ($query as $row) { $success = $this->matchPreDbFiles($row, true, 1, $show); @@ -1236,9 +1235,9 @@ class NameFixer $this->consoletools->overWritePrimary('Renamed Releases: ['.number_format($counted).'] '.$this->consoletools->percentString(++$counter, $total)); } } - $this->colorCli->header(PHP_EOL.'Renamed '.number_format($counted).' releases in '.now()->diffInSeconds($timestart).' seconds'.'.'); + $this->consoletools->header(PHP_EOL.'Renamed '.number_format($counted).' releases in '.now()->diffInSeconds($timestart).' seconds'.'.'); } else { - $this->colorCli->info('Nothing to do.'); + $this->consoletools->info('Nothing to do.'); } } } @@ -1414,7 +1413,7 @@ class NameFixer if ($time === 1) { $te = ' in the past 3 hours'; } - $this->colorCli->header('Fixing search names'.$te.' using the predb hash.'); + $this->consoletools->header('Fixing search names'.$te.' using the predb hash.'); } $regex = 'AND (r.ishashed = 1 OR rf.ishashed = 1)'; @@ -1432,7 +1431,7 @@ class NameFixer $res = Release::fromQuery($query); $total = \count($res); - $this->colorCli->primary(number_format($total).' releases to process.'); + $this->consoletools->primary(number_format($total).' releases to process.'); foreach ($res as $row) { if (preg_match('/[a-fA-F0-9]{32,40}/i', $row->name, $matches)) { $updated += $this->matchPredbHash($matches[0], $row, $echo, $nameStatus, $show); @@ -1440,13 +1439,13 @@ class NameFixer $updated += $this->matchPredbHash($matches[0], $row, $echo, $nameStatus, $show); } if ($show === 2) { - $this->colorCli->overWritePrimary('Renamed Releases: ['.number_format($updated).'] '.$this->consoletools->percentString($checked++, $total)); + $this->consoletools->overWritePrimary('Renamed Releases: ['.number_format($updated).'] '.$this->consoletools->percentString($checked++, $total)); } } if ($echo === 1) { - $this->colorCli->header(PHP_EOL.$updated.' releases have had their names changed out of: '.number_format($checked).' files.'); + $this->consoletools->header(PHP_EOL.$updated.' releases have had their names changed out of: '.number_format($checked).' files.'); } else { - $this->colorCli->header(PHP_EOL.$updated.' releases could have their names changed. '.number_format($checked).' files were checked.'); + $this->consoletools->header(PHP_EOL.$updated.' releases could have their names changed. '.number_format($checked).' files were checked.'); } return $updated; diff --git a/Blacklight/ReleaseRemover.php b/Blacklight/ReleaseRemover.php index bc081d795..e391514cb 100755 --- a/Blacklight/ReleaseRemover.php +++ b/Blacklight/ReleaseRemover.php @@ -126,7 +126,6 @@ class ReleaseRemover $this->releases = ($options['Releases'] instanceof Releases ? $options['Releases'] : new Releases()); $this->nzb = ($options['NZB'] instanceof NZB ? $options['NZB'] : new NZB()); $this->releaseImage = ($options['ReleaseImage'] instanceof ReleaseImage ? $options['ReleaseImage'] : new ReleaseImage()); - $this->colorCli = new ColorCLI(); $this->query = ''; $this->error = ''; @@ -185,8 +184,8 @@ class ReleaseRemover $this->deleteReleases(); if ($this->echoCLI) { - $this->colorCli->headerOver(($this->delete ? 'Deleted ' : 'Would have deleted ').$this->deletedCount.' release(s). This script ran for '); - $this->colorCli->header(now()->diffInSeconds($timeStart).' seconds', true); + $this->consoleTools->headerOver(($this->delete ? 'Deleted ' : 'Would have deleted ').$this->deletedCount.' release(s). This script ran for '); + $this->consoleTools->header(now()->diffInSeconds($timeStart).' seconds', true); } return $this->browser @@ -228,7 +227,7 @@ class ReleaseRemover if ($time === 'full') { if ($this->echoCLI) { - $this->colorCli->header('Removing '.($type === '' ? 'All crap releases ' : $type.' crap releases').' - no time limit.', true); + $this->consoleTools->header('Removing '.($type === '' ? 'All crap releases ' : $type.' crap releases').' - no time limit.', true); } } else { if (! is_numeric($time)) { @@ -237,7 +236,7 @@ class ReleaseRemover return $this->returnError(); } if ($this->echoCLI) { - $this->colorCli->header('Removing '.($type === '' ? 'All crap releases ' : $type.' crap releases').' from the past '.$time.' hour(s).', true); + $this->consoleTools->header('Removing '.($type === '' ? 'All crap releases ' : $type.' crap releases').' from the past '.$time.' hour(s).', true); } $this->crapTime = ' AND r.adddate > (NOW() - INTERVAL '.$time.' HOUR)'; } @@ -315,8 +314,8 @@ class ReleaseRemover } if ($this->echoCLI) { - $this->colorCli->headerOver(($this->delete ? 'Deleted ' : 'Would have deleted ').$this->deletedCount.' release(s). This script ran for '); - $this->colorCli->header(now()->diffInSeconds($timeStart).' seconds', true); + $this->consoleTools->headerOver(($this->delete ? 'Deleted ' : 'Would have deleted ').$this->deletedCount.' release(s). This script ran for '); + $this->consoleTools->header(now()->diffInSeconds($timeStart).' seconds', true); } return $this->browser @@ -798,7 +797,7 @@ class ReleaseRemover } // Provide useful output of operations - $this->colorCli->header( + $this->consoleTools->header( sprintf( 'Finding crap releases for %s: Using %s method against release %s.'. '%s', @@ -832,7 +831,7 @@ class ReleaseRemover $this->deleteReleases(); } } else { - $this->colorCli->error("No regular expressions were selected for blacklist removal. Make sure you have activated REGEXPs in Site Edit and you're specifying a valid ID.", true); + $this->consoleTools->error("No regular expressions were selected for blacklist removal. Make sure you have activated REGEXPs in Site Edit and you're specifying a valid ID.", true); } return true; @@ -902,7 +901,7 @@ class ReleaseRemover $ftUsing = PHP_EOL; // Provide useful output of operations - $this->colorCli->header( + $this->consoleTools->header( sprintf( 'Finding crap releases for %s: Using %s method against release filenames.'.PHP_EOL. '%s', @@ -1033,10 +1032,10 @@ class ReleaseRemover if ($this->delete) { $this->releases->deleteSingle(['g' => $release->guid, 'i' => $release->id], $this->nzb, $this->releaseImage); if ($this->echoCLI) { - $this->colorCli->primary('Deleting: '.$this->method.': '.$release->searchname, true); + $this->consoleTools->primary('Deleting: '.$this->method.': '.$release->searchname, true); } } elseif ($this->echoCLI) { - $this->colorCli->primary('Would be deleting: '.$this->method.': '.$release->searchname, true); + $this->consoleTools->primary('Would be deleting: '.$this->method.': '.$release->searchname, true); } $deletedCount++; } @@ -1253,7 +1252,7 @@ class ReleaseRemover } // Print the query to the user, ask them if they want to continue using it. - $this->colorCli->primary( + $this->consoleTools->primary( 'This is the query we have formatted using your criteria, you can run it in SQL to see if you like the results:'. PHP_EOL.$this->query.';'.PHP_EOL. 'If you are satisfied, type yes and press enter. Anything else will exit.', @@ -1263,7 +1262,7 @@ class ReleaseRemover // Check the users response. $userInput = trim(fgets(fopen('php://stdin', 'rtb'))); if ($userInput !== 'yes') { - $this->colorCli->primary('You typed: "'.$userInput.'", the program will exit.', true); + $this->consoleTools->primary('You typed: "'.$userInput.'", the program will exit.', true); return false; } @@ -1314,7 +1313,7 @@ class ReleaseRemover } if ($this->echoCLI && $this->error !== '') { - $this->colorCli->error($this->error, true); + $this->consoleTools->error($this->error, true); } return false; diff --git a/Blacklight/processing/ProcessReleases.php b/Blacklight/processing/ProcessReleases.php index 37f2ec44a..4874fe05b 100755 --- a/Blacklight/processing/ProcessReleases.php +++ b/Blacklight/processing/ProcessReleases.php @@ -9,7 +9,6 @@ use Blacklight\Genres; use App\Models\Release; use App\Models\Category; use App\Models\Settings; -use Blacklight\ColorCLI; use Blacklight\Releases; use App\Models\MusicInfo; use App\Models\Collection; @@ -102,11 +101,6 @@ class ProcessReleases */ private $collectionTimeout; - /** - * @var \Blacklight\ColorCLI - */ - protected $colorCli; - /** * @param array $options Class instances / Echo to cli ? * @@ -133,7 +127,6 @@ class ProcessReleases $this->releaseCleaning = ($options['ReleaseCleaning'] instanceof ReleaseCleaning ? $options['ReleaseCleaning'] : new ReleaseCleaning()); $this->releases = ($options['Releases'] instanceof Releases ? $options['Releases'] : new Releases()); $this->releaseImage = ($options['ReleaseImage'] instanceof ReleaseImage ? $options['ReleaseImage'] : new ReleaseImage()); - $this->colorCli = new ColorCLI(); $dummy = Settings::settingValue('..delaytime'); $this->collectionDelayTime = ($dummy !== '' ? (int) $dummy : 2); @@ -145,7 +138,7 @@ class ProcessReleases $this->completion = ($dummy !== '' ? (int) $dummy : 0); if ($this->completion > 100) { $this->completion = 100; - $this->colorCli->error(PHP_EOL.'You have an invalid setting for completion. It cannot be higher than 100.'); + $this->consoleTools->error(PHP_EOL.'You have an invalid setting for completion. It cannot be higher than 100.'); } $this->collectionTimeout = (int) Settings::settingValue('indexer.processing.collection_timeout'); } @@ -175,12 +168,12 @@ class ProcessReleases } if ($this->echoCLI) { - $this->colorCli->header('Starting release update process ('.now()->format('Y-m-d H:i:s').')'); + $this->consoleTools->header('Starting release update process ('.now()->format('Y-m-d H:i:s').')'); } if (! file_exists(Settings::settingValue('..nzbpath'))) { if ($this->echoCLI) { - $this->colorCli->error('Bad or missing nzb directory - '.Settings::settingValue('..nzbpath')); + $this->consoleTools->error('Bad or missing nzb directory - '.Settings::settingValue('..nzbpath')); } return 0; @@ -280,7 +273,7 @@ class ProcessReleases $startTime = now(); if ($this->echoCLI) { - $this->colorCli->header('Process Releases -> Attempting to find complete collections.'); + $this->consoleTools->header('Process Releases -> Attempting to find complete collections.'); } $where = (! empty($groupID) ? ' AND c.groups_id = '.$groupID.' ' : ' '); @@ -303,7 +296,7 @@ class ProcessReleases $totalTime = now()->diffInSeconds($startTime); - $this->colorCli->primary( + $this->consoleTools->primary( ($count ?? 0).' collections were found to be complete. Time: '. $totalTime.Str::plural(' second', $totalTime), true @@ -322,7 +315,7 @@ class ProcessReleases $startTime = now(); if ($this->echoCLI) { - $this->colorCli->header('Process Releases -> Calculating collection sizes (in bytes).'); + $this->consoleTools->header('Process Releases -> Calculating collection sizes (in bytes).'); } // Get the total size in bytes of the collection for collections where filecheck = 2. DB::transaction(function () use ($groupID, $startTime) { @@ -345,12 +338,12 @@ class ProcessReleases ) ); if ($checked > 0 && $this->echoCLI) { - $this->colorCli->primary( + $this->consoleTools->primary( $checked.' collections set to filecheck = 3(size calculated)', true ); $totalTime = now()->diffInSeconds($startTime); - $this->colorCli->primary($totalTime.Str::plural(' second', $totalTime), true); + $this->consoleTools->primary($totalTime.Str::plural(' second', $totalTime), true); } }, 10); } @@ -366,7 +359,7 @@ class ProcessReleases $startTime = now(); if ($this->echoCLI) { - $this->colorCli->header('Process Releases -> Delete collections smaller/larger than minimum size/file count from group/site setting.'); + $this->consoleTools->header('Process Releases -> Delete collections smaller/larger than minimum size/file count from group/site setting.'); } $groupID === '' ? $groupIDs = UsenetGroup::getActiveIDs() : $groupIDs = [['id' => $groupID]]; @@ -438,7 +431,7 @@ class ProcessReleases $totalTime = now()->diffInSeconds($startTime); if ($this->echoCLI) { - $this->colorCli->primary('Deleted '.($minSizeDeleted + $maxSizeDeleted + $minFilesDeleted).' collections: '.PHP_EOL.$minSizeDeleted.' smaller than, '.$maxSizeDeleted.' bigger than, '.$minFilesDeleted.' with less files than site/group settings in: '.$totalTime.Str::plural(' second', $totalTime), true); + $this->consoleTools->primary('Deleted '.($minSizeDeleted + $maxSizeDeleted + $minFilesDeleted).' collections: '.PHP_EOL.$minSizeDeleted.' smaller than, '.$maxSizeDeleted.' bigger than, '.$minFilesDeleted.' with less files than site/group settings in: '.$totalTime.Str::plural(' second', $totalTime), true); } }, 10); } @@ -459,7 +452,7 @@ class ProcessReleases $returnCount = $duplicate = 0; if ($this->echoCLI) { - $this->colorCli->header('Process Releases -> Create releases from complete collections.'); + $this->consoleTools->header('Process Releases -> Create releases from complete collections.'); } $collectionsQuery = Collection::query() ->where('collections.filecheck', self::COLLFC_SIZED) @@ -472,7 +465,7 @@ class ProcessReleases ->limit($this->releaseCreationLimit); $collections = $collectionsQuery->get(); if ($this->echoCLI && $collections->count() > 0) { - $this->colorCli->primary(\count($collections).' Collections ready to be converted to releases.', true); + $this->consoleTools->primary(\count($collections).' Collections ready to be converted to releases.', true); } foreach ($collections as $collection) { @@ -614,7 +607,7 @@ class ProcessReleases $totalTime = now()->diffInSeconds($startTime); if ($this->echoCLI) { - $this->colorCli->primary( + $this->consoleTools->primary( PHP_EOL. number_format($returnCount). ' Releases added and '. @@ -641,7 +634,7 @@ class ProcessReleases $startTime = now(); if ($this->echoCLI) { - $this->colorCli->header('Process Releases -> Create the NZB, delete collections/binaries/parts.'); + $this->consoleTools->header('Process Releases -> Create the NZB, delete collections/binaries/parts.'); } $releasesQuery = Release::query()->with('category.parent')->where('nzbstatus', '=', 0); @@ -667,7 +660,7 @@ class ProcessReleases $totalTime = now()->diffInSeconds($startTime); if ($this->echoCLI) { - $this->colorCli->primary( + $this->consoleTools->primary( number_format($nzbCount).' NZBs created/Collections deleted in '. $totalTime.Str::plural(' second', $totalTime).PHP_EOL. 'Total time: '.$totalTime.Str::plural(' second', $totalTime), @@ -691,7 +684,7 @@ class ProcessReleases { $startTime = now(); if ($this->echoCLI) { - $this->colorCli->header('Process Releases -> Categorize releases.'); + $this->consoleTools->header('Process Releases -> Categorize releases.'); } switch ((int) $categorize) { case 2: @@ -710,7 +703,7 @@ class ProcessReleases $totalTime = now()->diffInSeconds($startTime); if ($this->echoCLI) { - $this->colorCli->primary($totalTime.Str::plural(' second', $totalTime)); + $this->consoleTools->primary($totalTime.Str::plural(' second', $totalTime)); } } @@ -728,7 +721,7 @@ class ProcessReleases if ((int) $postProcess === 1) { (new PostProcess(['Echo' => $this->echoCLI]))->processAll($nntp); } elseif ($this->echoCLI) { - $this->colorCli->info( + $this->consoleTools->info( 'Post-processing is not running inside the Process Releases class.'.PHP_EOL. 'If you are using tmux or screen they might have their own scripts running Post-processing.' ); @@ -750,8 +743,8 @@ class ProcessReleases // CBP older than retention. if ($this->echoCLI) { echo - $this->colorCli->header('Process Releases -> Delete finished collections.'.PHP_EOL). - $this->colorCli->primary(sprintf( + $this->consoleTools->header('Process Releases -> Delete finished collections.'.PHP_EOL). + $this->consoleTools->primary(sprintf( 'Deleting collections/binaries/parts older than %d hours.', Settings::settingValue('..partretentionhours') ), true); @@ -771,7 +764,7 @@ class ProcessReleases $totalTime = $firstQuery->diffInSeconds($startTime); if ($this->echoCLI) { - $this->colorCli->primary( + $this->consoleTools->primary( 'Finished deleting '.$deleted.' old collections/binaries/parts in '. $totalTime.Str::plural(' second', $totalTime), true @@ -783,7 +776,7 @@ class ProcessReleases if (random_int(0, 200) <= 1) { // CBP collection orphaned with no binaries or parts. if ($this->echoCLI) { - echo $this->colorCli->header('Process Releases -> Remove CBP orphans.'.PHP_EOL).$this->colorCli->primary('Deleting orphaned collections.'); + echo $this->consoleTools->header('Process Releases -> Remove CBP orphans.'.PHP_EOL).$this->consoleTools->primary('Deleting orphaned collections.'); } $deleted = 0; @@ -797,12 +790,12 @@ class ProcessReleases $totalTime = now()->diffInSeconds($firstQuery); if ($this->echoCLI) { - $this->colorCli->primary('Finished deleting '.$deleted.' orphaned collections in '.$totalTime.Str::plural(' second', $totalTime), true); + $this->consoleTools->primary('Finished deleting '.$deleted.' orphaned collections in '.$totalTime.Str::plural(' second', $totalTime), true); } } if ($this->echoCLI) { - $this->colorCli->primary('Deleting collections that were missed after NZB creation.', true); + $this->consoleTools->primary('Deleting collections that were missed after NZB creation.', true); } $deleted = 0; @@ -819,7 +812,7 @@ class ProcessReleases $totalTime = $fourthQuery->diffInSeconds($startTime); if ($this->echoCLI) { - $this->colorCli->primary('Finished deleting '.$deleted.' collections missed after NZB creation in '.$colDelTime.Str::plural(' second', $colDelTime).PHP_EOL.'Removed '.number_format($deletedCount).' parts/binaries/collection rows in '.$totalTime.Str::plural(' second', $totalTime), true); + $this->consoleTools->primary('Finished deleting '.$deleted.' collections missed after NZB creation in '.$colDelTime.Str::plural(' second', $colDelTime).PHP_EOL.'Removed '.number_format($deletedCount).' parts/binaries/collection rows in '.$totalTime.Str::plural(' second', $totalTime), true); } }, 10); } @@ -839,7 +832,7 @@ class ProcessReleases $minSizeDeleted = $maxSizeDeleted = $minFilesDeleted = 0; if ($this->echoCLI) { - $this->colorCli->header('Process Releases -> Delete releases smaller/larger than minimum size/file count from group/site setting.'); + $this->consoleTools->header('Process Releases -> Delete releases smaller/larger than minimum size/file count from group/site setting.'); } $groupID === '' ? $groupIDs = UsenetGroup::getActiveIDs() : $groupIDs = [['id' => $groupID]]; @@ -874,7 +867,7 @@ class ProcessReleases $totalTime = now()->diffInSeconds($startTime); if ($this->echoCLI) { - $this->colorCli->primary( + $this->consoleTools->primary( 'Deleted '.($minSizeDeleted + $maxSizeDeleted + $minFilesDeleted). ' releases: '.PHP_EOL. $minSizeDeleted.' smaller than, '.$maxSizeDeleted.' bigger than, '.$minFilesDeleted. @@ -901,7 +894,7 @@ class ProcessReleases // Delete old releases and finished collections. if ($this->echoCLI) { - $this->colorCli->header('Process Releases -> Delete old releases and passworded releases.'); + $this->consoleTools->header('Process Releases -> Delete old releases and passworded releases.'); } // Releases past retention. @@ -1010,7 +1003,7 @@ class ProcessReleases } if ($this->echoCLI) { - $this->colorCli->primary( + $this->consoleTools->primary( 'Removed releases: '. number_format($retentionDeleted). ' past retention, '. @@ -1043,7 +1036,7 @@ class ProcessReleases ); if ($totalDeleted > 0) { $totalTime = now()->diffInSeconds($startTime); - $this->colorCli->primary( + $this->consoleTools->primary( 'Removed '.number_format($totalDeleted).' releases in '. $totalTime.Str::plural(' second', $totalTime), true @@ -1282,7 +1275,7 @@ class ProcessReleases } $obj = $objQuery->delete(); if ($this->echoCLI && $obj > 0) { - $this->colorCli->primary('Deleted '.$obj.' broken/stuck collections.', true); + $this->consoleTools->primary('Deleted '.$obj.' broken/stuck collections.', true); } }, 10); } diff --git a/Changelog b/Changelog index 9c0f627c1..b5f723fc8 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2019-04-15 DariusIII + * Chg: ConsoleTools now extends ColorCLI class * Chg: Remove unused PDO class instantiation * Chg: Remove $this->pdo as it is not used * Chg: Remove unused ReleaseSearch class diff --git a/app/Models/Predb.php b/app/Models/Predb.php index 1b6caeded..17c0e60df 100644 --- a/app/Models/Predb.php +++ b/app/Models/Predb.php @@ -122,7 +122,7 @@ class Predb extends Model if (config('nntmux.echocli')) { $consoleTools->overWritePrimary( - 'Matching up preDB titles with release searchnames: '.$consoleTools->percentString(++$updated, $total) + 'Matching up preDB titles with release searchnames: '.$consoleTools->percentString(++$updated, $total) ); } }