Skip to content

Commit 7e6eb94

Browse files
committed
fix(CalDAV/Backend/PDO): bind transparent as int in updateCalendar
`updateCalendar` stored the `transparent` field as a PHP boolean, which the pgsql PDO driver serializes as the empty string `''` when the value is `false`. The `transparent SMALLINT NOT NULL` column then rejects the parameter with SQLSTATE 22P02. This looks like a follow-up, 10 years later (!), of #816 :-)
1 parent fd48d44 commit 7e6eb94

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/CalDAV/Backend/PDO.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function updateCalendar($calendarId, PropPatch $propPatch)
306306
switch ($propertyName) {
307307
case '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-calendar-transp':
308308
$fieldName = 'transparent';
309-
$newValues[$fieldName] = 'transparent' === $propertyValue->getValue();
309+
$newValues[$fieldName] = 'transparent' === $propertyValue->getValue() ? 1 : 0;
310310
break;
311311
default:
312312
$fieldName = $this->propertyMap[$propertyName];

tests/Sabre/CalDAV/Backend/AbstractPDOTestCase.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ public function testUpdateCalendarAndFetch()
123123
self::assertArrayHasKey($name, $calendars[0]);
124124
self::assertEquals($value, $calendars[0][$name]);
125125
}
126+
127+
// Round-trip the other direction. Regression: prior to the fix,
128+
// the pgsql PDO driver rejected this with
129+
// SQLSTATE[22P02]: invalid input syntax for type smallint: ""
130+
// because updateCalendar bound a PHP bool (false) instead of int 0.
131+
$propPatch = new PropPatch([
132+
'{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('opaque'),
133+
]);
134+
$backend->updateCalendar($newId, $propPatch);
135+
self::assertTrue($propPatch->commit());
136+
137+
$calendars = $backend->getCalendarsForUser('principals/user2');
138+
self::assertEquals(
139+
new CalDAV\Xml\Property\ScheduleCalendarTransp('opaque'),
140+
$calendars[0]['{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp']
141+
);
126142
}
127143

128144
/**

0 commit comments

Comments
 (0)