Esempio n. 1
0
 function testAdHocHeaders()
 {
     $r = new folksoResponse();
     $r->setType('xml');
     $r->setOk(200, 'Dandy');
     $r->addHeader('X-Test-Random: Bob');
     $r->prepareHeaders();
     $this->assertTrue(count($r->headers) == 3, 'Incorrect number of headers: ' . count($r->headers));
     $this->assertEqual($r->headers[2], 'X-Test-Random: Bob', 'Not retrieveing correct ad-hoc header data');
 }
Esempio n. 2
0
File: tag.php Progetto: josf/folkso
/**
 * POST, res, target 
 * 
 * Retags all the tagevents tagged by "source" as "target", then
 * deletes "source".
 *
 * Returns 204 on success, 404 on missing tags.
 * 
 */
function tagMerge(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks)
{
    $r = new folksoResponse();
    $u = $fks->userSession(null, 'folkso', 'redac');
    if (!$u instanceof folksoUser || !$u->checkUserRight('folkso', 'redac')) {
        return $r->unAuthorized($u);
    }
    try {
        $i = new folksoDBinteract($dbc);
        /* build query. all the funny quote marks are there because the
           stored procedure 'tagmerge' needs 4 arguments to distinguish
           between numeric args and non numeric args*/
        $source_part = '';
        if (is_numeric($q->tag)) {
            $source_part = $q->tag . ", ''";
        } else {
            $source_part = "'', '" . $i->dbquote($q->tag) . "'";
        }
        $target_part = '';
        if (is_numeric($q->get_param('target'))) {
            $target_part = $q->get_param('target') . ", ''";
        } else {
            $target_part = "'', '" . $i->dbquote($q->get_param('target')) . "'";
        }
        $i->query("CALL TAGMERGE({$source_part}, {$target_part})");
    } catch (dbException $e) {
        return $r->handleDBexception($e);
    }
    $row = $i->result->fetch_object();
    $newid = $row->newid;
    switch ($row->status) {
        case 'OK':
            $r->setOk(204, 'Merge successful');
            $r->t($i->first_val('status'));
            $r->addHeader('X-Folksonomie-TargetId: ' . $newid);
            break;
        case 'NOTARGET':
            $r->setError(404, 'Invalid target tag', $status . $q->get_param('target') . " is not present in the database. Merge not accomplished.");
            break;
        case 'NOSOURCE':
            $r->setError(404, 'Invalid source tag', $q->res . " is not present in the database. Merge not accomplished.");
            break;
        default:
            $r->setError(500, 'Strange server error', "fv: " . $status . 'This should not have happened.' . $row->status);
    }
    return $r;
}