From c9467618d741fa7782dfbf6351d7f86318a68a7b Mon Sep 17 00:00:00 2001 From: Philipp Matthias Hahn Date: Wed, 11 Jan 2012 23:14:25 +0100 Subject: [PATCH] Fix remote time comparison The PostgreSQL database returns a string like "2013-01-11 18:37:36.737665+01", while curl returns the file-modification-time as a string repesenting the secondes since the UNIX epoche. Comparing them as strings us wrong. Convert them to DateTime() instances instead. And only do this when the filetime is actually returned. Signed-off-by: Andrew McMillan --- inc/external-fetch.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inc/external-fetch.php b/inc/external-fetch.php index d86483a6..49506c3a 100644 --- a/inc/external-fetch.php +++ b/inc/external-fetch.php @@ -62,9 +62,10 @@ function fetch_external ( $bind_id, $min_age = '1 hour' ) curl_setopt ( $curl, CURLOPT_NOBODY, true ); $ics = curl_exec ( $curl ); $info = curl_getinfo ( $curl ); - if ( $info['filetime'] <= $row->updated ) { + if ( isset($info['filetime']) && new DateTime("@" . $info['filetime']) <= $local_ts ) { dbg_error_log("external", "external resource unchanged " . $info['filetime'] ); curl_close ( $curl ); + // BUGlet: should track server-time instead of local-time $qry = new AwlQuery( 'UPDATE collection SET modified=NOW() WHERE collection_id = :cid', array ( ':cid' => $row->collection_id ) ); $qry->Exec('DAVResource'); return true; @@ -74,6 +75,7 @@ function fetch_external ( $bind_id, $min_age = '1 hour' ) $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', array ( ':cid' => $row->collection_id, ':etag' => md5($ics) ) ); $qry->Exec('DAVResource');