aboutsummaryrefslogtreecommitdiff
path: root/cli/Commands/Fix/EndTimeWeeklyRecurredEvents.php
blob: 40e7a2b0e0290d92c27c162c70bd83ebd0b0b489 (plain)
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
<?php

namespace Studip\Cli\Commands\Fix;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class EndTimeWeeklyRecurredEvents extends Command
{
    protected static $defaultName = 'fix:end-time-weekly-recurred-events';

    protected function configure(): void
    {
        $this->setDescription('Fix end time weekly recurred events');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);
        $events = \EventData::findBySQL("rtype = 'WEEKLY' AND IFNULL(count, 0) > 0");
        $cal_event = new \CalendarEvent();

        $i = 0;

        foreach ($events as $event) {
            $id = $event->getId();
            $cal_event->event = $event;
            $rrule = $cal_event->getRecurrence();
            $cal_event->setRecurrence($rrule);
            $event->expire = $cal_event->event->expire;
            $event->setId($id);
            $event->store();
            $i++;
        }
        $io->info('Wrong end time of recurrence fixed for ' . $i . ' events.');
        return Command::SUCCESS;
    }
}