Example #1
0
 public function saveDataToCouch($data)
 {
     try {
         phpillowConnection::createInstance($this->to_host, $this->to_port, '', '');
         phpillowConnection::setDatabase($this->to_database);
     } catch (Exception $e) {
         die("Nie moge nawiazac polaczenia z baza Couch ({$this->to_host}:{$this->to_port})");
     }
     $allowKeys = array('nazwa', 'dlugosc', 'szerokosc', 'ludnosc', 'link');
     foreach ($data as $k => $value) {
         if (is_array($value) && !empty($value)) {
             $doc = new miastoDocument();
             foreach ($value as $k1 => $v1) {
                 if (in_array($k1, $allowKeys)) {
                     $doc->{$k1} = $v1;
                 }
             }
             $doc->save();
         }
     }
 }
 /**
  * Reset database depending on provided options
  *
  * @param array $options
  * @return void
  */
 public static function resetDatabase(array $options = array())
 {
     phpillowConnectionTestHelper::reset();
     // Initialize wanted connection handler
     $handler = isset($options['handler']) ? $options['handler'] : 'phpillowConnection';
     call_user_func(array($handler, 'createInstance'));
     $db = phpillowConnection::getInstance();
     try {
         $db->delete('/test');
     } catch (Exception $e) {
         /* Ignored */
     }
     if (isset($options['database'])) {
         // Create test database
         phpillowConnection::setDatabase($options['database']);
         $db = phpillowConnection::getInstance();
         $db->put('/' . $options['database']);
     } else {
         // Reset all connection settings in the end
         phpillowConnectionTestHelper::reset();
     }
 }
<?php

// Include all required classes
$autoload = (require ($base = dirname(__FILE__) . '/../src/') . 'classes/autoload.php');
foreach ($autoload as $file) {
    require_once $base . $file;
}
// Configure parameters for speed testing
$puts = 1000;
$gets = 5000;
$views = 2000;
// Set up backend connection
phpillowConnection::createInstance('10.0.118.171', 5984, 'admin', 'm4!1.d3');
phpillowConnection::setDatabase('test');
$db = phpillowConnection::getInstance();
try {
    $db->delete('/test');
} catch (Exception $e) {
    /* Ignore */
}
$db->put('/test');
// /*
$start = microtime(true);
for ($i = 0; $i < $puts; ++$i) {
    $doc = new phpillowUserDocument();
    $doc->login = '******' . $i;
    $doc->name = 'Kore Nordmann';
    $doc->save();
}
printf("%d PUTs in %.2fs (%d req/s)\n", $puts, $time = microtime(true) - $start, $puts / $time);
// */
Example #4
0
<?php

//Install PHPillow using PEAR
require "PHPillow/bootstrap.php";
require "documents.php";
require "views.php";
require "settings.php";
phpillowConnection::createInstance('localhost', 5984, COUCHDB_USER, COUCHDB_PASSWORD);
phpillowConnection::setDatabase(COUCHDB_DATABASE);
function tripHash($password)
{
    //TODO: Talk to someone smart about cryptographic hash functions
    //This appears to work well, but there could be a flaw.
    //based on wikipedia description of algo
    $tripcode = substr(crypt($password, TRIPCODE_SALT), -10, 10);
    return $tripcode;
}
function validMessage($json)
{
    //make sure username is appropriate length and alphanumeric plus underscore
    if (strlen($json->username) > 30 || strlen($json->username) < 3) {
        return false;
    }
    $alphanumeric = '/^[0-9a-zA-Z_]+$/';
    if (!preg_match($alphanumeric, $json->username)) {
        return false;
    }
    //make sure message isn't too long.
    if (strlen($json->message) > 1000) {
        return false;
    }
 public function testDeleteDocumentMultipleRevisions()
 {
     phpillowConnection::createInstance();
     phpillowConnection::setDatabase('test');
     // Create test database
     $db = phpillowConnection::getInstance();
     $db->put('/test');
     // Add document to fetch
     $author = phpillowManager::createDocument('user');
     $author->login = '******';
     $author->save();
     $doc = phpillowManager::fetchDocument('user', 'user-kore');
     $doc->name = 'Kore';
     $doc->save();
     // Test delete
     phpillowManager::deleteDocument('user', 'user-kore');
     try {
         $user = phpillowManager::fetchDocument('user', 'user-kore');
         $this->fail('Expected phpillowResponseNotFoundErrorException.');
     } catch (phpillowResponseNotFoundErrorException $e) {
         /* Expected exception */
     }
     // Remove / clear test database
     $db = phpillowConnection::getInstance();
     $db->delete('/test');
     phpillowConnectionTestHelper::reset();
 }
 public function testGetDocumentFromNotExistentDatabase()
 {
     $this->markTestSkipped('It is currently not possible to detect from the CouchDB response, see: https://issues.apache.org/jira/browse/COUCHDB-41');
     phpillowStreamConnection::createInstance();
     phpillowConnection::setDatabase('test');
     $db = phpillowConnection::getInstance();
     try {
         $response = $db->delete('/test');
     } catch (phpillowResponseErrorException $e) {
         /* Ignore */
     }
     try {
         $response = $db->get('/test/not_existent');
         $this->fail('Expected phpillowDatabaseNotFoundErrorException.');
     } catch (phpillowDatabaseNotFoundErrorException $e) {
         /* Expected exception */
     }
 }
Example #7
0
<?php

/** Configuration Variables **/
define('DEVELOPMENT_ENVIRONMENT', true);
//RANDOM HASH STRING
define('HASH_STRING', '2d5A212fE35c');
//Typ bazy
define('DB_TYPE', 'couchdb');
//couchdb, mysql
//MYSQL
define('DB_NAME', 'yourdatabasename');
define('DB_USER', 'yourusername');
define('DB_PASSWORD', 'yourpassword');
define('DB_HOST', 'localhost');
//couchDB
define('CDB_USER', '');
define('CDB_PASSWORD', '');
define('CDB_HOST', '127.0.0.1');
define('CDB_PORT', '5984');
define('CDB_NAME', 'baza');
//nazwa bazy
phpillowConnection::createInstance(CDB_HOST, CDB_PORT, CDB_USER, CDB_PASSWORD);
phpillowConnection::setDatabase(CDB_NAME);
 public function testSetAndGetDatabase()
 {
     phpillowCustomConnection::createInstance();
     phpillowConnection::setDatabase('test');
     $this->assertSame('/test/', phpillowConnection::getDatabase());
 }