Allow setting creation of settings. Closes #396
This commit is contained in:
@@ -35,12 +35,12 @@ class Repository
|
|||||||
/**
|
/**
|
||||||
* Returns a setting from the database.
|
* Returns a setting from the database.
|
||||||
*
|
*
|
||||||
* @param string $settingName
|
* @param string $name
|
||||||
* @param bool $checkEnv
|
* @param bool $checkEnv
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function get($settingName, $checkEnv = true)
|
public function get($name, $checkEnv = true)
|
||||||
{
|
{
|
||||||
$setting = null;
|
$setting = null;
|
||||||
|
|
||||||
@@ -49,12 +49,12 @@ class Repository
|
|||||||
$this->settings = $this->model->all()->lists('value', 'name');
|
$this->settings = $this->model->all()->lists('value', 'name');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists($settingName, $this->settings)) {
|
if (array_key_exists($name, $this->settings)) {
|
||||||
return $this->settings[$settingName];
|
return $this->settings[$name];
|
||||||
}
|
}
|
||||||
} catch (ErrorException $e) {
|
} catch (ErrorException $e) {
|
||||||
if ($checkEnv) {
|
if ($checkEnv) {
|
||||||
$env = getenv(strtoupper($settingName));
|
$env = getenv(strtoupper($name));
|
||||||
if (!$env) {
|
if (!$env) {
|
||||||
return $env;
|
return $env;
|
||||||
}
|
}
|
||||||
@@ -65,4 +65,17 @@ class Repository
|
|||||||
|
|
||||||
return $setting;
|
return $setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates or updates a setting value.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @return \CachetHQ\Cachet\Models\Setting
|
||||||
|
*/
|
||||||
|
public function set($name, $value)
|
||||||
|
{
|
||||||
|
return $this->model->updateOrCreate(compact('name'), compact('value'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user