Merge pull request #1025 from cachethq/cachet-timezone
[WIP] Cachet timezone
This commit is contained in:
@@ -13,7 +13,6 @@ namespace CachetHQ\Cachet\Handlers\Commands\Incident;
|
|||||||
|
|
||||||
use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand;
|
use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand;
|
||||||
use CachetHQ\Cachet\Events\Incident\IncidentWasReportedEvent;
|
use CachetHQ\Cachet\Events\Incident\IncidentWasReportedEvent;
|
||||||
use CachetHQ\Cachet\Facades\Setting;
|
|
||||||
use CachetHQ\Cachet\Models\Component;
|
use CachetHQ\Cachet\Models\Component;
|
||||||
use CachetHQ\Cachet\Models\Incident;
|
use CachetHQ\Cachet\Models\Incident;
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
@@ -40,7 +39,7 @@ class ReportIncidentCommandHandler
|
|||||||
|
|
||||||
// The incident occurred at a different time.
|
// The incident occurred at a different time.
|
||||||
if ($command->incident_date) {
|
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([
|
$incident->update([
|
||||||
'created_at' => $incidentDate,
|
'created_at' => $incidentDate,
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ namespace CachetHQ\Cachet\Handlers\Commands\Incident;
|
|||||||
|
|
||||||
use CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand;
|
use CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand;
|
||||||
use CachetHQ\Cachet\Events\Incident\MaintenanceWasScheduledEvent;
|
use CachetHQ\Cachet\Events\Incident\MaintenanceWasScheduledEvent;
|
||||||
use CachetHQ\Cachet\Facades\Setting;
|
|
||||||
use CachetHQ\Cachet\Models\Incident;
|
use CachetHQ\Cachet\Models\Incident;
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
use Jenssegers\Date\Date;
|
use Jenssegers\Date\Date;
|
||||||
@@ -30,7 +29,7 @@ class ReportMaintenanceCommandHandler
|
|||||||
public function handle(ReportMaintenanceCommand $command)
|
public function handle(ReportMaintenanceCommand $command)
|
||||||
{
|
{
|
||||||
// TODO: Add validation to scheduledAt
|
// 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'));
|
->setTimezone(Config::get('app.timezone'));
|
||||||
|
|
||||||
$maintenanceEvent = Incident::create([
|
$maintenanceEvent = Incident::create([
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ namespace CachetHQ\Cachet\Handlers\Commands\Incident;
|
|||||||
|
|
||||||
use CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand;
|
use CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand;
|
||||||
use CachetHQ\Cachet\Events\Incident\IncidentWasUpdatedEvent;
|
use CachetHQ\Cachet\Events\Incident\IncidentWasUpdatedEvent;
|
||||||
use CachetHQ\Cachet\Facades\Setting;
|
|
||||||
use CachetHQ\Cachet\Models\Component;
|
use CachetHQ\Cachet\Models\Component;
|
||||||
use CachetHQ\Cachet\Models\Incident;
|
use CachetHQ\Cachet\Models\Incident;
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
@@ -35,7 +34,7 @@ class UpdateIncidentCommandHandler
|
|||||||
|
|
||||||
// The incident occurred at a different time.
|
// The incident occurred at a different time.
|
||||||
if ($command->incident_date) {
|
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([
|
$incident->update([
|
||||||
'created_at' => $incidentDate,
|
'created_at' => $incidentDate,
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ namespace CachetHQ\Cachet\Http\Controllers\Dashboard;
|
|||||||
|
|
||||||
use AltThree\Validator\ValidationException;
|
use AltThree\Validator\ValidationException;
|
||||||
use CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand;
|
use CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand;
|
||||||
use CachetHQ\Cachet\Facades\Setting;
|
|
||||||
use CachetHQ\Cachet\Models\Incident;
|
use CachetHQ\Cachet\Models\Incident;
|
||||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||||
use GrahamCampbell\Binput\Facades\Binput;
|
use GrahamCampbell\Binput\Facades\Binput;
|
||||||
@@ -140,7 +139,7 @@ class ScheduleController extends Controller
|
|||||||
{
|
{
|
||||||
$scheduleData = Binput::get('incident');
|
$scheduleData = Binput::get('incident');
|
||||||
// Parse the schedule date.
|
// 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'));
|
->setTimezone(Config::get('app.timezone'));
|
||||||
|
|
||||||
if ($scheduledAt->isPast()) {
|
if ($scheduledAt->isPast()) {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class Kernel extends HttpKernel
|
|||||||
'csrf' => 'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken',
|
'csrf' => 'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken',
|
||||||
'guest' => 'CachetHQ\Cachet\Http\Middleware\RedirectIfAuthenticated',
|
'guest' => 'CachetHQ\Cachet\Http\Middleware\RedirectIfAuthenticated',
|
||||||
'localize' => 'CachetHQ\Cachet\Http\Middleware\Localize',
|
'localize' => 'CachetHQ\Cachet\Http\Middleware\Localize',
|
||||||
|
'timezone' => 'CachetHQ\Cachet\Http\Middleware\Timezone',
|
||||||
'throttling' => 'GrahamCampbell\Throttle\Http\Middleware\ThrottleMiddleware',
|
'throttling' => 'GrahamCampbell\Throttle\Http\Middleware\ThrottleMiddleware',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?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\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
class Timezone
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @param string $type
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
if ($tz = $request->header('Time-Zone')) {
|
||||||
|
app('config')->set('cachet.timezone', $tz);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ class ApiRoutes
|
|||||||
$router->group([
|
$router->group([
|
||||||
'namespace' => 'Api',
|
'namespace' => 'Api',
|
||||||
'prefix' => 'api/v1',
|
'prefix' => 'api/v1',
|
||||||
'middleware' => 'accept:application/json',
|
'middleware' => ['accept:application/json', 'timezone'],
|
||||||
], function ($router) {
|
], function ($router) {
|
||||||
// General
|
// General
|
||||||
$router->get('ping', 'GeneralController@ping');
|
$router->get('ping', 'GeneralController@ping');
|
||||||
|
|||||||
@@ -26,12 +26,13 @@ class ConfigServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
$appDomain = $appLocale = null;
|
$appDomain = $appLocale = $appTimezone = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get app custom configuration.
|
// Get app custom configuration.
|
||||||
$appDomain = Setting::get('app_domain');
|
$appDomain = Setting::get('app_domain');
|
||||||
$appLocale = Setting::get('app_locale');
|
$appLocale = Setting::get('app_locale');
|
||||||
|
$appTimezone = Setting::get('app_timezone');
|
||||||
|
|
||||||
// Setup Cors.
|
// Setup Cors.
|
||||||
$allowedOrigins = $this->app->config->get('cors.defaults.allowedOrigins');
|
$allowedOrigins = $this->app->config->get('cors.defaults.allowedOrigins');
|
||||||
@@ -55,6 +56,7 @@ class ConfigServiceProvider extends ServiceProvider
|
|||||||
// Override default app values.
|
// Override default app values.
|
||||||
$this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url'));
|
$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('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.
|
// Set custom lang.
|
||||||
$this->app->translator->setLocale($appLocale);
|
$this->app->translator->setLocale($appLocale);
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Cachet Timezone
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The timezone Cachet uses for converting timezones on saving.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'timezone' => 'UTC',
|
||||||
|
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user