Improved the config system

This commit is contained in:
Graham Campbell
2016-01-29 22:49:06 +00:00
parent 51e850ddc2
commit 1b24cdb1c5
35 changed files with 188 additions and 232 deletions

View File

@@ -11,7 +11,6 @@
namespace CachetHQ\Cachet\Composers;
use CachetHQ\Cachet\Facades\Setting;
use GrahamCampbell\Markdown\Facades\Markdown;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Config;
@@ -27,26 +26,27 @@ class AppComposer
*/
public function compose(View $view)
{
$support = Setting::get('show_support');
$view->withAboutApp(Markdown::convertToHtml(Setting::get('app_about')));
$view->withAppAnalytics(Setting::get('app_analytics'));
$view->withAppAnalyticsGoSquared(Setting::get('app_analytics_go_squared'));
$view->withAppAnalyticsPiwikUrl(Setting::get('app_analytics_piwik_url'));
$view->withAppAnalyticsPiwikSiteId(Setting::get('app_analytics_piwik_siteid'));
$view->withAppBanner(Setting::get('app_banner'));
$view->withAppBannerStyleFullWidth(Setting::get('style_fullwidth_header'));
$view->withAppBannerType(Setting::get('app_banner_type'));
$view->withAppDomain(Setting::get('app_domain'));
$view->withAppGraphs(Setting::get('display_graphs'));
$view->withAppLocale(Setting::get('app_locale'));
$view->withAppName(Setting::get('app_name'));
if ($support) {
$view->withSiteTitle(Setting::get('app_name').' | Cachet');
} else {
$view->withSiteTitle(Setting::get('app_name'));
}
$view->withAppStylesheet(Setting::get('stylesheet'));
$view->withAboutApp(Markdown::convertToHtml(Config::get('setting.app_about')));
$view->withAppAnalytics(Config::get('setting.app_analytics'));
$view->withAppAnalyticsGoSquared(Config::get('setting.app_analytics_go_squared'));
$view->withAppAnalyticsPiwikUrl(Config::get('setting.app_analytics_piwik_url'));
$view->withAppAnalyticsPiwikSiteId(Config::get('setting.app_analytics_piwik_siteid'));
$view->withAppBanner(Config::get('setting.app_banner'));
$view->withAppBannerStyleFullWidth(Config::get('setting.style_fullwidth_header'));
$view->withAppBannerType(Config::get('setting.app_banner_type'));
$view->withAppDomain(Config::get('setting.app_domain'));
$view->withAppGraphs(Config::get('setting.display_graphs'));
$view->withAppLocale(Config::get('setting.app_locale'));
$view->withAppStylesheet(Config::get('setting.stylesheet'));
$view->withAppUrl(Config::get('app.url'));
$view->withShowSupport($support);
$view->withAppName($name =Config::get('setting.app_name'));
$view->withShowSupport($support = Config::get('setting.show_support'));
if ($support) {
$view->withSiteTitle(Config::get('setting.app_name').' | Cachet');
} else {
$view->withSiteTitle(Config::get('setting.app_name'));
}
}
}

View File

