settingValue function will not throw an exception anymore on empty setting value, but will return null

This commit is contained in:
DariusIII
2018-05-16 10:00:11 +02:00
parent fa94caa19d
commit 70aaffbb22
7 changed files with 15 additions and 25 deletions
+4 -4
View File
@@ -184,12 +184,12 @@ class Movie
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
$this->releaseImage = ($options['ReleaseImage'] instanceof ReleaseImage ? $options['ReleaseImage'] : new ReleaseImage());
$this->traktcheck = Settings::settingValue('APIs..trakttvclientkey', true);
$this->traktcheck = Settings::settingValue('APIs..trakttvclientkey');
if ($this->traktcheck !== null) {
$this->traktTv = new TraktTv(['Settings' => $this->pdo]);
}
$this->client = new Client();
$this->tmdbtokencheck = Settings::settingValue('APIs..tmdbkey', true);
$this->tmdbtokencheck = Settings::settingValue('APIs..tmdbkey');
if ($this->tmdbtokencheck !== null) {
$this->tmdbtoken = new ApiToken($this->tmdbtokencheck);
$this->tmdbclient = new TmdbClient($this->tmdbtoken, [
@@ -201,11 +201,11 @@ class Movie
$this->tmdbconfig = $this->configRepository->load();
$this->helper = new ImageHelper($this->tmdbconfig);
}
$this->fanartapikey = Settings::settingValue('APIs..fanarttvkey', true);
$this->fanartapikey = Settings::settingValue('APIs..fanarttvkey');
if ($this->fanartapikey !== null) {
$this->fanart = new FanartTV($this->fanartapikey);
}
$this->omdbapikey = Settings::settingValue('APIs..omdbkey', true);
$this->omdbapikey = Settings::settingValue('APIs..omdbkey');
if ($this->omdbapikey !== null) {
$this->omdbApi = new OMDbAPI($this->omdbapikey);
}
+1 -1
View File
@@ -185,7 +185,7 @@ class Releases
*/
public static function showPasswords($query = null, $builder = false)
{
$setting = Settings::settingValue('..showpasswordedrelease', true);
$setting = Settings::settingValue('..showpasswordedrelease');
$setting = ($setting !== null && is_numeric($setting)) ? $setting : 10;
switch ($setting) {
case 0: // Hide releases with a password or a potential password (Hide unprocessed releases).
+1 -1
View File
@@ -343,7 +343,7 @@ class Tmux
*/
public function rand_bool($loop, $chance = 60): bool
{
$usecache = Settings::settingValue('site.tmux.usecache', true) ?? 0;
$usecache = Settings::settingValue('site.tmux.usecache') ?? 0;
if ($loop === 1 || $usecache === 0) {
return false;
}
+1
View File
@@ -1,4 +1,5 @@
2018-05-16 DariusIII
* Chg: settingValue function will not throw an exception anymore on empty setting value, but will return null
* Chg: Check also tmdb, fanart and omdb keys
* Chg: Add check for existence of trakttv api key in Movies class
* Fix: Fix movies cover and full view
+1 -1
View File
@@ -248,7 +248,7 @@ class Versions extends Collection
*/
public function getSQLPatchFromDB(): ?string
{
$dbVersion = Settings::settingValue('..sqlpatch', true);
$dbVersion = Settings::settingValue('..sqlpatch');
if (! is_numeric($dbVersion)) {
throw new \RuntimeException('Bad sqlpatch value');
+3 -14
View File
@@ -240,20 +240,11 @@ class Settings extends Model
}
/**
* Return the value of supplied setting.
* The setting can be either a normal condition array for the custom 'setting' finder or a
* dotted string notation setting. Note that dotted notation will be converted to an array,
* so it will be slower: Explicitly use the array format if speed it paramount.
* Be aware that this method only returns the first of any values found, so make sure your
* $setting produces a unique result.
* @param bool|array $setting
* @param bool $returnAlways Indicates if the method should throw an exception (false) or return
* null on failure. Defaults to throwing an exception.
* @param $setting
*
* @return string|null The setting's value, or null on failure IF 'returnAlways' is true.
* @throws \Exception
* @return null|string
*/
public static function settingValue($setting, $returnAlways = false): ?string
public static function settingValue($setting): ?string
{
$setting = self::settingToArray($setting);
$result = self::query()->where([
@@ -264,8 +255,6 @@ class Settings extends Model
if ($result !== null) {
$value = $result;
} elseif ($returnAlways === false) {
throw new \RuntimeException('Unable to fetch setting from Db!');
} else {
$value = null;
}
+4 -4
View File
@@ -11,10 +11,10 @@ use Blacklight\utility\Utility;
$pdo = new DB();
$DIR = NN_TMUX;
$patch = Settings::settingValue('..sqlpatch');
$import = Settings::settingValue('site.tmux.import', true) ?? 0;
$tmux_session = Settings::settingValue('site.tmux.tmux_session', true) ?? 0;
$seq = Settings::settingValue('site.tmux.sequential', true) ?? 0;
$powerline = Settings::settingValue('site.tmux.powerline', true) ?? 0;
$import = Settings::settingValue('site.tmux.import') ?? 0;
$tmux_session = Settings::settingValue('site.tmux.tmux_session') ?? 0;
$seq = Settings::settingValue('site.tmux.sequential') ?? 0;
$powerline = Settings::settingValue('site.tmux.powerline') ?? 0;
$delaytimet = Settings::settingValue('..delaytime');
$delaytimet = $delaytimet ? (int) $delaytimet : 2;