From d459b489ac997c4cb52b8b3b5bd6aca296581c76 Mon Sep 17 00:00:00 2001 From: Florian Schlichting Date: Sat, 13 Jan 2018 23:41:04 +0100 Subject: [PATCH] external fetch: improve error reporting --- inc/external-fetch.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/inc/external-fetch.php b/inc/external-fetch.php index 1dc02bce..e844541d 100644 --- a/inc/external-fetch.php +++ b/inc/external-fetch.php @@ -65,7 +65,7 @@ function fetch_external ( $bind_id, $min_age = '1 hour', $ua_string ) curl_setopt ( $curl, CURLOPT_TIMEVALUE, $local_ts->format("U") ); curl_setopt ( $curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE ); if ( isset( $ua_string ) ) - curl_setopt($curl, CURLOPT_USERAGENT, $ua_string); + curl_setopt($curl, CURLOPT_USERAGENT, $ua_string); dbg_error_log("external", "checking external resource for remote changes " . $row->external_url ); $ics = curl_exec ( $curl ); $info = curl_getinfo ( $curl ); @@ -85,7 +85,6 @@ function fetch_external ( $bind_id, $min_age = '1 hour', $ua_string ) curl_setopt ( $curl, CURLOPT_NOBODY, false ); curl_setopt ( $curl, CURLOPT_HEADER, false ); $ics = curl_exec ( $curl ); - curl_close ( $curl ); if ( is_string ( $ics ) && strlen ( $ics ) > 20 ) { // BUGlet: should track server-time instead of local-time $qry = new AwlQuery( 'UPDATE collection SET modified=NOW(), dav_etag=:etag WHERE collection_id = :cid', @@ -94,7 +93,14 @@ function fetch_external ( $bind_id, $min_age = '1 hour', $ua_string ) require_once ( 'caldav-PUT-functions.php'); import_collection ( $ics , $row->user_no, $row->path, 'External Fetch' , false ) ; return true; + } else { + if ( curl_errno($curl) ) { + dbg_error_log('ERROR', 'external:Fetch of %s (%s) failed with curl error %s: %s', $row->collection_id, $row->external_url, curl_errno($curl), curl_error($curl)); + } else { + dbg_error_log('ERROR', 'external:Not importing unusual ics data: "%s"', $ics); + } } + curl_close ( $curl ); } else { dbg_error_log("external", "external resource up to date or not found id(%s)", $bind_id ); @@ -117,7 +123,7 @@ function update_external ( $request ) if ( $qry->Exec('DAVResource') && $qry->rows() > 0 && $row = $qry->Fetch() ) { if ( $row->bind_id != 0 ) { dbg_error_log("external", "external resource needs updating, this might take a minute : %s", $row->url ); - fetch_external ( $row->bind_id, $c->external_refresh . ' minutes', $c->external_ua_string ); + fetch_external ( $row->bind_id, $c->external_refresh . ' minutes', @$c->external_ua_string ); } } }