コード例 #1
0
ファイル: caldav-BIND.php プロジェクト: derekyu1437/davical
        $qry->QDo('SELECT collection_id FROM collection WHERE dav_name = :dav_name ', array(':dav_name' => '/.external/' . md5($href)));
        if ($qry->rows() != 1 || !($row = $qry->Fetch())) {
            $request->DoResponse(500, translate('Database Error'));
        }
        $dav_id = $row->collection_id;
    }
    $sql = 'INSERT INTO dav_binding ( bound_source_id, access_ticket_id, dav_owner_id, parent_container, dav_name, dav_displayname, external_url, type )
  VALUES( :target_id, :ticket_id, :session_principal, :parent_container, :dav_name, :displayname, :external_url, :external_type )';
    $params = array(':target_id' => $dav_id, ':ticket_id' => null, ':parent_container' => $parent->dav_name(), ':session_principal' => $session->principal_id, ':dav_name' => $destination_path, ':displayname' => $segment, ':external_url' => $href, ':external_type' => 'calendar');
    $qry = new AwlQuery($sql, $params);
    if ($qry->Exec('BIND', __LINE__, __FILE__)) {
        $qry = new AwlQuery('SELECT bind_id from dav_binding where dav_name = :dav_name', array(':dav_name' => $destination_path));
        if (!$qry->Exec('BIND', __LINE__, __FILE__) || $qry->rows() != 1 || !($row = $qry->Fetch())) {
            $request->DoResponse(500, translate('Database Error'));
        }
        fetch_external($row->bind_id, '');
        $request->DoResponse(201);
    } else {
        $request->DoResponse(500, translate('Database Error'));
    }
} else {
    $source = new DAVResource($href);
    if (!$source->Exists()) {
        $request->PreconditionFailed(403, 'DAV::bind-source-exists', translate('The BIND Request MUST identify an existing resource.'));
    }
    if ($source->IsPrincipal() || !$source->IsCollection()) {
        $request->PreconditionFailed(403, 'DAV::binding-allowed', translate('DAViCal only allows BIND requests for collections at present.'));
    }
    if ($source->IsBinding()) {
        $source = new DAVResource($source->bound_from());
    }
コード例 #2
0
function update_external($request)
{
    global $c;
    if ($c->external_refresh < 1) {
        return;
    }
    if (!function_exists("curl_init")) {
        dbg_error_log("external", "external resource cannot be fetched without curl, please install curl");
        return;
    }
    $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 : %s", $row->url);
            fetch_external($row->bind_id);
        }
    }
}