*/
require_once "../lib/couch.php";
require_once "../lib/couchClient.php";
require_once "../lib/couchDocument.php";
/**
* create the client
*/
$client = new couchClient($couch_dsn, $couch_db);
/**
* As usual we create the database
*
*
*/
echo "#### Creating database " . $client->getDatabaseUri() . ': $result = $client->createDatabase();' . "\n";
try {
    $result = $client->createDatabase();
} catch (Exception $e) {
    if ($e instanceof couchException) {
        echo "We issued the request, but couch server returned an error.\n";
        echo "We can have HTTP Status code returned by couchDB using \$e->getCode() : " . $e->getCode() . "\n";
        echo "We can have error message returned by couchDB using \$e->getMessage() : " . $e->getMessage() . "\n";
        echo "Finally, we can have CouchDB's complete response body using \$e->getBody() : " . print_r($e->getBody(), true) . "\n";
        echo "Are you sure that your CouchDB server is at {$couch_dsn}, and that database {$couch_db} does not exist ?\n";
        exit(1);
    } else {
        echo "It seems that something wrong happened. You can have more details using :\n";
        echo "the exception class with get_class(\$e) : " . get_class($e) . "\n";
        echo "the exception error code with \$e->getCode() : " . $e->getCode() . "\n";
        echo "the exception error message with \$e->getMessage() : " . $e->getMessage() . "\n";
        exit(1);
    }
Esempio n. 2
0
			print '<input type="hidden" name="couchdb_user_root" value="' . $_POST['couchdb_user_root'] . '">';
			print '<input type="hidden" name="couchdb_pass_root" value="' . $_POST['couchdb_pass_root'] . '">';

			try {
				if ($_POST['couchdb_create_admin']) {
					$couchdb = new couchClient($conf->Couchdb->host . ':' . $conf->Couchdb->port . '/', $conf->Couchdb->name);
					$couchAdmin = new couchAdmin($couchdb);
					$couchAdmin->createAdmin($_POST['couchdb_user_root'], $_POST['couchdb_pass_root']);
					$couchAdmin->addRoleToUser($_POST['couchdb_user_root'], "Administrator"); // Add user in administrator group
				}

				$host = substr($conf->Couchdb->host, 7);
				$couchdb = new couchClient('http://' . $_POST['couchdb_user_root'] . ':' . $_POST['couchdb_pass_root'] . '@' . $host . ':' . $conf->Couchdb->port . '/', $conf->Couchdb->name, array("cookie_auth" => false));

				if ($_POST['couchdb_create_database'])
					$couchdb->createDatabase();

				$couchdb->getDatabaseInfos();
				print "<tr><td>";
				print $langs->trans("ServerConnection") . " (" . $langs->trans("User") . " " . $_POST['couchdb_user_root'] . ") : ";
				print $dolibarr_main_couchdb_host;
				print "</td><td>";
				print $langs->trans("OK");
				print "</td></tr>";
				print "<tr><td>";
				print $langs->trans("DatabaseConnection") . " (" . $langs->trans("User") . " " . $_POST['couchdb_user_root'] . ") : ";
				print $dolibarr_main_couchdb_name;
				print "</td><td>";
				print $langs->trans("OK");
				print "</td></tr>";
			} catch (Exception $e) {