From 15f304ab1c99bd787f1c30f796aae6839728a3c8 Mon Sep 17 00:00:00 2001 From: Benedikt Spranger Date: Tue, 17 Oct 2023 02:42:10 +0200 Subject: [PATCH] Fix handling of events started before 1900 commit 15d01c8bed2d ("Store DTSTART and DTEND from user in shadow columns") breaks handling of events started before 1900: [19-Sep-2023 14:30:39 UTC] davical: BUG: :DAViCal Fatal Error: [42804] SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "dtstart_orig" is of type timestamp with time zone but expression is of type integer [19-Sep-2023 14:30:39 UTC] ================= Stack Trace =================== [19-Sep-2023 14:30:39 UTC] davical: LOG: :Response status 500 for PUT //home/6bb3a62b-43ae-4a21-bb83-fca84d9ef050.ics [19-Sep-2023 14:30:39 UTC] davical: LOG: :***************** Response Header **************** [19-Sep-2023 14:30:39 UTC] davical: LOG: headers:-->Server: 1.1 [19-Sep-2023 14:30:39 UTC] davical: LOG: headers:-->DAV: 1, 2, 3, access-control, calendar-access, calendar-schedule [19-Sep-2023 14:30:39 UTC] davical: LOG: headers:-->DAV: extended-mkcol, bind, addressbook, calendar-auto-schedule, calendar-proxy [19-Sep-2023 14:30:39 UTC] davical: LOG: headers:-->X-DAViCal-Version: DAViCal/1.1.12; DB/1.3.5 [19-Sep-2023 14:30:39 UTC] davical: LOG: headers:-->Content-type: text/plain; charset="utf-8" [19-Sep-2023 14:30:39 UTC] davical: LOG: :******************** Response ******************** [19-Sep-2023 14:30:39 UTC] davical: LOG: response:-->DAViCal Fatal Error Update dtstart_orig in these cases to avoid the database failure. Signed-off-by: Benedikt Spranger --- inc/caldav-PUT-functions.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/inc/caldav-PUT-functions.php b/inc/caldav-PUT-functions.php index 0824b244..e1e47c32 100644 --- a/inc/caldav-PUT-functions.php +++ b/inc/caldav-PUT-functions.php @@ -1482,8 +1482,10 @@ function write_resource( DAVResource $resource, $caldav_data, DAVResource $colle $calitem_params[':dtstart_orig'] = $dtstart; if ( empty($dtstart) ) $dtstart = $due; - if (isset($dtstart) && preg_match("/^1[0-8][0-9][0-9][01][0-9][0-3][0-9]$/", $dtstart)) + if (isset($dtstart) && preg_match("/^1[0-8][0-9][0-9][01][0-9][0-3][0-9]$/", $dtstart)) { $dtstart = $dtstart . "T000000Z"; + $calitem_params[':dtstart_orig'] = $dtstart; + } $calitem_params[':dtstart'] = $dtstart; $dtend = $first->GetPValue('DTEND'); @@ -1491,8 +1493,10 @@ function write_resource( DAVResource $resource, $caldav_data, DAVResource $colle if ( isset($dtend) && $dtend != '' ) { dbg_error_log( 'PUT', ' DTEND: "%s", DTSTART: "%s", DURATION: "%s"', $dtend, $dtstart, $first->GetPValue('DURATION') ); - if (preg_match("/^1[0-8][0-9][0-9][01][0-9][0-3][0-9]$/", $dtend)) + if (preg_match("/^1[0-8][0-9][0-9][01][0-9][0-3][0-9]$/", $dtend)) { $dtend = $dtend . "T000000Z"; + $calitem_params[':dtend_orig'] = $dtend; + } $calitem_params[':dtend'] = $dtend; $dtend = ':dtend'; }