Added logging to Settings

This commit is contained in:
Miguel Nogueira 2020-08-31 19:47:27 +01:00
parent ea96cbc1f5
commit 2afea88846
2 changed files with 13 additions and 3 deletions

View File

@ -5,6 +5,7 @@ namespace App\Helpers;
use App\Options as Option; use App\Options as Option;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
class Options class Options
{ {
@ -15,6 +16,7 @@ class Options
if (is_null($value)) if (is_null($value))
{ {
Log::info('Option ' . $option . 'not found in cache, refreshing from database');
$value = Option::where('option_name', $option)->first(); $value = Option::where('option_name', $option)->first();
if (is_null($value)) if (is_null($value))
throw new \Exception('This option does not exist.'); throw new \Exception('This option does not exist.');
@ -59,10 +61,19 @@ class Options
$dbOptionInstance = Option::find($dbOption->first()->id); $dbOptionInstance = Option::find($dbOption->first()->id);
Cache::forget($option); Cache::forget($option);
Log::warning('Changing db configuration option', [
'old_value' => $dbOptionInstance->option_value,
'new_value' => $newValue
]);
$dbOptionInstance->option_value = $newValue; $dbOptionInstance->option_value = $newValue;
$dbOptionInstance->save(); $dbOptionInstance->save();
Log::warning('New db configuration option saved',
[
'option' => $dbOptionInstance->option_value
]);
Cache::put('option_name', $newValue, now()->addDay()); Cache::put('option_name', $newValue, now()->addDay());
} }
else else

View File

@ -40,9 +40,8 @@ class OptionsController extends Controller
} }
catch(\Exception $ex) catch(\Exception $ex)
{ {
// Silently ignore, because the only way this would happen is if someone manipulates the page, $request->session()->flash('error', 'An error occurred while trying to save settings: ' . $ex->getMessage());
// and obviously we can't save arbitrary option values even if the user has permission to do so. exit;
continue;
} }
} }