diff --git a/app/Console/Commands/CrystalliseEventTimezone.php b/app/Console/Commands/CrystalliseEventTimezone.php new file mode 100644 index 000000000..02082a936 --- /dev/null +++ b/app/Console/Commands/CrystalliseEventTimezone.php @@ -0,0 +1,51 @@ +discourseService = $discourseService; + } + + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $events = Party::past()->where('timezone', null)->get(); + + foreach ($events as $event) { + $event->timezone = $event->theGroup->timezone; + $event->save(); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 84a4a6006..473a39c6e 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -43,6 +43,8 @@ protected function schedule(Schedule $schedule) ->emailOutputTo(env('SEND_COMMAND_LOGS_TO'), 'tech@therestartproject.org'); $schedule->command('groups:country')->hourly(); + + $schedule->command('event:timezones')->hourly(); } /** diff --git a/tests/Unit/Events/TimezoneTest.php b/tests/Unit/Events/TimezoneTest.php index dc6660cdb..ab3139ebc 100644 --- a/tests/Unit/Events/TimezoneTest.php +++ b/tests/Unit/Events/TimezoneTest.php @@ -11,6 +11,9 @@ use Illuminate\Validation\ValidationException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Tests\TestCase; +use function PHPUnit\Framework\assertEquals; +use function PHPUnit\Framework\assertNull; +use Illuminate\Support\Facades\Artisan; class TimezoneTest extends TestCase { @@ -221,4 +224,25 @@ public function testTimezoneChangeUpdatesFutureEvents() { $party->refresh(); self::assertEquals('Europe/London', $party->timezone); } + + public function testCrystallise() { + // Create a past event and check that the scheduled command crystallises the timezone. + $g = Group::factory()->create([ + 'timezone' => 'Asia/Samarkand' + ]); + + $e = Party::factory()->create([ + 'group' => $g->idgroups, + 'event_start_utc' => '2021-02-01T10:15:05+05:00', + 'event_end_utc' => '2021-02-01T13:45:05+05:00', + 'timezone' => NULL + ]); + + // We want to skip the accessor for this test. + assertNull($e->getAttributes()['timezone']); + Artisan::call('event:timezones'); + + $e->refresh(); + assertEquals('Asia/Samarkand', $e->getAttributes()['timezone']); + } }