From e7afaef931c3ef7888e137d89b14524879e86e41 Mon Sep 17 00:00:00 2001 From: Rob Ostensen Date: Tue, 6 Mar 2012 14:30:10 -0600 Subject: [PATCH] fix a few external BIND import bugs --- inc/external-fetch.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/inc/external-fetch.php b/inc/external-fetch.php index da687967..6417feb5 100644 --- a/inc/external-fetch.php +++ b/inc/external-fetch.php @@ -49,7 +49,7 @@ function fetch_external ( $bind_id, $min_age = '1 hour' ) $sql = 'SELECT collection.*, collection.dav_name AS path, dav_binding.external_url AS external_url FROM dav_binding LEFT JOIN collection ON (collection.collection_id=bound_source_id) WHERE bind_id = :bind_id'; $params = array( ':bind_id' => $bind_id ); if ( strlen ( $min_age ) > 2 ) { - $sql .= ' AND collection.modified + interval :interval > NOW()'; + $sql .= ' AND collection.modified + interval :interval < NOW()'; $params[':interval'] = $min_age; } $sql .= ' ORDER BY modified DESC LIMIT 1'; @@ -63,10 +63,11 @@ function fetch_external ( $bind_id, $min_age = '1 hour' ) curl_setopt ( $curl, CURLOPT_NOBODY, true ); curl_setopt ( $curl, CURLOPT_TIMEVALUE, $local_ts->format("U") ); curl_setopt ( $curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE ); + dbg_error_log("external", "checking external resource for remote changes " . $row->external_url ); $ics = curl_exec ( $curl ); $info = curl_getinfo ( $curl ); if ( $info['http_code'] === 304 || 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'] . ' < ' . $local_ts->getTimestamp() ); 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 ) ); @@ -75,6 +76,7 @@ function fetch_external ( $bind_id, $min_age = '1 hour' ) } dbg_error_log("external", "external resource changed, re importing" . $info['filetime'] ); 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 ) { @@ -88,7 +90,7 @@ function fetch_external ( $bind_id, $min_age = '1 hour' ) } } else { - dbg_error_log("external", "external resource not found"); + dbg_error_log("external", "external resource up to date or not found id(%s)", $bind_id ); } return false; } @@ -102,12 +104,12 @@ function update_external ( $request ) dbg_error_log("external", "external resource cannot be fetched without curl, please install curl"); return ; } - $sql = 'SELECT bind_id from dav_binding LEFT JOIN collection ON (collection.collection_id=bound_source_id) WHERE dav_binding.dav_name = :dav_name AND collection.modified + interval :interval < NOW()'; + $sql = 'SELECT bind_id, external_url as url from dav_binding LEFT JOIN collection ON (collection.collection_id=bound_source_id) WHERE dav_binding.dav_name = :dav_name AND collection.modified + interval :interval < NOW()'; $qry = new AwlQuery( $sql, array ( ':dav_name' => $request->dav_name(), ':interval' => $c->external_refresh . ' minutes' ) ); dbg_error_log("external", "checking if external resource needs update"); 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"); + dbg_error_log("external", "external resource needs updating, this might take a minute : %s", $row->url ); fetch_external ( $row->bind_id ); } } -- 2.11.4.GIT