Ejemplo n.º 1
0
/**
 * Given a resource, this function fetches that resource and updates
 * its status in the database if anything has changed, in particular
 * the title field.
 *
 * If the resource is no longer available (returns 404), the resource
 * is removed. Is this too radical?
 *
 */
function reload(folksoQuery $q, folksoWsseCreds $cred, folksoDBconnect $dbc)
{
    $i = new folksoDBinteract($dbc);
    if ($i->db_error()) {
        header('HTTP/1.0 501 Database connection error');
        die($i->error_info());
    }
    /** check initial url **/
    $url = '';
    if (is_numeric($q->res)) {
        $url = $i->url_from_id($q->res);
        if ($url = 0) {
            // no corresponding url
            header('HTTP/1.1 404 Resource not found.');
            print "The numeric id " . $q->res . " that was provided does not correspond " . " to an existing  resource. Perhaps the resource has been deleted.";
            return;
        }
    } else {
        $url = $q->res;
        if (!$i->resourcep($url)) {
            header('HTTP/1.1 404 Resource not found');
            print "The url provided (" . $q->res . ") was not found in the database. " . "It must be added before it can be modified.";
            return;
        }
    }
    /** do request **/
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_USERAGENT, 'folksoClient');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    $result_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    /** react to request results **/
    $rq = new folksoResupQuery();
    switch ($result_code) {
        case '404':
            $i->query($rq->resremove($url));
            header('http/1.1 200 Deleted');
            print "Removed the resource {$url} from the system.";
            return;
            break;
        case '200':
            $i->query($rq->resmodtitle($url, $newtitle));
    }
}
Ejemplo n.º 2
0
 public function testUrl_from_id()
 {
     $i = new folksoDBinteract($this->dbc);
     $this->assertEqual($i->url_from_id(3), 'http://example.com/3', 'url_from_id not retrieving correct url.');
 }