mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
02ad342bac
[ci skip] [skip ci]
121 lines
2.8 KiB
PHP
121 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Blacklight\Tmux;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\App;
|
|
use Ytake\LaravelSmarty\Smarty;
|
|
|
|
class UpdateNNTmux extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'nntmux:all';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Update NNTmux installation';
|
|
|
|
/**
|
|
* @var \app\extensions\util\Git object.
|
|
*/
|
|
protected $git;
|
|
|
|
/**
|
|
* @var array Decoded JSON updates file.
|
|
*/
|
|
protected $updates = null;
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$maintenance = $this->appDown();
|
|
$running = $this->stopTmux();
|
|
|
|
try {
|
|
$output = $this->call('nntmux:git');
|
|
if ($output === 'Already up-to-date.') {
|
|
$this->info($output);
|
|
} else {
|
|
$status = $this->call('nntmux:composer');
|
|
if ($status) {
|
|
$this->error('Composer failed to update!!');
|
|
}
|
|
$fail = $this->call('nntmux:db');
|
|
if ($fail) {
|
|
$this->error('Db updating failed!!');
|
|
}
|
|
}
|
|
} catch (\Exception $e) {
|
|
$this->error($e->getMessage());
|
|
}
|
|
|
|
$cleared = (new Smarty())->setCompileDir(config('ytake-laravel-smarty.compile_path'))->clearCompiledTemplate();
|
|
if ($cleared) {
|
|
$this->output->writeln('<comment>The Smarty compiled template cache has been cleaned for you</comment>');
|
|
} else {
|
|
$this->output->writeln(
|
|
'<comment>You should clear your Smarty compiled template cache at: '.
|
|
config('ytake-laravel-smarty.compile_path').'</comment>'
|
|
);
|
|
}
|
|
|
|
if ($maintenance === true) {
|
|
$this->call('up');
|
|
}
|
|
if ($running === true) {
|
|
$this->startTmux();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
private function appDown(): bool
|
|
{
|
|
if (App::isDownForMaintenance() === false) {
|
|
$this->call('down', ['--message' => 'Doing site backend and frontend updates, we will be back shortly', '--retry' => 120]);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
private function stopTmux(): bool
|
|
{
|
|
if ((new Tmux())->isRunning() === true) {
|
|
$this->call('tmux-ui:stop', ['--kill' => true]);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private function startTmux(): void
|
|
{
|
|
$this->call('tmux-ui:start');
|
|
}
|
|
}
|