@@ -11,10 +11,10 @@
namespace CachetHQ\Cachet\Composers;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Config;
class MetricsComposer
{
@@ -46,7 +46,7 @@ class MetricsComposer
{
$metrics = null;
$metricData = [];
if ($displayMetrics = Setting::get('display_graphs')) {
if ($displayMetrics = Config::get('setting.display_graphs')) {
$metrics = Metric::where('display_chart', 1)->orderBy('id')->get();
$metrics->map(function ($metric) use (&$metricData) {

View File

@@ -11,8 +11,8 @@
namespace CachetHQ\Cachet\Composers;
use CachetHQ\Cachet\Facades\Setting;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Config;
class ThemeComposer
{
@@ -26,17 +26,17 @@ class ThemeComposer
public function compose(View $view)
{
// Theme colors.
$view->withThemeBackgroundColor(Setting::get('style_background_color', '#F0F3F4'));
$view->withThemeBackgroundFills(Setting::get('style_background_fills', '#FFFFFF'));
$view->withThemeBannerBackgroundColor(Setting::get('style_banner_background_color', ''));
$view->withThemeBannerPadding(Setting::get('style_banner_padding', '40px 0'));
$view->withThemeTextColor(Setting::get('style_text_color', '#333333'));
$view->withThemeReds(Setting::get('style_reds', '#ff6f6f'));
$view->withThemeBlues(Setting::get('style_blues', '#3498db'));
$view->withThemeGreens(Setting::get('style_greens', '#7ED321'));
$view->withThemeYellows(Setting::get('style_yellows', '#F7CA18'));
$view->withThemeOranges(Setting::get('style_oranges', '#FF8800'));
$view->withThemeMetrics(Setting::get('style_metrics', '#0dccc0'));
$view->withThemeLinks(Setting::get('style_links', '#7ED321'));
$view->withThemeBackgroundColor(Config::get('setting.style_background_color', '#F0F3F4'));
$view->withThemeBackgroundFills(Config::get('setting.style_background_fills', '#FFFFFF'));
$view->withThemeBannerBackgroundColor(Config::get('setting.style_banner_background_color', ''));
$view->withThemeBannerPadding(Config::get('setting.style_banner_padding', '40px 0'));
$view->withThemeTextColor(Config::get('setting.style_text_color', '#333333'));
$view->withThemeReds(Config::get('setting.style_reds', '#ff6f6f'));
$view->withThemeBlues(Config::get('setting.style_blues', '#3498db'));
$view->withThemeGreens(Config::get('setting.style_greens', '#7ED321'));
$view->withThemeYellows(Config::get('setting.style_yellows', '#F7CA18'));
$view->withThemeOranges(Config::get('setting.style_oranges', '#FF8800'));
$view->withThemeMetrics(Config::get('setting.style_metrics', '#0dccc0'));
$view->withThemeLinks(Config::get('setting.style_links', '#7ED321'));
}
}

View File

@@ -23,11 +23,11 @@ class Repository
protected $model;
/**
* Cache of the settings.
* Is the config state stale?
*
* @var array|null
* @var bool
*/
protected $settings;
protected $stale = false;
/**
* Create a new settings service instance.
@@ -44,26 +44,15 @@ class Repository
/**
* Returns a setting from the database.
*
* @param string $name
* @param string|null $default
*
* @return string|null
* @return array
*/
public function get($name, $default = null)
public function all()
{
if (!$this->settings) {
$this->settings = $this->model->all()->pluck('value', 'name');
}
if (!empty($this->settings[$name])) {
return $this->settings[$name];
}
return $default;
return $this->model->all(['name', 'value'])->pluck('value', 'name')->toArray();
}
/**
* Creates or updates a setting value.
* Updates a setting value.
*
* @param string $name
* @param string|null $value
@@ -72,18 +61,22 @@ class Repository
*/
public function set($name, $value)
{
$this->stale = true;
if ($value === null) {
$this->model->where('name', $name)->delete();
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;
}
}
}
/**
* Is the config state stale?
*
* @return bool
*/
public function stale()
{
return $this->stale;
}
}

View File

@@ -1,30 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @see \CachetHQ\Cachet\Services\SettingsService
*/
class Setting extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'setting';
}
}

View File

@@ -12,9 +12,10 @@
namespace CachetHQ\Cachet\Foundation\Providers;
use CachetHQ\Cachet\Config\Repository;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Setting as SettingModel;
use Exception;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
class ConfigServiceProvider extends ServiceProvider
@@ -26,40 +27,57 @@ class ConfigServiceProvider extends ServiceProvider
*/
public function boot()
{
$appDomain = $appLocale = $appTimezone = null;
try {
// Get app custom configuration.
$appDomain = Setting::get('app_domain');
$appLocale = Setting::get('app_locale');
$appTimezone = Setting::get('app_timezone');
// Setup Cors.
$allowedOrigins = $this->app->config->get('cors.defaults.allowedOrigins');
$allowedOrigins[] = Setting::get('app_domain');
// Add our allowed domains too.
if ($allowedDomains = Setting::get('allowed_domains')) {
$domains = explode(',', $allowedDomains);
foreach ($domains as $domain) {
$allowedOrigins[] = $domain;
}
if ($this->app->configurationIsCached()) {
if ($this->app->environment() === 'production') {
$this->app->terminating(function () {
if ($this->app->setting->stale()) {
$this->app->make(Kernel::class)->call('config:cache');
}
});
} else {
$allowedOrigins[] = $this->app->config->get('app.url');
$this->app->make(Kernel::class)->call('config:clear');
}
$this->app->config->set('cors.paths.api/v1/*.allowedOrigins', $allowedOrigins);
} catch (Exception $e) {
// Don't throw any errors, we may not be setup yet.
return;
}
// Override default app values.
$this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url'));
$this->app->config->set('app.locale', $appLocale ?: $this->app->config->get('app.locale'));
$this->app->config->set('cachet.timezone', $appTimezone ?: $this->app->config->get('cachet.timezone'));
try {
$this->app->config->set('setting', $this->app->setting->all());
} catch (Exception $e) {
//
}
// Set custom lang.
$this->app->translator->setLocale($appLocale);
if ($appDomain = $this->app->config->get('setting.app_domain')) {
$this->app->config->set('app.url', $appDomain);
}
if ($appLocale = $this->app->config->get('setting.app.locale')) {
$this->app->config->set('app.locale', $appLocale);
$this->app->translator->setLocale($appLocale);
}
if ($appTimezone = $this->app->config->get('setting.app_timezone')) {
$this->app->config->set('cachet.timezone', $appTimezone);
}
$allowedOrigins = $this->app->config->get('cors.defaults.allowedOrigins');
if ($allowedDomains = $this->app->config->get('setting.allowed_domains')) {
$domains = explode(',', $allowedDomains);
foreach ($domains as $domain) {
$allowedOrigins[] = $domain;
}
} else {
$allowedOrigins[] = $this->app->config->get('app.url');
}
$this->app->config->set('cors.paths.api/v1/*.allowedOrigins', $allowedOrigins);
if ($this->app->environment() === 'production') {
$this->app->terminating(function () {
$this->app->make(Kernel::class)->call('config:cache');
});
}
}
/**

View File

@@ -11,11 +11,11 @@
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\Subscriber;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View;
use Jenssegers\Date\Date;
@@ -43,7 +43,7 @@ class DashboardController extends Controller
public function __construct()
{
$this->startDate = new Date();
$this->dateTimeZone = Setting::get('app_timezone');
$this->dateTimeZone = Config::get('cachet.timezone');
}
/**

View File

@@ -11,11 +11,11 @@
namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\User;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Session;
@@ -102,7 +102,7 @@ class SettingsController extends Controller
return View::make('dashboard.settings.app-setup')
->withPageTitle(trans('dashboard.settings.app-setup.app-setup').' - '.trans('dashboard.dashboard'))
->withSubMenu($this->subMenu)
->withRawAppAbout(Setting::get('app_about'));
->withRawAppAbout(Config::get('setting.app_about'));
}
/**
@@ -197,8 +197,10 @@ class SettingsController extends Controller
{
$redirectUrl = Session::get('redirect_to', route('dashboard.settings.setup'));
$setting = app('setting');
if (Binput::get('remove_banner') === '1') {
Setting::set('app_banner', null);
$setting->set('app_banner', null);
}
if (Binput::hasFile('app_banner')) {
@@ -221,10 +223,10 @@ class SettingsController extends Controller
}
// Store the banner.
Setting::set('app_banner', base64_encode(file_get_contents($file->getRealPath())));
$setting->set('app_banner', base64_encode(file_get_contents($file->getRealPath())));
// Store the banner type.
Setting::set('app_banner_type', $file->getMimeType());
$setting->set('app_banner_type', $file->getMimeType());
}
try {
@@ -233,7 +235,7 @@ class SettingsController extends Controller
$settingValue = rtrim($settingValue, '/');
}
Setting::set($settingName, $settingValue);
$setting->set($settingName, $settingValue);
}
} catch (Exception $e) {
return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.edit.failure'));

View File

@@ -11,11 +11,11 @@
namespace CachetHQ\Cachet\Http\Controllers;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident;
use GrahamCampbell\Markdown\Facades\Markdown;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Str;
use Roumen\Feed\Facades\Feed;
@@ -36,9 +36,9 @@ class FeedController extends Controller
public function __construct()
{
$this->feed = Feed::make();
$this->feed->title = Setting::get('app_name');
$this->feed->title = Config::get('setting.app_name');
$this->feed->description = trans('cachet.feed');
$this->feed->link = Str::canonicalize(Setting::get('app_domain'));
$this->feed->link = Str::canonicalize(Config::get('setting.app_domain'));
$this->feed->setDateFormat('datetime');
}
@@ -63,7 +63,7 @@ class FeedController extends Controller
*/
public function rssAction(ComponentGroup $group = null)
{
$this->feed->lang = Setting::get('app_locale');
$this->feed->lang = Config::get('setting.app_locale');
return $this->feedAction($group, true);
}
@@ -103,7 +103,7 @@ class FeedController extends Controller
{
$this->feed->add(
$incident->name,
Setting::get('app_name'),
Config::get('setting.app_name'),
Str::canonicalize(route('incident', ['id' => $incident->id])),
$isRss ? $incident->created_at->toRssString() : $incident->created_at->toAtomString(),
$isRss ? $incident->message : Markdown::convertToHtml($incident->message)

View File

@@ -11,7 +11,6 @@
namespace CachetHQ\Cachet\Http\Controllers;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\User;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
@@ -179,10 +178,12 @@ class SetupController extends Controller
Auth::login($user);
$setting = app('setting');
$settings = array_pull($postData, 'settings');
foreach ($settings as $settingName => $settingValue) {
Setting::set($settingName, $settingValue);
$setting->set($settingName, $settingValue);
}
$envData = array_pull($postData, 'env');

View File

@@ -11,12 +11,12 @@
namespace CachetHQ\Cachet\Http\Controllers;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Incident;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View;
use Jenssegers\Date\Date;
@@ -47,14 +47,14 @@ class StatusPageController extends Controller
}
}
$daysToShow = Setting::get('app_incident_days', 0) - 1;
$daysToShow = Config::get('setting.app_incident_days', 0) - 1;
if ($daysToShow < 0) {
$daysToShow = 0;
$incidentDays = [];
} else {
$incidentDays = range(0, $daysToShow);
}
$dateTimeZone = Setting::get('app_timezone');
$dateTimeZone = Config::get('cachet.timezone');
$incidentVisibility = Auth::check() ? 0 : 1;

View File

@@ -16,13 +16,13 @@ use CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand;
use CachetHQ\Cachet\Bus\Commands\Subscriber\UnsubscribeSubscriberCommand;
use CachetHQ\Cachet\Bus\Commands\Subscriber\UnsubscribeSubscriptionCommand;
use CachetHQ\Cachet\Bus\Commands\Subscriber\VerifySubscriberCommand;
use CachetHQ\Cachet\Bus\Exceptions\Subscriber\AlreadySubscribedException;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Exceptions\AlreadySubscribedException;
use CachetHQ\Cachet\Models\Subscriber;
use CachetHQ\Cachet\Models\Subscription;
use GrahamCampbell\Binput\Facades\Binput;
use GrahamCampbell\Markdown\Facades\Markdown;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
@@ -43,7 +43,7 @@ class SubscribeController extends Controller
public function showSubscribe()
{
return View::make('subscribe')
->withAboutApp(Markdown::convertToHtml(Setting::get('app_about')));
->withAboutApp(Markdown::convertToHtml(Config::get('setting.app_about')));
}
/**

View File

@@ -11,9 +11,9 @@
namespace CachetHQ\Cachet\Http\Middleware;
use CachetHQ\Cachet\Facades\Setting;
use Closure;
use Exception;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect;
class ReadyForUse
@@ -29,7 +29,7 @@ class ReadyForUse
public function handle($request, Closure $next)
{
try {
if (!Setting::get('app_name')) {
if (!Config::get('setting.app_name')) {
return Redirect::to('setup');
}
} catch (Exception $e) {

View File

@@ -11,8 +11,8 @@
namespace CachetHQ\Cachet\Http\Middleware;
use CachetHQ\Cachet\Facades\Setting;
use Closure;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect;
class SetupAlreadyCompleted
@@ -27,7 +27,7 @@ class SetupAlreadyCompleted
*/
public function handle($request, Closure $next)
{
if (Setting::get('app_name')) {
if (Config::get('setting.app_name')) {
return Redirect::to('dashboard');
}

View File

@@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/
use CachetHQ\Cachet\Facades\Setting;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Request;
use Jenssegers\Date\Date;
@@ -47,7 +46,7 @@ if (!function_exists('formatted_date')) {
*/
function formatted_date($date)
{
$dateFormat = Setting::get('date_format', 'jS F Y');
$dateFormat = Config::get('setting.date_format', 'jS F Y');
return (new Date($date))->format($dateFormat);
}
@@ -61,7 +60,7 @@ if (!function_exists('subscribers_enabled')) {
*/
function subscribers_enabled()
{
$isEnabled = Setting::get('enable_subscribers', false);
$isEnabled = Config::get('setting.enable_subscribers', false);
$mailAddress = Config::get('mail.from.address', false);
$mailFrom = Config::get('mail.from.name', false);

View File

@@ -1,39 +0,0 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Presenters;
use Illuminate\Contracts\Support\Arrayable;
use McCool\LaravelAutoPresenter\BasePresenter as BaseLaravelAutoPresenter;
abstract class AbstractPresenter extends BaseLaravelAutoPresenter implements Arrayable
{
/**
* The setting repository.
*
* @var \CachetHQ\Cachet\Config\Repository
*/
protected $setting;
/**
* Create an abstract presenter instance.
*
* @param \Illuminate\Database\Eloquent\Model $resource
*
* @return void
*/
public function __construct($resource)
{
parent::__construct($resource);
$this->setting = app('setting');
}
}

View File

@@ -12,9 +12,11 @@
namespace CachetHQ\Cachet\Presenters;
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
use Illuminate\Contracts\Support\Arrayable;
use McCool\LaravelAutoPresenter\BasePresenter;
use McCool\LaravelAutoPresenter\Facades\AutoPresenter;
class ComponentGroupPresenter extends AbstractPresenter
class ComponentGroupPresenter extends BasePresenter implements Arrayable
{
use TimestampsTrait;

View File

@@ -12,8 +12,10 @@
namespace CachetHQ\Cachet\Presenters;
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
use Illuminate\Contracts\Support\Arrayable;
use McCool\LaravelAutoPresenter\BasePresenter;
class ComponentPresenter extends AbstractPresenter
class ComponentPresenter extends BasePresenter implements Arrayable
{
use TimestampsTrait;

View File

@@ -11,12 +11,14 @@
namespace CachetHQ\Cachet\Presenters;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
use GrahamCampbell\Markdown\Facades\Markdown;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Facades\Config;
use Jenssegers\Date\Date;
use McCool\LaravelAutoPresenter\BasePresenter;
class IncidentPresenter extends AbstractPresenter
class IncidentPresenter extends BasePresenter implements Arrayable
{
use TimestampsTrait;
@@ -38,7 +40,7 @@ class IncidentPresenter extends AbstractPresenter
public function created_at_diff()
{
return (new Date($this->wrappedObject->created_at))
->setTimezone($this->setting->get('app_timezone'))
->setTimezone(Config::get('cachet.timezone'))
->diffForHumans();
}
@@ -50,8 +52,8 @@ class IncidentPresenter extends AbstractPresenter
public function created_at_formatted()
{
return ucfirst((new Date($this->wrappedObject->created_at))
->setTimezone($this->setting->get('app_timezone'))
->format($this->setting->get('incident_date_format', 'l jS F Y H:i:s')));
->setTimezone(Config::get('cachet.timezone'))
->format(Config::get('setting.incident_date_format', 'l jS F Y H:i:s')));
}
/**
@@ -61,7 +63,7 @@ class IncidentPresenter extends AbstractPresenter
*/
public function created_at_datetimepicker()
{
return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->format('d/m/Y H:i');
return $this->wrappedObject->created_at->setTimezone(Config::get('cachet.timezone'))->format('d/m/Y H:i');
}
/**
@@ -71,7 +73,7 @@ class IncidentPresenter extends AbstractPresenter
*/
public function created_at_iso()
{
return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->toISO8601String();
return $this->wrappedObject->created_at->setTimezone(Config::get('cachet.timezone'))->toISO8601String();
}
/**
@@ -82,7 +84,7 @@ class IncidentPresenter extends AbstractPresenter
public function scheduled_at()
{
return (new Date($this->wrappedObject->scheduled_at))
->setTimezone($this->setting->get('app_timezone'))->toDateTimeString();
->setTimezone(Config::get('cachet.timezone'))->toDateTimeString();
}
/**
@@ -93,7 +95,7 @@ class IncidentPresenter extends AbstractPresenter
public function scheduled_at_diff()
{
return (new Date($this->wrappedObject->scheduled_at))
->setTimezone($this->setting->get('app_timezone'))
->setTimezone(Config::get('cachet.timezone'))
->diffForHumans();
}
@@ -105,8 +107,8 @@ class IncidentPresenter extends AbstractPresenter
public function scheduled_at_formatted()
{
return ucfirst((new Date($this->wrappedObject->scheduled_at))
->setTimezone($this->setting->get('app_timezone'))
->format($this->setting->get('incident_date_format', 'l jS F Y H:i:s')));
->setTimezone(Config::get('cachet.timezone'))
->format(Config::get('setting.incident_date_format', 'l jS F Y H:i:s')));
}
/**
@@ -116,7 +118,7 @@ class IncidentPresenter extends AbstractPresenter
*/
public function scheduled_at_iso()
{
return $this->wrappedObject->scheduled_at->setTimezone($this->setting->get('app_timezone'))->toISO8601String();
return $this->wrappedObject->scheduled_at->setTimezone(Config::get('cachet.timezone'))->toISO8601String();
}
/**
@@ -126,7 +128,7 @@ class IncidentPresenter extends AbstractPresenter
*/
public function scheduled_at_datetimepicker()
{
return $this->wrappedObject->scheduled_at->setTimezone($this->setting->get('app_timezone'))->format('d/m/Y H:i');
return $this->wrappedObject->scheduled_at->setTimezone(Config::get('cachet.timezone'))->format('d/m/Y H:i');
}
/**

View File

@@ -12,8 +12,10 @@
namespace CachetHQ\Cachet\Presenters;
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
use Illuminate\Contracts\Support\Arrayable;
use McCool\LaravelAutoPresenter\BasePresenter;
class MetricPointPresenter extends AbstractPresenter
class MetricPointPresenter extends BasePresenter implements Arrayable
{
use TimestampsTrait;

View File

@@ -12,8 +12,10 @@
namespace CachetHQ\Cachet\Presenters;
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
use Illuminate\Contracts\Support\Arrayable;
use McCool\LaravelAutoPresenter\BasePresenter;
class MetricPresenter extends AbstractPresenter
class MetricPresenter extends BasePresenter implements Arrayable
{
use TimestampsTrait;

View File

@@ -12,9 +12,12 @@
namespace CachetHQ\Cachet\Presenters;
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Facades\Config;
use Jenssegers\Date\Date;
use McCool\LaravelAutoPresenter\BasePresenter;
class SubscriberPresenter extends AbstractPresenter
class SubscriberPresenter extends BasePresenter implements Arrayable
{
use TimestampsTrait;
@@ -26,7 +29,7 @@ class SubscriberPresenter extends AbstractPresenter
public function verified_at()
{
return (new Date($this->wrappedObject->verified_at))
->setTimezone($this->setting->get('app_timezone'))->toDateTimeString();
->setTimezone(Config::get('cachet.timezone'))->toDateTimeString();
}
/**

View File

@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Presenters\Traits;
use Illuminate\Support\Facades\Config;
use Jenssegers\Date\Date;
trait TimestampsTrait
@@ -23,7 +24,7 @@ trait TimestampsTrait
public function created_at()
{
return (new Date($this->wrappedObject->created_at))
->setTimezone($this->setting->get('app_timezone'))->toDateTimeString();
->setTimezone(Config::get('cachet.timezone'))->toDateTimeString();
}
/**
@@ -34,7 +35,7 @@ trait TimestampsTrait
public function updated_at()
{
return (new Date($this->wrappedObject->updated_at))
->setTimezone($this->setting->get('app_timezone'))->toDateTimeString();
->setTimezone(Config::get('cachet.timezone'))->toDateTimeString();
}
/**
@@ -45,6 +46,6 @@ trait TimestampsTrait
public function deleted_at()
{
return (new Date($this->wrappedObject->deleted_at))
->setTimezone($this->setting->get('app_timezone'))->toDateTimeString();
->setTimezone(Config::get('cachet.timezone'))->toDateTimeString();
}
}

View File

@@ -11,9 +11,9 @@
namespace CachetHQ\Cachet\Repositories\Metric;
use CachetHQ\Cachet\Facades\Setting as SettingFacade;
use CachetHQ\Cachet\Models\Metric;
use DateInterval;
use Illuminate\Support\Facades\Config;
use Jenssegers\Date\Date;
class MetricRepository
@@ -40,7 +40,7 @@ class MetricRepository
public function __construct(MetricInterface $repository)
{
$this->repository = $repository;
$this->dateTimeZone = SettingFacade::get('app_timezone');
$this->dateTimeZone = Config::get('cachet.timezone');
}
/**

View File

@@ -11,9 +11,9 @@
namespace CachetHQ\Cachet\Repositories\Metric;
use CachetHQ\Cachet\Facades\Setting as SettingFacade;
use CachetHQ\Cachet\Models\Metric;
use DateInterval;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Jenssegers\Date\Date;
@@ -33,7 +33,7 @@ class MySqlRepository implements MetricInterface
*/
public function __construct()
{
$this->dateTimeZone = SettingFacade::get('app_timezone');
$this->dateTimeZone = Config::get('cachet.timezone');
}
/**

View File

@@ -11,9 +11,9 @@
namespace CachetHQ\Cachet\Repositories\Metric;
use CachetHQ\Cachet\Facades\Setting as SettingFacade;
use CachetHQ\Cachet\Models\Metric;
use DateInterval;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Jenssegers\Date\Date;
@@ -33,7 +33,7 @@ class PgSqlRepository implements MetricInterface
*/
public function __construct()
{
$this->dateTimeZone = SettingFacade::get('app_timezone');
$this->dateTimeZone = Config::get('cachet.timezone');
}
/**

View File

@@ -11,9 +11,9 @@
namespace CachetHQ\Cachet\Repositories\Metric;
use CachetHQ\Cachet\Facades\Setting as SettingFacade;
use CachetHQ\Cachet\Models\Metric;
use DateInterval;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Jenssegers\Date\Date;
@@ -33,7 +33,7 @@ class SqliteRepository implements MetricInterface
*/
public function __construct()
{
$this->dateTimeZone = SettingFacade::get('app_timezone');
$this->dateTimeZone = Config::get('cachet.timezone');
}
/**

View File

@@ -232,7 +232,6 @@ return [
'View' => 'Illuminate\Support\Facades\View',
'Binput' => 'GrahamCampbell\Binput\Facades\Binput',
'Setting' => 'CachetHQ\Cachet\Facades\Setting',
'Str' => 'Illuminate\Support\Str',
],

View File

@@ -47,7 +47,7 @@
<div class="col-xs-12">
<div class="form-group">
<label>{{ trans('forms.settings.app-setup.days-of-incidents') }}</label>
<input type="number" max="100" name="app_incident_days" class="form-control" value="{{ Setting::get('app_incident_days', 7) }}">
<input type="number" max="100" name="app_incident_days" class="form-control" value="{{ Config::get('setting.app_incident_days', 7) }}">
</div>
</div>
</div>
@@ -56,7 +56,7 @@
<div class="checkbox">
<label>
<input type="hidden" value="0" name="enable_subscribers">
<input type="checkbox" value="1" name="enable_subscribers" {{ Setting::get('enable_subscribers') ? 'checked' : null }}>
<input type="checkbox" value="1" name="enable_subscribers" {{ Config::get('setting.enable_subscribers') ? 'checked' : null }}>
{{ trans('forms.settings.app-setup.subscribers') }}
</label>
</div>

View File

@@ -26,7 +26,7 @@
@foreach($timezones as $region => $list)
<optgroup label="{{ $region }}">
@foreach($list as $timezone => $name)
<option value="{{ $timezone }}" @if(Setting::get('app_timezone') == $timezone) selected @endif>
<option value="{{ $timezone }}" @if(Config::get('cachet.timezone') == $timezone) selected @endif>
{{ $name }}
</option>
@endforeach
@@ -43,7 +43,7 @@
{{ trans('forms.settings.localization.date-format') }}
<a href="http://php.net/manual/en/function.date.php" target="_blank"><i class="icon ion-help-circled"></i></a>
</label>
<input type="text" class="form-control" name="date_format" value="{{ Setting::get('date_format') ?: 'l jS F Y' }}">
<input type="text" class="form-control" name="date_format" value="{{ Config::get('setting.date_format') ?: 'l jS F Y' }}">
</div>
</div>
</div>
@@ -54,7 +54,7 @@
{{ trans('forms.settings.localization.incident-date-format') }}
<a href="http://php.net/manual/en/function.date.php" target="_blank"><i class="icon ion-help-circled"></i></a>
</label>
<input type="text" class="form-control" name="incident_date_format" value="{{ Setting::get('incident_date_format') ?: 'l jS F Y H:i:s' }}">
<input type="text" class="form-control" name="incident_date_format" value="{{ Config::get('setting.incident_date_format') ?: 'l jS F Y H:i:s' }}">
</div>
</div>
</div>

View File

@@ -21,7 +21,7 @@
<div class="col-xs-12">
<div class="form-group">
<label>{{ trans('forms.settings.security.allowed-domains') }}</label>
<textarea class="form-control" name="allowed_domains" rows="5" placeholder="http://cachet.io, http://cachet.herokuapp.com">{{ Setting::get('allowed_domains') }}</textarea>
<textarea class="form-control" name="allowed_domains" rows="5" placeholder="http://cachet.io, http://cachet.herokuapp.com">{{ Config::get('setting.allowed_domains') }}</textarea>
<div class="help-block">
{{ trans('forms.settings.security.allowed-domains-help') }}
</div>

View File

@@ -21,7 +21,7 @@
<div class="col-xs-12">
<div class="form-group">
<label>{{ trans('forms.settings.stylesheet.custom-css') }}</label>
<textarea class="form-control autosize" name="stylesheet" rows="10">{{ Setting::get('stylesheet') }}</textarea>
<textarea class="form-control autosize" name="stylesheet" rows="10">{{ Config::get('setting.stylesheet') }}</textarea>
</div>
</div>
</div>

View File

@@ -136,7 +136,7 @@
<div class="checkbox">
<label>
<input type="hidden" name="dashboard_login_link" value="0">
<input type="checkbox" value="1" name="dashboard_login_link" {{ Setting::get('dashboard_login_link') ? 'checked' : null }}>
<input type="checkbox" value="1" name="dashboard_login_link" {{ Config::get('setting.dashboard_login_link') ? 'checked' : null }}>
{{ trans('forms.settings.theme.dashboard-login') }}
</label>
</div>

View File

@@ -8,7 +8,7 @@
</div>
<div class="col-sm-7">
<ul class="list-inline">
@if($current_user || Setting::get('dashboard_login_link'))
@if($current_user || Config::get('setting.dashboard_login_link'))
<li>
<a class="btn btn-link" href="/dashboard">{{ trans('dashboard.dashboard') }}</a>
</li>

View File

@@ -88,16 +88,15 @@ class MetricPointTest extends AbstractApiTestCase
$timezone = 'America/Mexico_City';
$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$timestamp = Carbon::now()->timezone($timezone)->timestamp;
$datetime = Carbon::now()->toDateTimeString();
$datetime = Carbon::now()->timezone($timezone);
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->make([
'metric_id' => $metric->id,
]);
$postData = $metricPoint->toArray();
$postData['timestamp'] = $timestamp;
$postData['timestamp'] = $datetime->timestamp;
$this->post("/api/v1/metrics/{$metric->id}/points", $postData, ['Time-Zone' => $timezone]);
$this->seeJson(['value' => $metricPoint->value, 'created_at' => $datetime]);
$this->seeJson(['value' => $metricPoint->value, 'created_at' => $datetime->toDateTimeString()]);
}
public function testPutMetricPoint()