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

fix(dav): fix event birthday alarms not being updated #39977

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion apps/dav/lib/CalDAV/BirthdayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,11 @@
}

/**
* The birthday event is considered changed if either
* - the start date has changed
* - the title has changed
* - the time for the alarm has changed
*
* @param string $existingCalendarData
* @param VCalendar $newCalendarData
* @return bool
Expand All @@ -331,7 +336,8 @@

return (
$newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() ||
$newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue()
$newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue() ||

Check notice

Code scanning / Psalm

PossiblyNullPropertyFetch Note

Cannot get property on possibly null variable $newCalendarData->VEVENT of type Sabre\VObject\Property|null

Check notice

Code scanning / Psalm

UndefinedPropertyFetch Note

Instance property Sabre\VObject\Property::$SUMMARY is not defined

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getValue on possibly null value

Check notice

Code scanning / Psalm

PossiblyNullPropertyFetch Note

Cannot get property on possibly null variable $existingBirthday->VEVENT of type Sabre\VObject\Property|null

Check notice

Code scanning / Psalm

UndefinedPropertyFetch Note

Instance property Sabre\VObject\Property::$SUMMARY is not defined

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getValue on possibly null value
($newCalendarData->VEVENT->VALARM && $existingBirthday->VEVENT->VALARM && $newCalendarData->VEVENT->VALARM->TRIGGER->getValue() !== $existingBirthday->VEVENT->VALARM->TRIGGER->getValue())

Check failure on line 340 in apps/dav/lib/CalDAV/BirthdayService.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedPropertyFetch

apps/dav/lib/CalDAV/BirthdayService.php:340:5: UndefinedPropertyFetch: Instance property Sabre\VObject\Property::$VALARM is not defined (see https://psalm.dev/039)

Check failure on line 340 in apps/dav/lib/CalDAV/BirthdayService.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedPropertyFetch

apps/dav/lib/CalDAV/BirthdayService.php:340:41: UndefinedPropertyFetch: Instance property Sabre\VObject\Property::$VALARM is not defined (see https://psalm.dev/039)

Check failure

Code scanning / Psalm

UndefinedPropertyFetch Error

Instance property Sabre\VObject\Property::$VALARM is not defined

Check failure

Code scanning / Psalm

UndefinedPropertyFetch Error

Instance property Sabre\VObject\Property::$VALARM is not defined

Check notice

Code scanning / Psalm

PossiblyNullPropertyFetch Note

Cannot get property on possibly null variable $newCalendarData->VEVENT of type Sabre\VObject\Property|null

Check notice

Code scanning / Psalm

PossiblyNullPropertyFetch Note

Cannot get property on possibly null variable $existingBirthday->VEVENT of type Sabre\VObject\Property|null
);
}

Expand Down
26 changes: 7 additions & 19 deletions apps/dav/lib/Migration/RegenerateBirthdayCalendars.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Georg Ehrke <oc.list@georgehrke.com>
* @author Thomas Citharel <nextcloud@tcit.fr>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -30,36 +31,22 @@
use OCP\Migration\IRepairStep;

class RegenerateBirthdayCalendars implements IRepairStep {
private IJobList $jobList;
private IConfig $config;

/** @var IJobList */
private $jobList;

/** @var IConfig */
private $config;

/**
* @param IJobList $jobList
* @param IConfig $config
*/
public function __construct(IJobList $jobList,
IConfig $config) {
$this->jobList = $jobList;
$this->config = $config;
}

/**
* @return string
*/
public function getName() {
public function getName(): string {
return 'Regenerating birthday calendars to use new icons and fix old birthday events without year';
}

/**
* @param IOutput $output
*/
public function run(IOutput $output) {
public function run(IOutput $output): void {
// only run once
if ($this->config->getAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix') === 'yes') {
if ($this->config->getAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix') === 'yes' && $this->config->getAppValue('dav', 'regeneratedBirthdayCalendarsForAlarmFix') === 'yes') {

Check notice

Code scanning / Psalm

DeprecatedMethod Note

The method OCP\IConfig::getAppValue has been marked as deprecated

Check notice

Code scanning / Psalm

DeprecatedMethod Note

The method OCP\IConfig::getAppValue has been marked as deprecated
$output->info('Repair step already executed');
return;
}
Expand All @@ -69,5 +56,6 @@

// if all were done, no need to redo the repair during next upgrade
$this->config->setAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');
$this->config->setAppValue('dav', 'regeneratedBirthdayCalendarsForAlarmFix', 'yes');

Check notice

Code scanning / Psalm

DeprecatedMethod Note

The method OCP\IConfig::setAppValue has been marked as deprecated
}
}
69 changes: 37 additions & 32 deletions apps/dav/tests/unit/Migration/RegenerateBirthdayCalendarsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,17 @@
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\Migration\IOutput;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class RegenerateBirthdayCalendarsTest extends TestCase {

/** @var IJobList | \PHPUnit\Framework\MockObject\MockObject */
/** @var IJobList | MockObject */
private $jobList;

/** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
/** @var IConfig | MockObject */
private $config;

/** @var RegenerateBirthdayCalendars */
private $migration;
private RegenerateBirthdayCalendars $migration;

protected function setUp(): void {
parent::setUp();
Expand All @@ -61,41 +60,47 @@ public function testGetName(): void {
);
}

public function testRun(): void {
$this->config->expects($this->once())
public function dataForTestRun(): array {
return [
['', '', true],
['yes', '', true],
['yes', 'yes', false]
];
}

/**
* @dataProvider dataForTestRun
*/
public function testRun(string $yearFix, string $alarmFix, bool $run): void {
$this->config->expects($this->exactly($yearFix === '' ? 1 : 2))
->method('getAppValue')
->with('dav', 'regeneratedBirthdayCalendarsForYearFix')
->willReturn(null);
->withConsecutive(['dav', 'regeneratedBirthdayCalendarsForYearFix'], ['dav', 'regeneratedBirthdayCalendarsForAlarmFix'])
->willReturnOnConsecutiveCalls($yearFix, $alarmFix);

$output = $this->createMock(IOutput::class);
$output->expects($this->once())
->method('info')
->with('Adding background jobs to regenerate birthday calendar');

$this->jobList->expects($this->once())
->method('add')
->with(RegisterRegenerateBirthdayCalendars::class);

$this->config->expects($this->once())
->method('setAppValue')
->with('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');
if ($run) {
$output->expects($this->once())
->method('info')
->with('Adding background jobs to regenerate birthday calendar');

$this->migration->run($output);
}
$this->jobList->expects($this->once())
->method('add')
->with(RegisterRegenerateBirthdayCalendars::class);

public function testRunSecondTime(): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('dav', 'regeneratedBirthdayCalendarsForYearFix')
->willReturn('yes');
$this->config->expects($this->exactly(2))
->method('setAppValue')
->withConsecutive(['dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes'], ['dav', 'regeneratedBirthdayCalendarsForAlarmFix', 'yes']);
} else {
$output->expects($this->once())
->method('info')
->with('Repair step already executed');

$output = $this->createMock(IOutput::class);
$output->expects($this->once())
->method('info')
->with('Repair step already executed');
$this->jobList->expects($this->never())
->method('add');

$this->jobList->expects($this->never())
->method('add');
$this->config->expects($this->never())->method('setAppValue');
}

$this->migration->run($output);
}
Expand Down
Loading