add command microcaching:service {enable/disable}

This commit is contained in:
Irfan 2021-06-25 02:02:55 +05:00
parent aaa9eaee74
commit 3ff68c4f17
3 changed files with 70 additions and 3 deletions

View File

@ -72,10 +72,10 @@ class CurrentSeasonIndexer extends Command
file_get_contents($url);
sleep(3); // prevent rate-limit
echo "Updating {$i}/{$itemCount} [{$entry['mal_id']} - {$entry['title']}] \r";
echo "Updating {$i}/{$itemCount} {$url} [{$entry['mal_id']} - {$entry['title']}] \n";
try {
} catch (\Exception $e) {
echo "[SKIPPED] Failed to fetch {$url}";
echo "[SKIPPED] Failed to fetch {$url}\n";
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ManageMicrocaching extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'microcaching:service {status}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Enable or disable microcaching';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if (!\in_array($this->argument('status'), ['disable', 'enable'])) {
$this->error('Only [enable/disable] allowed');
return;
}
$enabled = $this->argument('status') === 'enable';
if ($enabled === env('MICROCACHING')) {
$this->error("MICROCASHING is already '{$this->argument('status')}'");
return;
}
$path = base_path('.env');
if (!file_exists($path)) {
$this->error(".env does not exist");
return;
}
file_put_contents($path, str_replace(
'MICROCACHING='.(env('MICROCACHING') ? 'true' : 'false'), 'MICROCACHING='.($enabled ? 'true' : 'false'), file_get_contents($path)
));
$this->info("MICROCACHING: '{$this->argument('status')}'");
}
}

View File

@ -12,6 +12,7 @@ use App\Console\Commands\Indexer\AnimeScheduleIndexer;
use App\Console\Commands\Indexer\CommonIndexer;
use App\Console\Commands\Indexer\CurrentSeasonIndexer;
use App\Console\Commands\Indexer\ScheduleIndexer;
use App\Console\Commands\ManageMicrocaching;
use App\Console\Commands\ModifyCacheDriver;
use App\Console\Commands\ModifyCacheMethod;
use Illuminate\Console\Scheduling\Schedule;
@ -32,7 +33,8 @@ class Kernel extends ConsoleKernel
CacheRemove::class,
CommonIndexer::class,
AnimeScheduleIndexer::class,
CurrentSeasonIndexer::class
CurrentSeasonIndexer::class,
ManageMicrocaching::class
];
/**