Cleanup settings() call and log messages

This commit is contained in:
Nabeel Shahzad
2017-12-12 17:09:26 -06:00
parent 248a8d1488
commit 5428f4387a
3 changed files with 24 additions and 8 deletions

View File

@@ -2,11 +2,13 @@
namespace App\Repositories;
use Log;
use Illuminate\Support\Carbon;
use Prettus\Repository\Contracts\CacheableInterface;
use App\Models\Setting;
use App\Repositories\Traits\CacheableRepository;
use Prettus\Validator\Exceptions\ValidatorException;
class SettingRepository extends BaseRepository implements CacheableInterface
{
@@ -49,6 +51,13 @@ class SettingRepository extends BaseRepository implements CacheableInterface
}
}
/**
* Update an existing setting with a new value. Doesn't create
* a new setting
* @param $key
* @param $value
* @return null
*/
public function store($key, $value)
{
$setting = $this->findWhere(['key' => $key], ['id'])->first();
@@ -56,6 +65,12 @@ class SettingRepository extends BaseRepository implements CacheableInterface
return null;
}
$this->update(['value' => $value], $setting->id);
try {
$this->update(['value' => $value], $setting->id);
} catch (ValidatorException $e) {
Log::error($e->getMessage(), $e->getTrace());
}
return $value;
}
}

View File

@@ -9,6 +9,7 @@
namespace App\Services;
use Log;
use App\Models\Flight;
use App\Models\User;
use App\Models\UserBid;
@@ -25,7 +26,7 @@ class FlightService extends BaseService
{
# If it's already been bid on, then it can't be bid on again
if($flight->has_bid && setting('bids.disable_flight_on_bid')) {
Log.info($flight->id . ' already has a bid, skipping');
Log::info($flight->id . ' already has a bid, skipping');
return null;
}
@@ -33,7 +34,7 @@ class FlightService extends BaseService
if(!setting('bids.allow_multiple_bids')) {
$user_bids = UserBid::where(['user_id' => $user->id])->first();
if($user_bids) {
Log.info('User "' . $user->id . '" already has bids, skipping');
Log::info('User "' . $user->id . '" already has bids, skipping');
return null;
}
}

View File

@@ -6,11 +6,11 @@
if (!function_exists('setting')) {
function setting($key, $value = null)
{
$settingRepo = app('setting');
if($value === null) {
return $settingRepo->retrieve($key);
} else {
$settingRepo->set($key, $value);
$settingRepo = app('setting'); // defined in AppServiceProvider
if($value !== null) {
return $settingRepo->store($key, $value);
}
return $settingRepo->retrieve($key);
}
}