fix(dav): add a new config key to check to retrigger regenerating birthday calendars

So that birthday calendars are immediately updated and we don't need to wait for user to change a
card or disable/enable the calendar. We reuse the existing RegenerateBirthdayCalendars repair step
instead of adding a new one.

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2023-10-02 16:27:10 +02:00
parent 8939a2edcd
commit 4451809b30
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 46 additions and 53 deletions

View file

@ -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
*
@ -30,36 +31,22 @@ use OCP\Migration\IOutput;
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') {
$output->info('Repair step already executed');
return;
}
@ -69,5 +56,6 @@ class RegenerateBirthdayCalendars implements IRepairStep {
// 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');
}
}

View file

@ -31,18 +31,17 @@ use OCA\DAV\Migration\RegenerateBirthdayCalendars;
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();
@ -61,41 +60,47 @@ class RegenerateBirthdayCalendarsTest extends TestCase {
);
}
public function testRun(): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('dav', 'regeneratedBirthdayCalendarsForYearFix')
->willReturn(null);
$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');
$this->migration->run($output);
public function dataForTestRun(): array {
return [
['', '', true],
['yes', '', true],
['yes', 'yes', false]
];
}
public function testRunSecondTime(): void {
$this->config->expects($this->once())
/**
* @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('yes');
->withConsecutive(['dav', 'regeneratedBirthdayCalendarsForYearFix'], ['dav', 'regeneratedBirthdayCalendarsForAlarmFix'])
->willReturnOnConsecutiveCalls($yearFix, $alarmFix);
$output = $this->createMock(IOutput::class);
$output->expects($this->once())
->method('info')
->with('Repair step already executed');
$this->jobList->expects($this->never())
->method('add');
if ($run) {
$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->exactly(2))
->method('setAppValue')
->withConsecutive(['dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes'], ['dav', 'regeneratedBirthdayCalendarsForAlarmFix', 'yes']);
} else {
$output->expects($this->once())
->method('info')
->with('Repair step already executed');
$this->jobList->expects($this->never())
->method('add');
$this->config->expects($this->never())->method('setAppValue');
}
$this->migration->run($output);
}