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()
{ {
try {
$options = DB::table('options')->get(); $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,6 +80,7 @@ class OptionRepository extends Repository
{ {
$this->items_modified = array_unique($this->items_modified); $this->items_modified = array_unique($this->items_modified);
try {
foreach ($this->items_modified as $key) { foreach ($this->items_modified as $key) {
if (!DB::table('options')->where('option_name', $key)->first()) { if (!DB::table('options')->where('option_name', $key)->first()) {
DB::table('options') DB::table('options')
@ -85,6 +91,9 @@ class OptionRepository extends Repository
->update(['option_value' => $this[$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');