From 46decc12502eef1a13703dab87b77a4a29e63554 Mon Sep 17 00:00:00 2001 From: cuneytsenturk Date: Thu, 7 Mar 2019 16:41:14 +0300 Subject: [PATCH] close #782 Enhancement: Schedule Time configuration change --- .env.example | 1 + .env.testing | 1 + app/Console/Kernel.php | 8 ++-- app/Http/Controllers/Settings/Settings.php | 3 ++ app/Listeners/Updates/V11/Version112.php | 9 +---- app/Listeners/Updates/V13/Version1313.php | 43 ++++++++++++++++++++++ app/Providers/EventServiceProvider.php | 1 + 7 files changed, 56 insertions(+), 10 deletions(-) create mode 100644 app/Listeners/Updates/V13/Version1313.php diff --git a/.env.example b/.env.example index c15b6a8d6..7340c448e 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,7 @@ APP_KEY= APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL= +APP_SCHEDULE_TIME="09:00" DB_CONNECTION=mysql DB_HOST=localhost diff --git a/.env.testing b/.env.testing index 05683b486..e312103a3 100644 --- a/.env.testing +++ b/.env.testing @@ -6,6 +6,7 @@ APP_KEY=base64:xBC+BxlC7sXhYAtpTZv8TYAHqoPgsJaXL0S5Id6BbBc= APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://akaunting.test +APP_SCHEDULE_TIME="09:00" DB_CONNECTION=sqlite DB_DATABASE=:memory: diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 96844ddfc..3db83e239 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -37,9 +37,11 @@ class Kernel extends ConsoleKernel return; } - $schedule->command('reminder:invoice')->dailyAt(setting('general.schedule_time', '09:00')); - $schedule->command('reminder:bill')->dailyAt(setting('general.schedule_time', '09:00')); - $schedule->command('recurring:check')->dailyAt(setting('general.schedule_time', '09:00')); + $schedule_time = env('APP_SCHEDULE_TIME', '09:00'); + + $schedule->command('reminder:invoice')->dailyAt($schedule_time); + $schedule->command('reminder:bill')->dailyAt($schedule_time); + $schedule->command('recurring:check')->dailyAt($schedule_time); } /** diff --git a/app/Http/Controllers/Settings/Settings.php b/app/Http/Controllers/Settings/Settings.php index 27fb9923c..e8f6e0a2a 100644 --- a/app/Http/Controllers/Settings/Settings.php +++ b/app/Http/Controllers/Settings/Settings.php @@ -188,6 +188,9 @@ class Settings extends Controller case 'session_handler': Installer::updateEnv(['SESSION_DRIVER' => $value]); break; + case 'schedule_time': + Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $value . '"']); + break; } } } diff --git a/app/Listeners/Updates/V11/Version112.php b/app/Listeners/Updates/V11/Version112.php index 235959f3b..21bbde8af 100644 --- a/app/Listeners/Updates/V11/Version112.php +++ b/app/Listeners/Updates/V11/Version112.php @@ -5,7 +5,7 @@ namespace App\Listeners\Updates\V11; use App\Events\UpdateFinished; use App\Listeners\Updates\Listener; use App\Models\Common\Company; -use DotenvEditor; +use App\Utilities\Installer; class Version112 extends Listener { @@ -34,11 +34,6 @@ class Version112 extends Listener } // Set default locale - DotenvEditor::setKeys([ - [ - 'key' => 'APP_LOCALE', - 'value' => $locale, - ], - ])->save(); + Installer::updateEnv(['APP_LOCALE' => $locale]); } } diff --git a/app/Listeners/Updates/V13/Version1313.php b/app/Listeners/Updates/V13/Version1313.php new file mode 100644 index 000000000..c01ce7fce --- /dev/null +++ b/app/Listeners/Updates/V13/Version1313.php @@ -0,0 +1,43 @@ +check($event)) { + return; + } + + $schedule_time = '09:00'; + + // Get default locale if only 1 company + if (Company::all()->count() == 1) { + $schedule_time = setting('general.schedule_time', '09:00'); + } + + // Set default locale + Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $schedule_time . '"']); + + // Update database + Artisan::call('migrate', ['--force' => true]); + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index b5732a2fa..c3d80ac45 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -34,6 +34,7 @@ class EventServiceProvider extends ServiceProvider 'App\Listeners\Updates\V13\Version138', 'App\Listeners\Updates\V13\Version139', 'App\Listeners\Updates\V13\Version1311', + 'App\Listeners\Updates\V13\Version1313', ], 'Illuminate\Auth\Events\Login' => [ 'App\Listeners\Auth\Login',