mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-05-25 02:34:17 +00:00
Fixed fetching new external resources on BIND
This commit is contained in:
parent
e913676660
commit
96a5a31203
@ -28,7 +28,7 @@ $bad_events = null;
|
||||
/**
|
||||
* A regex which will match most reasonable timezones acceptable to PostgreSQL.
|
||||
*/
|
||||
$tz_regex = ':^(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Brazil|Canada|Chile|Etc|Europe|Indian|Mexico|Mideast|Pacific|US)/[a-z_]+$:i';
|
||||
$GLOBALS['tz_regex'] = ':^(Africa|America|Antarctica|Arctic|Asia|Atlantic|Australia|Brazil|Canada|Chile|Etc|Europe|Indian|Mexico|Mideast|Pacific|US)/[a-z_]+$:i';
|
||||
|
||||
/**
|
||||
* This function launches an error
|
||||
|
||||
@ -22,9 +22,9 @@ function create_external ( $path,$is_calendar,$is_addressbook )
|
||||
if ($is_calendar) $resourcetypes .= '<urn:ietf:params:xml:ns:caldav:calendar/>';
|
||||
$qry = new AwlQuery();
|
||||
if ( ! $qry->QDo( 'INSERT INTO collection ( user_no, parent_container, dav_name, dav_etag, dav_displayname,
|
||||
is_calendar, is_addressbook, resourcetypes, created, modified )
|
||||
is_calendar, is_addressbook, resourcetypes, created )
|
||||
VALUES( :user_no, :parent_container, :dav_name, :dav_etag, :dav_displayname,
|
||||
:is_calendar, :is_addressbook, :resourcetypes, current_timestamp, current_timestamp )',
|
||||
:is_calendar, :is_addressbook, :resourcetypes, current_timestamp )',
|
||||
array(
|
||||
':user_no' => $request->user_no,
|
||||
':parent_container' => '/.external/',
|
||||
@ -55,43 +55,48 @@ function fetch_external ( $bind_id, $min_age = '1 hour' )
|
||||
$sql .= ' ORDER BY modified DESC LIMIT 1';
|
||||
$qry = new AwlQuery( $sql, $params );
|
||||
if ( $qry->Exec('DAVResource') && $qry->rows() > 0 && $row = $qry->Fetch() ) {
|
||||
$local_ts = new DateTime($row->modified);
|
||||
$curl = curl_init ( $row->external_url );
|
||||
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt ( $curl, CURLOPT_HEADER, true );
|
||||
curl_setopt ( $curl, CURLOPT_FILETIME, true );
|
||||
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'] . ' < ' . $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 ) );
|
||||
$qry->Exec('DAVResource');
|
||||
return true;
|
||||
if ( $row->modified ) {
|
||||
$local_ts = new DateTime($row->modified);
|
||||
curl_setopt ( $curl, CURLOPT_HEADER, true );
|
||||
curl_setopt ( $curl, CURLOPT_FILETIME, true );
|
||||
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']) && $info['filetime'] != -1 && new DateTime("@" . $info['filetime']) <= $local_ts )) {
|
||||
dbg_error_log("external", "external resource unchanged " . $info['filetime'] . ' < ' . $local_ts->getTimestamp() . ' (' . $info['http_code'] . ')');
|
||||
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;
|
||||
}
|
||||
dbg_error_log("external", "external resource changed, re importing" . $info['filetime'] );
|
||||
}
|
||||
else {
|
||||
dbg_error_log("external", "fetching external resource for the first time " . $row->external_url );
|
||||
}
|
||||
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 ) {
|
||||
// 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');
|
||||
// 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');
|
||||
require_once ( 'caldav-PUT-functions.php');
|
||||
import_collection ( $ics , $row->user_no, $row->path, 'External Fetch' , false ) ;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
dbg_error_log("external", "external resource up to date or not found id(%s)", $bind_id );
|
||||
}
|
||||
}
|
||||
else {
|
||||
dbg_error_log("external", "external resource up to date or not found id(%s)", $bind_id );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user