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
Owner
|
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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.This change sets the backend before both
syncUser()calls, built the same way as inSyncBirthdayCalendars. Since that goes throughObjectManager::getConnection(), I addedgetConnectionto the controller's entry inpsalm-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 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. Without the change to the controller, both fail withCall to a member function createCalendarObject() on null.vendor/bin/phpunit --process-isolationon PHP 8.5 with SQLite (Docker,composer:2image): 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-fixerdry run: 0 of 130 files to fix.