Slightly more robust configuration polling.

This commit is contained in:
James Cole
2020-07-06 06:49:48 +02:00
parent 4271dc1638
commit 26d19fab32
4 changed files with 32 additions and 25 deletions

View File

@@ -44,7 +44,8 @@ trait UpdateTrait
Log::debug('Now in getLatestRelease()'); Log::debug('Now in getLatestRelease()');
/** @var UpdateRequestInterface $checker */ /** @var UpdateRequestInterface $checker */
$checker = app(UpdateRequestInterface::class); $checker = app(UpdateRequestInterface::class);
$channel = app('fireflyconfig')->get('update_channel', 'stable')->data; $channelConfig = app('fireflyconfig')->get('update_channel', 'stable');
$channel = $channelConfig ? $channelConfig->data : 'stable';
return $checker->getUpdateInformation($channel); return $checker->getUpdateInformation($channel);
} }

View File

@@ -55,7 +55,8 @@ class Controller extends BaseController
public function __construct() public function __construct()
{ {
// is site a demo site? // is site a demo site?
$isDemoSite = app('fireflyconfig')->get('is_demo_site', config('firefly.configuration.is_demo_site', false,),)->data; $isDemoSiteConfig = app('fireflyconfig')->get('is_demo_site', config('firefly.configuration.is_demo_site', false,),);
$isDemoSite = $isDemoSiteConfig ? $isDemoSiteConfig->data : false;
app('view')->share('IS_DEMO_SITE', $isDemoSite,); app('view')->share('IS_DEMO_SITE', $isDemoSite,);
app('view')->share('DEMO_USERNAME', config('firefly.demo_username')); app('view')->share('DEMO_USERNAME', config('firefly.demo_username'));
app('view')->share('DEMO_PASSWORD', config('firefly.demo_password')); app('view')->share('DEMO_PASSWORD', config('firefly.demo_password'));

View File

@@ -122,7 +122,8 @@ class DebugController extends Controller
$replace = ['\~', '# ']; $replace = ['\~', '# '];
$now = Carbon::now()->format('Y-m-d H:i:s e'); $now = Carbon::now()->format('Y-m-d H:i:s e');
$installationId = app('fireflyconfig')->get('installation_id', '')->data; $installationIdConfig = app('fireflyconfig')->get('installation_id', '');
$installationId = $installationIdConfig ? $installationIdConfig->data : '';
$phpVersion = str_replace($search, $replace, PHP_VERSION); $phpVersion = str_replace($search, $replace, PHP_VERSION);
$phpOs = str_replace($search, $replace, PHP_OS); $phpOs = str_replace($search, $replace, PHP_OS);
$interface = PHP_SAPI; $interface = PHP_SAPI;

View File

@@ -24,6 +24,7 @@ namespace FireflyIII\Support;
use Cache; use Cache;
use Exception; use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Configuration; use FireflyIII\Models\Configuration;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Log; use Log;
@@ -67,9 +68,10 @@ class FireflyConfig
/** /**
* @param string $name * @param string $name
* @param mixed $default * @param null $default
* *
* @return \FireflyIII\Models\Configuration|null * @throws FireflyException
* @return Configuration|null
*/ */
public function get(string $name, $default = null): ?Configuration public function get(string $name, $default = null): ?Configuration
{ {
@@ -82,10 +84,12 @@ class FireflyConfig
} }
try { try {
/** @var Configuration $config */
$config = Configuration::where('name', $name)->first(['id', 'name', 'data']); $config = Configuration::where('name', $name)->first(['id', 'name', 'data']);
} catch (QueryException|Exception $e) { } catch (QueryException|Exception $e) {
Log::error(sprintf('Query exception while polling for config var: %s', $e->getMessage())); Log::error(sprintf('Query exception while polling for config var: %s', $e->getMessage()));
return null; Log::error($e->getTraceAsString());
throw new FireflyException(sprintf('Could not poll the database: %s', $e->getMessage()));
} }
if ($config) { if ($config) {