ConsoleTools now extends ColorCLI class

This commit is contained in:
DariusIII
2019-04-15 12:28:34 +02:00
parent e2e8ecb447
commit 2f0142e2bf
6 changed files with 101 additions and 115 deletions
+31 -38
View File
@@ -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);
}