fix booting option repository at setup

This commit is contained in:
printempw 2016-10-23 13:04:59 +08:00
parent 429dc7c7a7
commit 7f79a654bd
3 changed files with 20 additions and 11 deletions

View File

@ -213,7 +213,7 @@ class PluginManager
*/ */
public function getEnabled() public function getEnabled()
{ {
return json_decode($this->option->get('plugins_enabled'), true); return (array) json_decode($this->option->get('plugins_enabled'), true);
} }
/** /**

View File

@ -4,6 +4,7 @@ namespace App\Services\Repositories;
use DB; use DB;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Database\QueryException;
class OptionRepository extends Repository class OptionRepository extends Repository
{ {
@ -21,7 +22,11 @@ class OptionRepository extends Repository
*/ */
public function __construct() public function __construct()
{ {
$options = DB::table('options')->get(); try {
$options = DB::table('options')->get();
} catch (QueryException $e) {
$options = [];
}
foreach ($options as $option) { foreach ($options as $option) {
$this->items[$option->option_name] = $option->option_value; $this->items[$option->option_name] = $option->option_value;
@ -75,15 +80,19 @@ class OptionRepository extends Repository
{ {
$this->items_modified = array_unique($this->items_modified); $this->items_modified = array_unique($this->items_modified);
foreach ($this->items_modified as $key) { try {
if (!DB::table('options')->where('option_name', $key)->first()) { foreach ($this->items_modified as $key) {
DB::table('options') if (!DB::table('options')->where('option_name', $key)->first()) {
->insert(['option_name' => $key, 'option_value' => $this[$key]]); DB::table('options')
} else { ->insert(['option_name' => $key, 'option_value' => $this[$key]]);
DB::table('options') } else {
->where('option_name', $key) DB::table('options')
->update(['option_value' => $this[$key]]); ->where('option_name', $key)
->update(['option_value' => $this[$key]]);
}
} }
} catch (QueryException $e) {
return;
} }
} }

View File

@ -83,7 +83,7 @@ $app->bind('url', function ($app) {
$app->instance('request', $request); $app->instance('request', $request);
$app->singleton('database', App\Services\Database\Database::class); $app->singleton('database', App\Services\Database\Database::class);
$app->singleton('option', App\Services\OptionRepository::class); $app->singleton('option', App\Services\Repositories\OptionRepository::class);
View::addExtension('tpl', 'blade'); View::addExtension('tpl', 'blade');