Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursisve events expansion returns error 500 #695

Closed
deboutv opened this issue Jun 18, 2017 · 6 comments
Closed

Recursisve events expansion returns error 500 #695

deboutv opened this issue Jun 18, 2017 · 6 comments

Comments

@deboutv
Copy link

deboutv commented Jun 18, 2017

The following request without expand is working fine.
REPORT /cal.php/calendars/user/default/ HTTP/1.1
...

<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<D:getetag />
<C:calendar-data />
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:prop-filter name="CATEGORIES"><C:text-match match-type="equals">Birthday</C:text-match></C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>

The following request with expand returns an 500 error.
REPORT /cal.php/calendars/user/default/ HTTP/1.1
...

<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<D:getetag />
<C:calendar-data>
<C:expand start="20170618T000000Z" end="20170620T000000Z" />
</C:calendar-data>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:prop-filter name="CATEGORIES"><C:text-match match-type="equals">Birthday</C:text-match></C:prop-filter>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>

Here is the error returned:
HTTP/1.1 500 Internal Server Error
Date: Sun, 18 Jun 2017 13:37:18 GMT
Server: Apache/2.4.18 (Ubuntu)
Set-Cookie: PHPSESSID=g93nsk5ki97o2acctvg4jlj1p1; path=/; HttpOnly
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
X-Sabre-Version: 3.1.3
Content-Length: 274
Connection: close
Content-Type: application/xml; charset=utf-8

<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
<s:sabredav-version>3.1.3</s:sabredav-version>
<s:exception>Sabre\VObject\EofException</s:exception>
<s:message>End of document reached prematurely</s:message>
</d:error>

Older version of baikal was working fine.

@evert
Copy link
Member

evert commented Jun 18, 2017

Newer sabre/vobject versions (the lib that parses icalendar) have become more strict in terms of what kind of data they accept. In the past it ignored a lot of problems that it shouldn't have.

The issue in this case is that you have a broken iCalendar object in your database. vobject tries to parse it to expand it, but can't because the object is invalid. If you can find out in your db which the broken iCalendar object might be, deleting it will solve this problem. It's not a very easy solution, I know...

@lbeziaud
Copy link

@evert I just tried the second query on an empty calendar (thus without any "broken ICalendar object") and the result is still an error 500.

This also seems to affect the ics-export plugin when the expand=1 option is passed.

I assume free-busy-query are using expand too (?). If it is the case then #697 might be linked to this issue.

@deboutv
Copy link
Author

deboutv commented Jun 2, 2018

@lbeziaud I have setup UTC as timezone for the calendar but it does not help that much as I have now another error.

<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
<s:sabredav-version>3.1.3</s:sabredav-version>
<s:exception>Sabre\VObject\ParseException</s:exception>
<s:message>This parser only supports VCARD and VCALENDAR files (UTC)</s:message>
</d:error>

In bold, I have added some debug information to help.

switch (strtoupper($line)) {
case 'BEGIN:VCALENDAR' :
$class = VCalendar::$componentMap['VCALENDAR'];
break;
case 'BEGIN:VCARD' :
$class = VCard::$componentMap['VCARD'];
break;
default :
throw new ParseException('This parser only supports VCARD and VCALENDAR files (' . strtoupper($line) . ')');
}

@deboutv
Copy link
Author

deboutv commented Jun 2, 2018

Well, I got it! I have made the same kind of patch as described in #697 (added bold code)

function calendarQueryReport($report) {

    $path = $this->server->getRequestUri();

    $needsJson = $report->contentType === 'application/calendar+json';

    $node = $this->server->tree->getNodeForPath($this->server->getRequestUri());
    $depth = $this->server->getHTTPDepth(0);

    // The default result is an empty array
    $result = [];

    $calendarTimeZone = null;
    if ($report->expand) {
        // We're expanding, and for that we need to figure out the
        // calendar's timezone.
        $tzProp = '{' . self::NS_CALDAV . '}calendar-timezone';
        $tzResult = $this->server->getProperties($path, [$tzProp]);
        if (isset($tzResult[$tzProp]) **&& !empty($tzResult[$tzProp])**) {
            // This property contains a VCALENDAR with a single
            // VTIMEZONE.
            $vtimezoneObj = VObject\Reader::read($tzResult[$tzProp]);
            $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();

            // Destroy circular references so PHP will garbage collect the
            // object.
            $vtimezoneObj->destroy();
        } else {
            // Defaulting to UTC.
            $calendarTimeZone = new DateTimeZone('UTC');
        }
    }

@fr0z3nfyr
Copy link

@deboutv That will at least make the export work but the problem is that the events will now all be in UTC timezone which is probably not not one would want.

@evert
Copy link
Member

evert commented Apr 27, 2019

The problem is that the underlying iCalendar data needs to be repaired for sabre/vobject to start accepting it. This is unfortunate. Sabre/dav does come with a repair script in /vendor/bin/vobject but it repairs files not the database directly :(

anyway let me know if you need help for this. I'm closing this ticket for now for housekeeping but opening it up again is super easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants