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 <andrew@morphoss.com>
This commit is contained in:
Philipp Matthias Hahn 2012-01-11 23:14:25 +01:00 committed by Andrew McMillan
parent 05613124ce
commit c9467618d7

View File

@ -62,9 +62,10 @@ function fetch_external ( $bind_id, $min_age = '1 hour' )
curl_setopt ( $curl, CURLOPT_NOBODY, true ); curl_setopt ( $curl, CURLOPT_NOBODY, true );
$ics = curl_exec ( $curl ); $ics = curl_exec ( $curl );
$info = curl_getinfo ( $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'] ); dbg_error_log("external", "external resource unchanged " . $info['filetime'] );
curl_close ( $curl ); 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 = new AwlQuery( 'UPDATE collection SET modified=NOW() WHERE collection_id = :cid', array ( ':cid' => $row->collection_id ) );
$qry->Exec('DAVResource'); $qry->Exec('DAVResource');
return true; return true;
@ -74,6 +75,7 @@ function fetch_external ( $bind_id, $min_age = '1 hour' )
$ics = curl_exec ( $curl ); $ics = curl_exec ( $curl );
curl_close ( $curl ); curl_close ( $curl );
if ( is_string ( $ics ) && strlen ( $ics ) > 20 ) { 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', $qry = new AwlQuery( 'UPDATE collection SET modified=NOW(), dav_etag=:etag WHERE collection_id = :cid',
array ( ':cid' => $row->collection_id, ':etag' => md5($ics) ) ); array ( ':cid' => $row->collection_id, ':etag' => md5($ics) ) );
$qry->Exec('DAVResource'); $qry->Exec('DAVResource');