Repository navigation
Conversation
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
|
Thanks @0z5a Rather than setting the backend in a third place, I'd rather fix it at the source I think: 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:
WDYT? |
The birthday service only got its CalDAV backend through setBackend(), which the DAV server plugin and the sync command called, so any other caller had to remember it. Get the backend from the container instead, as a constructor argument, and remove setBackend(). The plugin and the command no longer deal with the backend, and the admin address book actions no longer need to set it. The service is lazy: building the backend opens the database connection, and the sync command is built on every console run.
|
Agreed, that's cleaner. Done in 63a9a6e, on top of the earlier commit:
On 7.4, Tests:
The full suite passes locally on SQLite with PHP 8.6: 315 tests, 0 failures. One test was skipped, the LDAP-missing diagnostics test, because the extension is installed here. Psalm, php-cs-fixer and |
Fixes #328.
I started from #328 and checked it against the code.
BirthdayServicewrites the birthday events through$calendarBackend, which is only set bysetBackend(). The DAV server sets it throughBirthdayCalendarPlugin, anddav:sync-birthday-calendarsets it in its constructor, butAddressBookControllercallssyncUser()after saving and after deleting an address book without setting it. As soon as an included address book has a contact with aBDAY,updateCalendar()callscreateCalendarObject()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.Following review, this is fixed at the source:
BirthdayServicenow gets itsSabre\CalDAV\Backend\PDOfrom the container as a constructor argument (a lazy service, so building it does not open the database connection), andsetBackend()is removed.BirthdayCalendarPluginanddav:sync-birthday-calendarno longer deal with the backend, and no caller has to remember to set it. The first version of this PR set the backend in the admin controller instead; that is reverted.How I found it
I followed the stack trace from the issue to
BirthdayService::updateCalendar()and looked for everysetBackend()call. The existingtestTheBirthdayCalendarFlagIsSavedturns the flag on too, but the test user's address book has no cards, soupdateCalendar()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
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. Againstmainboth fail withCall to a member function createCalendarObject() on null.DavTestcase: deleting a card through the/dav/route removes its birthday event.setBackend().vendor/bin/phpunit --process-isolationon PHP 8.6 with SQLite: 315 tests, 0 failures, 1 skipped (the LDAP-missing diagnostics test, since the extension is installed locally).vendor/bin/psalm,php-cs-fixerandbin/console lint:container: clean.bin/console liststill works when the database is unreachable.