Esempio n. 1
0
<?php

/*
 * A sample script illustrating one way to insert a user into the 
 *  CloudKnock database
 */
require 'classes/user.php';
require 'path/to/Sag.php';
$user = new User(null, null, null, null, "5551112222", null, "15551112222", null);
$user->setName("Your Name");
$sag = new Sag('your-db.couchone.com', '5984');
$sag->setDatabase('cloudknock');
$sag->post(sprintf($user));
$dbs = $s->getAllDatabases()->body;
/* if db already exists, delete it */
if (in_array($dbName, $dbs)) {
    $s->deleteDatabase($dbName);
}
$s->createDatabase($dbName);
$s->setDatabase($dbName);
/* load all the map/reduce js functions from mapReduce directory */
$views = array();
foreach (glob("docs/mapReduce/*") as $mrFiles) {
    list($name, $type) = explode(".", basename($mrFiles));
    $views[$name][$type] = file_get_contents($mrFiles);
}
$view = array("_id" => "_design/files", "type" => "view", "language" => "javascript", "views" => $views);
// Add the view
$s->post($view);
// Delete all cache entries as to not accumulate too many
foreach (glob($cachePath . "/*") as $cacheEntry) {
    unlink($cacheEntry);
}
// Import all new entries
foreach (glob($fileStorageDir . "/*") as $userDir) {
    $userName = trim(base64_decode(basename($userDir)));
    foreach (glob($userDir . "/*") as $userFile) {
        if (!is_file($userFile)) {
            continue;
        }
        echo "[{$userName}] Analyzing: " . basename($userFile) . "\n";
        $metaData = new stdClass();
        $metaData->fileName = basename($userFile);
        analyzeFile($metaData, dirname($userFile), $cachePath);