Skip to content

Set the birthday calendar backend in the admin address book actions - #329

Open
0z5a wants to merge 1 commit into
tchapi:mainfrom
0z5a:fix-328-birthday-backend
Open

0z5a wants to merge 1 commit into
tchapi:mainfrom
0z5a:fix-328-birthday-backend

Conversation

@0z5a

@0z5a 0z5a commented Nov 19, 2026

Copy link
Copy Markdown

Fixes #328.

I started from #328 and checked it against the code. BirthdayService writes the birthday events through $calendarBackend, which is only set by setBackend(). The DAV server sets it through BirthdayCalendarPlugin, and dav:sync-birthday-calendar sets it in its constructor, but AddressBookController calls syncUser() after saving and after deleting an address book without setting it. As soon as an included address book has a contact with a BDAY, updateCalendar() calls createCalendarObject() on null and the admin returns a 500. The address book itself is already saved at that point, but the birthday calendar is not updated.

This change sets the backend before both syncUser() calls, built the same way as in SyncBirthdayCalendars. Since that goes through ObjectManager::getConnection(), I added getConnection to the controller's entry in psalm-baseline.xml, as it is for the command.

How I found it

I followed the stack trace from the issue to BirthdayService::updateCalendar() and looked for every setBackend() call. The existing testTheBirthdayCalendarFlagIsSaved turns the flag on too, but the test user's address book has no cards, so updateCalendar() is never reached. With one card that has a birthday, the same form submission gives the 500.

Where this can show up in practice

Anyone who uses the admin dashboard to turn on "Include in birthday calendar" for an address book that already has contacts with birthdays, which is the usual case for that option. Deleting another address book of the same user from the admin hits the same error. The birthday calendar then stays as it was until a card is changed over CardDAV or the sync command is run. This is my estimate beyond the report in #328.

Testing

  • Two new tests in AddressBookControllerTest: saving the address book with a birthday contact and the flag on, and deleting a second address book of the same user. Both check for the redirect and for the birthday event. Without the change to the controller, both fail with Call to a member function createCalendarObject() on null.
  • Full suite with vendor/bin/phpunit --process-isolation on PHP 8.5 with SQLite (Docker, composer:2 image): 314 tests, 0 failures, 1 skipped with the change. With only the controller change reverted, the same run has exactly the two new tests failing.
  • vendor/bin/psalm: no errors. php-cs-fixer dry run: 0 of 130 files to fix.
  • Not run: the MySQL and PostgreSQL jobs, and PHP 8.2 to 8.4 from the CI matrix.

Saving or deleting an address book from the admin syncs the user's
birthday calendar, but the birthday service only gets its CalDAV
backend from the DAV server plugin and the sync command. With a
contact that has a birthday, the sync then failed with "Call to a
member function createCalendarObject() on null" and the admin
showed a 500.

Set the backend the same way the sync command does before both
syncUser() calls.

Fixes tchapi#328
@tchapi tchapi self-assigned this Nov 20, 2026
@tchapi tchapi added the bug Something isn't working label Nov 20, 2026
@tchapi

tchapi commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks @0z5a

Rather than setting the backend in a third place, I'd rather fix it at the source I think: BirthdayService should get its backend from the container, so that no caller has to remember setBackend(). Something along these lines in config/services.yaml:

App\Services\BirthdayService:
    lazy: true # Building it opens the database connection, we don't want that
    arguments:
        # The sabre/dav backend
        $calendarBackend: !service
            class: Sabre\CalDAV\Backend\PDO
            arguments:
                - !service
                    class: PDO
                    factory: ['@doctrine.dbal.default_connection', 'getNativeConnection']
        $birthdayReminderOffset: "%birthday_reminder_offset%"

With that:

  • BirthdayService takes the backend as a constructor argument and setBackend() can be removed
  • BirthdayCalendarPlugin and SyncBirthdayCalendars no longer need to deal with the backend at all (since it's in the service)

WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Admin UI: enabling a birthday calendar for address book returns 500

2 participants