From a288f84fc571253b6d10372984a09f3e928658c6 Mon Sep 17 00:00:00 2001 From: Joseph Cohen Date: Thu, 8 Oct 2015 16:11:30 -0500 Subject: [PATCH] Settable timezones with cachet config --- .../Incident/ReportIncidentCommandHandler.php | 2 +- .../ReportMaintenanceCommandHandler.php | 2 +- .../Incident/UpdateIncidentCommandHandler.php | 2 +- .../Dashboard/ScheduleController.php | 2 +- app/Http/Controllers/StatusPageController.php | 2 +- app/Http/Middleware/Timezone.php | 3 +-- app/Providers/ConfigServiceProvider.php | 2 ++ config/cachet.php | 24 +++++++++++++++++++ 8 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 config/cachet.php diff --git a/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php b/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php index 3d3d37e0e..4dd101e7a 100644 --- a/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php +++ b/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php @@ -40,7 +40,7 @@ class ReportIncidentCommandHandler // The incident occurred at a different time. if ($command->incident_date) { - $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone')); + $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone')); $incident->update([ 'created_at' => $incidentDate, diff --git a/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php b/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php index b9542191c..ac72df05c 100644 --- a/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php +++ b/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php @@ -30,7 +30,7 @@ class ReportMaintenanceCommandHandler public function handle(ReportMaintenanceCommand $command) { // TODO: Add validation to scheduledAt - $scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, Setting::get('app_timezone')) + $scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, config('cachet.timezone')) ->setTimezone(Config::get('app.timezone')); $maintenanceEvent = Incident::create([ diff --git a/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php b/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php index ef25992cd..09d5ed496 100644 --- a/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php +++ b/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php @@ -35,7 +35,7 @@ class UpdateIncidentCommandHandler // The incident occurred at a different time. if ($command->incident_date) { - $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone')); + $incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone')); $incident->update([ 'created_at' => $incidentDate, diff --git a/app/Http/Controllers/Dashboard/ScheduleController.php b/app/Http/Controllers/Dashboard/ScheduleController.php index 3e7f94aa8..60d4b2f3e 100644 --- a/app/Http/Controllers/Dashboard/ScheduleController.php +++ b/app/Http/Controllers/Dashboard/ScheduleController.php @@ -140,7 +140,7 @@ class ScheduleController extends Controller { $scheduleData = Binput::get('incident'); // Parse the schedule date. - $scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone')) + $scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], config('cachet.timezone')) ->setTimezone(Config::get('app.timezone')); if ($scheduledAt->isPast()) { diff --git a/app/Http/Controllers/StatusPageController.php b/app/Http/Controllers/StatusPageController.php index 231b234de..8012f7560 100644 --- a/app/Http/Controllers/StatusPageController.php +++ b/app/Http/Controllers/StatusPageController.php @@ -55,7 +55,7 @@ class StatusPageController extends Controller } else { $incidentDays = range(0, $daysToShow); } - $dateTimeZone = Setting::get('app_timezone'); + $dateTimeZone = config('cachet.timezone'); $incidentVisiblity = Auth::check() ? 0 : 1; diff --git a/app/Http/Middleware/Timezone.php b/app/Http/Middleware/Timezone.php index 2ab69d862..ad5bd11db 100644 --- a/app/Http/Middleware/Timezone.php +++ b/app/Http/Middleware/Timezone.php @@ -28,8 +28,7 @@ class Timezone public function handle($request, Closure $next) { if ($tz = $request->header('Time-Zone')) { - app('config')->set('app.timezone', $tz); - Setting::set('app_timezone', $tz); + app('config')->set('cachet.timezone', $tz); } return $next($request); diff --git a/app/Providers/ConfigServiceProvider.php b/app/Providers/ConfigServiceProvider.php index 0a25dc33c..a9e04eddd 100644 --- a/app/Providers/ConfigServiceProvider.php +++ b/app/Providers/ConfigServiceProvider.php @@ -32,6 +32,7 @@ class ConfigServiceProvider extends ServiceProvider // 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'); @@ -55,6 +56,7 @@ class ConfigServiceProvider extends ServiceProvider // 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')); // Set custom lang. $this->app->translator->setLocale($appLocale); diff --git a/config/cachet.php b/config/cachet.php new file mode 100644 index 000000000..ee7e42bb6 --- /dev/null +++ b/config/cachet.php @@ -0,0 +1,24 @@ + 'UTC', +];