Skip to content

Commit

Permalink
fixed #132
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Dec 6, 2017
1 parent eaf703a commit 4665038
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/Http/Controllers/Install/Requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ private function createEnvFile()
'key' => 'APP_ENV',
'value' => 'production',
],
[
'key' => 'APP_LOCALE',
'value' => 'en-GB',
],
[
'key' => 'APP_INSTALLED',
'value' => 'false',
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Controllers/Install/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ private function finalTouches()

// Update .env file
DotenvEditor::setKeys([
[
'key' => 'APP_LOCALE',
'value' => session('locale'),
],
[
'key' => 'APP_INSTALLED',
'value' => 'true',
Expand Down
18 changes: 16 additions & 2 deletions app/Http/Controllers/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use App\Http\Controllers\Controller;
use App\Http\Requests\Setting\Setting as Request;
use App\Models\Banking\Account;
use App\Models\Company\Company;
use App\Models\Setting\Currency;
use App\Models\Setting\Tax;
use App\Models\Setting\Setting;
use App\Models\Setting\Tax;
use App\Traits\DateTime;
use App\Traits\Uploads;

use App\Utilities\Modules;
use DotenvEditor;

class Settings extends Controller
{
Expand Down Expand Up @@ -90,6 +91,8 @@ public function update(Request $request)

$skip_keys = ['company_id', '_method', '_token'];
$file_keys = ['company_logo', 'invoice_logo'];

$companies = Company::all()->count();

foreach ($fields as $key => $value) {
// Don't process unwanted keys
Expand All @@ -107,6 +110,17 @@ public function update(Request $request)
}
}

// Change default locale if only 1 company
if (($key == 'default_locale') && ($companies == 1)) {
// Update .env file
DotenvEditor::setKeys([
[
'key' => 'APP_LOCALE',
'value' => $value,
],
])->save();
}

setting()->set('general.' . $key, $value);
}

Expand Down
43 changes: 43 additions & 0 deletions app/Listeners/Updates/Version111.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Listeners\Updates;

use App\Events\UpdateFinished;
use App\Models\Company\Company;
use DotenvEditor;

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

const VERSION = '1.1.1';

/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(UpdateFinished $event)
{
// Check if should listen
if (!$this->check($event)) {
return;
}

$locale = 'en-GB';

// Get default locale if only 1 company
if (Company::all()->count() == 1) {
$locale = setting('general.default_locale', 'en-GB');
}

// Set default locale
DotenvEditor::setKeys([
[
'key' => 'APP_LOCALE',
'value' => $locale,
],
])->save();
}
}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
|
*/

'locale' => 'en-GB',
'locale' => env('APP_LOCALE', 'en-GB'),

/*
|--------------------------------------------------------------------------
Expand Down

0 comments on commit 4665038

Please sign in to comment.