-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathCalendarCommand.php
More file actions
61 lines (48 loc) · 2.33 KB
/
Copy pathCalendarCommand.php
File metadata and controls
61 lines (48 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php declare(strict_types=1);
namespace App\Command;
use Ibexa\Contracts\Calendar;
use Ibexa\Contracts\Calendar\CalendarServiceInterface;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Scheduler\Calendar\EventAction\RescheduleEventActionContext;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
#[AsCommand(
name: 'doc:calendar',
description: 'Lists Calendar event in the provided time range and reschedules them.'
)]
class CalendarCommand extends Command
{
public function __construct(
private readonly PermissionResolver $permissionResolver,
private readonly UserService $userService,
private readonly CalendarServiceInterface $calendarService
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$user = $this->userService->loadUserByLogin('admin');
$this->permissionResolver->setCurrentUserReference($user);
$dateFrom = new \DateTimeImmutable('2023-01-01T10:00:00+00:00');
$dateTo = new \DateTimeImmutable('2023-12-31T10:0:00+00:00');
$dateRange = new Calendar\DateRange($dateFrom, $dateTo);
$eventQuery = new Calendar\EventQuery($dateRange, 10);
$eventList = $this->calendarService->getEvents($eventQuery);
foreach ($eventList as $event) {
$output->writeln($event->getName() . '; date: ' . $event->getDateTime()->format('T Y-m-d H:i:s'));
}
$eventCollection = $eventList->getEvents();
$output->writeln('First event: ' . $eventCollection->first()->getName() . '; date: ' . $eventCollection->first()->getDateTime()->format('T Y-m-d H:i:s'));
$newCollection = $eventCollection->slice(3, 5);
foreach ($newCollection as $event) {
$output->writeln('New collection: ' . $event->getName() . '; date: ' . $event->getDateTime()->format('T Y-m-d H:i:s'));
}
$newDate = new \DateTimeImmutable('2023-12-06T13:00:00+00:00');
$context = new RescheduleEventActionContext($eventCollection, $newDate);
$this->calendarService->executeAction($context);
return self::SUCCESS;
}
}