Skip to content

Commit

Permalink
close #782 Enhancement: Schedule Time configuration change
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Mar 7, 2019
1 parent 8b0a1a5 commit 46decc1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ protected function schedule(Schedule $schedule)
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);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ protected function oneCompany($key, $value)
case 'session_handler':
Installer::updateEnv(['SESSION_DRIVER' => $value]);
break;
case 'schedule_time':
Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $value . '"']);
break;
}
}
}
9 changes: 2 additions & 7 deletions app/Listeners/Updates/V11/Version112.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Events\UpdateFinished;
use App\Listeners\Updates\Listener;
use App\Models\Common\Company;
use DotenvEditor;
use App\Utilities\Installer;

class Version112 extends Listener
{
Expand Down Expand Up @@ -34,11 +34,6 @@ public function handle(UpdateFinished $event)
}

// Set default locale
DotenvEditor::setKeys([
[
'key' => 'APP_LOCALE',
'value' => $locale,
],
])->save();
Installer::updateEnv(['APP_LOCALE' => $locale]);
}
}
43 changes: 43 additions & 0 deletions app/Listeners/Updates/V13/Version1313.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Listeners\Updates\V13;

use App\Events\UpdateFinished;
use App\Listeners\Updates\Listener;
use App\Models\Common\Company;
use App\Utilities\Installer;
use Artisan;

class Version1313 extends Listener
{
const ALIAS = 'core';

const VERSION = '1.3.13';

/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(UpdateFinished $event)
{
// Check if should listen
if (!$this->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]);
}
}
1 change: 1 addition & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 46decc1

Please sign in to comment.