Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RES-1929 Crystallise timezone on past events #686

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions app/Console/Commands/CrystalliseEventTimezone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Console\Commands;

use App\Party;
use App\Services\DiscourseService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class CrystalliseEventTimezone extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'event:timezones';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Set timezone on past events';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct(DiscourseService $discourseService)
{
parent::__construct();
$this->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();
}
}
}
2 changes: 2 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/Events/TimezoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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']);
}
}