Cleanup settings() call and log messages
This commit is contained in:
@@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Repositories;
|
namespace App\Repositories;
|
||||||
|
|
||||||
|
use Log;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
use Prettus\Repository\Contracts\CacheableInterface;
|
use Prettus\Repository\Contracts\CacheableInterface;
|
||||||
|
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Repositories\Traits\CacheableRepository;
|
use App\Repositories\Traits\CacheableRepository;
|
||||||
|
use Prettus\Validator\Exceptions\ValidatorException;
|
||||||
|
|
||||||
class SettingRepository extends BaseRepository implements CacheableInterface
|
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)
|
public function store($key, $value)
|
||||||
{
|
{
|
||||||
$setting = $this->findWhere(['key' => $key], ['id'])->first();
|
$setting = $this->findWhere(['key' => $key], ['id'])->first();
|
||||||
@@ -56,6 +65,12 @@ class SettingRepository extends BaseRepository implements CacheableInterface
|
|||||||
return null;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
use App\Models\Flight;
|
use App\Models\Flight;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UserBid;
|
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 it's already been bid on, then it can't be bid on again
|
||||||
if($flight->has_bid && setting('bids.disable_flight_on_bid')) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ class FlightService extends BaseService
|
|||||||
if(!setting('bids.allow_multiple_bids')) {
|
if(!setting('bids.allow_multiple_bids')) {
|
||||||
$user_bids = UserBid::where(['user_id' => $user->id])->first();
|
$user_bids = UserBid::where(['user_id' => $user->id])->first();
|
||||||
if($user_bids) {
|
if($user_bids) {
|
||||||
Log.info('User "' . $user->id . '" already has bids, skipping');
|
Log::info('User "' . $user->id . '" already has bids, skipping');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -6,11 +6,11 @@
|
|||||||
if (!function_exists('setting')) {
|
if (!function_exists('setting')) {
|
||||||
function setting($key, $value = null)
|
function setting($key, $value = null)
|
||||||
{
|
{
|
||||||
$settingRepo = app('setting');
|
$settingRepo = app('setting'); // defined in AppServiceProvider
|
||||||
if($value === null) {
|
if($value !== null) {
|
||||||
return $settingRepo->retrieve($key);
|
return $settingRepo->store($key, $value);
|
||||||
} else {
|
|
||||||
$settingRepo->set($key, $value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $settingRepo->retrieve($key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user