Merge pull request #1257 from cachethq/settings

Convert raw usage of the session model to the repository
This commit is contained in:
Graham Campbell
2015-12-23 15:35:18 +00:00
3 changed files with 21 additions and 21 deletions

View File

@@ -51,12 +51,10 @@ class Repository
*/
public function get($name, $default = null)
{
// if we've not loaded the settings, load them now
if (!$this->settings) {
$this->settings = $this->model->all()->lists('value', 'name');
}
// if the setting exists and is not blank, return it
if (!empty($this->settings[$name])) {
return $this->settings[$name];
}
@@ -67,19 +65,25 @@ class Repository
/**
* Creates or updates a setting value.
*
* @param string $name
* @param string $value
* @param string $name
* @param string|null $value
*
* @return void
*/
public function set($name, $value)
{
// save the change to the db
$this->model->updateOrCreate(compact('name'), compact('value'));
if ($value === null) {
$this->model->where('name', $name)->delete();
// if we've loaded the settings, persist this change
if ($this->settings) {
$this->settings[$name] = $value;
if ($this->settings && isset($this->settings[$name])) {
unset($this->settings[$name]);
}
} else {
$this->model->updateOrCreate(compact('name'), compact('value'));
if ($this->settings) {
$this->settings[$name] = $value;
}
}
}
}

View File

@@ -11,7 +11,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use CachetHQ\Cachet\Models\Setting;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\User;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
@@ -197,8 +197,7 @@ class SettingsController extends Controller
$redirectUrl = Session::get('redirect_to', route('dashboard.settings.setup'));
if (Binput::get('remove_banner') === '1') {
$setting = Setting::where('name', 'app_banner');
$setting->delete();
Setting::set('app_banner', null);
}
if (Binput::hasFile('app_banner')) {
@@ -221,10 +220,10 @@ class SettingsController extends Controller
}
// Store the banner.
Setting::firstOrCreate(['name' => 'app_banner'])->update(['value' => base64_encode(file_get_contents($file->getRealPath()))]);
Setting::set('app_banner', base64_encode(file_get_contents($file->getRealPath())));
// Store the banner type
Setting::firstOrCreate(['name' => 'app_banner_type'])->update(['value' => $file->getMimeType()]);
// Store the banner type.
Setting::set('app_banner_type', $file->getMimeType());
}
try {
@@ -233,7 +232,7 @@ class SettingsController extends Controller
$settingValue = rtrim($settingValue, '/');
}
Setting::firstOrCreate(['name' => $settingName])->update(['value' => $settingValue]);
Setting::set($settingName, $settingValue);
}
} catch (Exception $e) {
return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.edit.failure'));

View File

@@ -11,7 +11,7 @@
namespace CachetHQ\Cachet\Http\Controllers;
use CachetHQ\Cachet\Models\Setting;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\User;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
@@ -166,10 +166,7 @@ class SetupController extends Controller
$settings = array_pull($postData, 'settings');
foreach ($settings as $settingName => $settingValue) {
Setting::create([
'name' => $settingName,
'value' => $settingValue,
]);
Setting::set($settingName, $settingValue);
}
$envData = array_pull($postData, 'env');