mirror of
https://gitlab.com/davical-project/davical.git
synced 2026-05-27 02:54:27 +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.
|
* 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
|
* 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/>';
|
if ($is_calendar) $resourcetypes .= '<urn:ietf:params:xml:ns:caldav:calendar/>';
|
||||||
$qry = new AwlQuery();
|
$qry = new AwlQuery();
|
||||||
if ( ! $qry->QDo( 'INSERT INTO collection ( user_no, parent_container, dav_name, dav_etag, dav_displayname,
|
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,
|
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(
|
array(
|
||||||
':user_no' => $request->user_no,
|
':user_no' => $request->user_no,
|
||||||
':parent_container' => '/.external/',
|
':parent_container' => '/.external/',
|
||||||
@ -55,43 +55,48 @@ function fetch_external ( $bind_id, $min_age = '1 hour' )
|
|||||||
$sql .= ' ORDER BY modified DESC LIMIT 1';
|
$sql .= ' ORDER BY modified DESC LIMIT 1';
|
||||||
$qry = new AwlQuery( $sql, $params );
|
$qry = new AwlQuery( $sql, $params );
|
||||||
if ( $qry->Exec('DAVResource') && $qry->rows() > 0 && $row = $qry->Fetch() ) {
|
if ( $qry->Exec('DAVResource') && $qry->rows() > 0 && $row = $qry->Fetch() ) {
|
||||||
$local_ts = new DateTime($row->modified);
|
|
||||||
$curl = curl_init ( $row->external_url );
|
$curl = curl_init ( $row->external_url );
|
||||||
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
|
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||||
curl_setopt ( $curl, CURLOPT_HEADER, true );
|
if ( $row->modified ) {
|
||||||
curl_setopt ( $curl, CURLOPT_FILETIME, true );
|
$local_ts = new DateTime($row->modified);
|
||||||
curl_setopt ( $curl, CURLOPT_NOBODY, true );
|
curl_setopt ( $curl, CURLOPT_HEADER, true );
|
||||||
curl_setopt ( $curl, CURLOPT_TIMEVALUE, $local_ts->format("U") );
|
curl_setopt ( $curl, CURLOPT_FILETIME, true );
|
||||||
curl_setopt ( $curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE );
|
curl_setopt ( $curl, CURLOPT_NOBODY, true );
|
||||||
dbg_error_log("external", "checking external resource for remote changes " . $row->external_url );
|
curl_setopt ( $curl, CURLOPT_TIMEVALUE, $local_ts->format("U") );
|
||||||
$ics = curl_exec ( $curl );
|
curl_setopt ( $curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE );
|
||||||
$info = curl_getinfo ( $curl );
|
dbg_error_log("external", "checking external resource for remote changes " . $row->external_url );
|
||||||
if ( $info['http_code'] === 304 || isset($info['filetime']) && new DateTime("@" . $info['filetime']) <= $local_ts ) {
|
$ics = curl_exec ( $curl );
|
||||||
dbg_error_log("external", "external resource unchanged " . $info['filetime'] . ' < ' . $local_ts->getTimestamp() );
|
$info = curl_getinfo ( $curl );
|
||||||
curl_close ( $curl );
|
if ( $info['http_code'] === 304 || (isset($info['filetime']) && $info['filetime'] != -1 && new DateTime("@" . $info['filetime']) <= $local_ts )) {
|
||||||
// BUGlet: should track server-time instead of local-time
|
dbg_error_log("external", "external resource unchanged " . $info['filetime'] . ' < ' . $local_ts->getTimestamp() . ' (' . $info['http_code'] . ')');
|
||||||
$qry = new AwlQuery( 'UPDATE collection SET modified=NOW() WHERE collection_id = :cid', array ( ':cid' => $row->collection_id ) );
|
curl_close ( $curl );
|
||||||
$qry->Exec('DAVResource');
|
// BUGlet: should track server-time instead of local-time
|
||||||
return true;
|
$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_NOBODY, false );
|
||||||
curl_setopt ( $curl, CURLOPT_HEADER, false );
|
curl_setopt ( $curl, CURLOPT_HEADER, false );
|
||||||
$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
|
// 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');
|
||||||
require_once ( 'caldav-PUT-functions.php');
|
require_once ( 'caldav-PUT-functions.php');
|
||||||
import_collection ( $ics , $row->user_no, $row->path, 'External Fetch' , false ) ;
|
import_collection ( $ics , $row->user_no, $row->path, 'External Fetch' , false ) ;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dbg_error_log("external", "external resource up to date or not found id(%s)", $bind_id );
|
dbg_error_log("external", "external resource up to date or not found id(%s)", $bind_id );
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user