From b23d80ce2109c464388f3f0c20e7dd0aee11cef5 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 11 Jan 2019 14:36:26 +0100 Subject: [PATCH] Update install command and reduce code used --- Changelog | 1 + app/Console/Commands/InstallNntmux.php | 44 ++++++-------------------- config/nntmux.php | 3 ++ 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/Changelog b/Changelog index 816ca9fba..b26443549 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2019-01-11 DariusIII + * Chg: Update install command and reduce code used * Chg: Simplify UpdateNNTmuxDB.php handle function, use native artisan commands without Symfony Process component * Chg: Update czproject/git-php to version 2.15.0 2019-01-10 DariusIII diff --git a/app/Console/Commands/InstallNntmux.php b/app/Console/Commands/InstallNntmux.php index 81fea2d1c..43cff14c9 100644 --- a/app/Console/Commands/InstallNntmux.php +++ b/app/Console/Commands/InstallNntmux.php @@ -71,26 +71,10 @@ class InstallNntmux extends Command } } $this->info('Migrating tables and seeding them with initial data'); - if (env('APP_ENV') !== 'production') { - $process = new Process('php artisan migrate:fresh --seed'); - $process->setTimeout(600); - $process->run(function ($type, $buffer) { - if (Process::ERR === $type) { - echo 'ERR > '.$buffer; - } else { - echo $buffer; - } - }); + if (config('app.env') !== 'production') { + $this->call('migrate:fresh', ['--seed' => true]); } else { - $process = new Process('php artisan migrate:fresh --force --seed'); - $process->setTimeout(600); - $process->run(function ($type, $buffer) { - if (Process::ERR === $type) { - echo 'ERR > '.$buffer; - } else { - echo $buffer; - } - }); + $this->call('migrate:fresh', ['--force' => true, '--seed' => true]); } $paths = $this->updatePaths(); @@ -108,15 +92,7 @@ class InstallNntmux extends Command if (! $error && $this->addAdminUser()) { File::put(base_path().'/_install/install.lock', 'application install locked on '.now()); $this->info('Generating application key'); - $process = new Process('php artisan key:generate --force'); - $process->setTimeout(600); - $process->run(function ($type, $buffer) { - if (Process::ERR === $type) { - echo 'ERR > '.$buffer; - } else { - echo $buffer; - } - }); + $this->call('key:generate', ['--force' => true]); $this->info('NNTmux installation completed successfully'); exit(); } @@ -141,7 +117,7 @@ class InstallNntmux extends Command $tmp_path = base_path().'/resources/tmp/'; $unrar_path = $tmp_path.'unrar/'; - $nzbPathCheck = is_writable($nzb_path); + $nzbPathCheck = File::isWritable($nzb_path); if ($nzbPathCheck === false) { $this->warn($nzb_path.' is not writable. Please fix folder permissions'); @@ -150,7 +126,7 @@ class InstallNntmux extends Command if (! file_exists($unrar_path)) { $this->info('Creating missing '.$unrar_path.' folder'); - if (! @mkdir($unrar_path) && ! is_dir($unrar_path)) { + if (! @File::makeDirectory($unrar_path) && ! File::isDirectory($unrar_path)) { throw new \RuntimeException('Unable to create '.$unrar_path.' folder'); } $this->info('Folder '.$unrar_path.' successfully created'); @@ -162,7 +138,7 @@ class InstallNntmux extends Command return false; } - $coversPathCheck = is_writable($covers_path); + $coversPathCheck = File::isWritable($covers_path); if ($coversPathCheck === false) { $this->warn($covers_path.' is not writable. Please fix folder permissions'); @@ -181,15 +157,15 @@ class InstallNntmux extends Command */ private function addAdminUser(): bool { - if (env('ADMIN_USER') === '' || env('ADMIN_PASS') === '' || env('ADMIN_EMAIL') === '') { + if (config('nntmux.admin_username') === '' || config('nntmux.admin_password') === '' || config('nntmux.admin_email') === '') { $this->error('Admin user data cannot be empty! Please edit .env file and fill in admin user details and run this script again!'); exit(); } $this->info('Adding admin user to database'); try { - User::add(env('ADMIN_USER'), env('ADMIN_PASS'), env('ADMIN_EMAIL'), 2, '', '', '', ''); - User::where('username', env('ADMIN_USER'))->update(['verified' => 1]); + User::add(config('nntmux.admin_username'), config('nntmux.admin_password'), config('nntmux.admin_email'), 2, '', '', '', ''); + User::where('username', config('nntmux.admin_username'))->update(['verified' => 1]); } catch (\Throwable $e) { echo $e->getMessage(); $this->error('Unable to add admin user!'); diff --git a/config/nntmux.php b/config/nntmux.php index 13c5c8077..ed3a27c95 100644 --- a/config/nntmux.php +++ b/config/nntmux.php @@ -14,4 +14,7 @@ return [ 'cache_expiry_short' => env('CACHE_EXPIRY_SHORT', 5), 'cache_expiry_medium' =>env('CACHE_EXPIRY_MEDIUM', 10), 'cache_expiry_long' => env('CACHE_EXPIRY_LONG', 15), + 'admin_username' => env('ADMIN_USER', 'admin'), + 'admin_password' => env('ADMIN_PASS', 'admin'), + 'admin_email' => env('ADMIN_EMAIL', 'admin@example.com') ];