本文整理汇总了PHP中OC_DB::createDbFromStructure方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_DB::createDbFromStructure方法的具体用法?PHP OC_DB::createDbFromStructure怎么用?PHP OC_DB::createDbFromStructure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_DB
的用法示例。
在下文中一共展示了OC_DB::createDbFromStructure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupDatabase
public function setupDatabase($username)
{
$datadir = \OC_Config::getValue('datadirectory');
//delete the old sqlite database first, might cause infinte loops otherwise
if (file_exists("{$datadir}/owncloud.db")) {
unlink("{$datadir}/owncloud.db");
}
//in case of sqlite, we can always fill the database
error_log("creating sqlite db");
\OC_DB::createDbFromStructure($this->dbDefinitionFile);
}
示例2: setupDatabase
public function setupDatabase($username)
{
//check if the database user has admin right
$connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword);
if (!$connection) {
throw new \OC\DatabaseSetupException($this->trans->t('MySQL/MariaDB username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.'));
}
//user already specified in config
$oldUser = \OC_Config::getValue('dbuser', false);
//we don't have a dbuser specified in config
if ($this->dbuser != $oldUser) {
//add prefix to the admin username to prevent collisions
$adminUser = substr('oc_' . $username, 0, 16);
$i = 1;
while (true) {
//this should be enough to check for admin rights in mysql
$query = "SELECT user FROM mysql.user WHERE user='{$adminUser}'";
$result = mysql_query($query, $connection);
//current dbuser has admin rights
if ($result) {
//new dbuser does not exist
if (mysql_num_rows($result) === 0) {
//use the admin login data for the new database user
$this->dbuser = $adminUser;
//create a random password so we don't need to store the admin password in the config file
$this->dbpassword = \OC_Util::generateRandomBytes(30);
$this->createDBUser($connection);
break;
} else {
//repeat with different username
$length = strlen((string) $i);
$adminUser = substr('oc_' . $username, 0, 16 - $length) . $i;
$i++;
}
} else {
break;
}
}
\OC_Config::setValue('dbuser', $this->dbuser);
\OC_Config::setValue('dbpassword', $this->dbpassword);
}
//create the database
$this->createDatabase($connection);
//fill the database if needed
$query = 'select count(*) from information_schema.tables' . " where table_schema='" . $this->dbname . "' AND table_name = '" . $this->tableprefix . "users';";
$result = mysql_query($query, $connection);
if ($result) {
$row = mysql_fetch_row($result);
}
if (!$result or $row[0] == 0) {
\OC_DB::createDbFromStructure($this->dbDefinitionFile);
}
mysql_close($connection);
}
示例3: setUp
public function setUp()
{
$dbfile = OC::$SERVERROOT . '/tests/data/db_structure.xml';
$r = '_' . OC_Util::generate_random_bytes('4') . '_';
$content = file_get_contents($dbfile);
$content = str_replace('*dbprefix*', '*dbprefix*' . $r, $content);
file_put_contents(self::$schema_file, $content);
OC_DB::createDbFromStructure(self::$schema_file);
$this->test_prefix = $r;
$this->table1 = $this->test_prefix . 'contacts_addressbooks';
$this->table2 = $this->test_prefix . 'contacts_cards';
$this->table3 = $this->test_prefix . 'vcategory';
}
示例4: setupDatabase
public function setupDatabase($username)
{
//check if the database user has admin right
$connection = $this->connect();
$this->createSpecificUser($username, $connection);
//create the database
$this->createDatabase($connection);
//fill the database if needed
$query = 'select count(*) from information_schema.tables where table_schema=? AND table_name = ?';
$result = $connection->executeQuery($query, [$this->dbName, $this->tablePrefix . 'users']);
$row = $result->fetch();
if (!$result or $row[0] == 0) {
\OC_DB::createDbFromStructure($this->dbDefinitionFile);
}
}
示例5: setUp
protected function setUp()
{
parent::setUp();
$dbfile = OC::$SERVERROOT . '/tests/data/db_structure.xml';
$r = '_' . OC_Util::generateRandomBytes(4) . '_';
$content = file_get_contents($dbfile);
$content = str_replace('*dbprefix*', '*dbprefix*' . $r, $content);
file_put_contents(self::$schema_file, $content);
OC_DB::createDbFromStructure(self::$schema_file);
$this->test_prefix = $r;
$this->table1 = $this->test_prefix . 'cntcts_addrsbks';
$this->table2 = $this->test_prefix . 'cntcts_cards';
$this->table3 = $this->test_prefix . 'vcategory';
$this->table4 = $this->test_prefix . 'decimal';
}
示例6: xsetUpBeforeClass
public static function xsetUpBeforeClass()
{
$dbfile = __DIR__ . '/../../appinfo/database.xml';
self::$test_prefix = '_' . OC_Util::generateRandomBytes('4') . '_';
$content = file_get_contents($dbfile);
$content = str_replace('*dbprefix*', '*dbprefix*' . self::$test_prefix, $content);
file_put_contents(self::$schema_file, $content);
OC_DB::createDbFromStructure(self::$schema_file);
self::$addressBooksTableName = '*PREFIX*' . self::$test_prefix . 'contacts_addressbooks';
self::$cardsTableName = '*PREFIX*' . self::$test_prefix . 'contacts_cards';
OC_User::clearBackends();
OC_User::useBackend('dummy');
self::$user = uniqid('user_');
OC_User::createUser(self::$user, 'pass');
OC_User::setUserId(self::$user);
self::$backend = new OCA\Contacts\Backend\Database(self::$user, self::$addressBooksTableName, self::$cardsTableName);
}
示例7: setupDatabase
public function setupDatabase($username)
{
//check if the database user has admin right
$connection = @mysql_connect($this->dbhost, $this->dbuser, $this->dbpassword);
if (!$connection) {
throw new \DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.'));
}
$oldUser = \OC_Config::getValue('dbuser', false);
//this should be enough to check for admin rights in mysql
$query = "SELECT user FROM mysql.user WHERE user='{$this->dbuser}'";
if (mysql_query($query, $connection)) {
//use the admin login data for the new database user
//add prefix to the mysql user name to prevent collisions
$this->dbuser = substr('oc_' . $username, 0, 16);
if ($this->dbuser != $oldUser) {
//hash the password so we don't need to store the admin config in the config file
$this->dbpassword = \OC_Util::generateRandomBytes(30);
$this->createDBUser($connection);
\OC_Config::setValue('dbuser', $this->dbuser);
\OC_Config::setValue('dbpassword', $this->dbpassword);
}
//create the database
$this->createDatabase($connection);
} else {
if ($this->dbuser != $oldUser) {
\OC_Config::setValue('dbuser', $this->dbuser);
\OC_Config::setValue('dbpassword', $this->dbpassword);
}
//create the database
$this->createDatabase($connection);
}
//fill the database if needed
$query = 'select count(*) from information_schema.tables' . " where table_schema='" . $this->dbname . "' AND table_name = '" . $this->tableprefix . "users';";
$result = mysql_query($query, $connection);
if ($result) {
$row = mysql_fetch_row($result);
}
if (!$result or $row[0] == 0) {
\OC_DB::createDbFromStructure($this->dbDefinitionFile);
}
mysql_close($connection);
}
示例8:
<?php
$currentVersion = OC_Appconfig::getValue('gallery', 'installed_version');
if (version_compare($currentVersion, '0.5.0', '<')) {
$stmt = OCP\DB::prepare('DROP TABLE IF EXISTS `*PREFIX*gallery_photos`');
$stmt->execute();
$stmt = OCP\DB::prepare('DROP TABLE IF EXISTS `*PREFIX*gallery_albums`');
$stmt->execute();
\OC_DB::createDbFromStructure(OC_App::getAppPath($appid) . '/appinfo/database.xml');
}
示例9:
<?php
$currentVersion = OC_Appconfig::getValue('gallery', 'installed_version');
if (version_compare($currentVersion, '0.5.0', '<')) {
$stmt = OCP\DB::prepare('DROP TABLE IF EXISTS *PREFIX*gallery_photos');
$stmt->execute();
$stmt = OCP\DB::prepare('DROP TABLE IF EXISTS *PREFIX*gallery_albums');
$stmt->execute();
\OC_DB::createDbFromStructure(OC::$APPSROOT . '/apps/' . $appid . '/appinfo/database.xml');
}
示例10: doTestSchemaCreating
public function doTestSchemaCreating()
{
OC_DB::createDbFromStructure($this->schema_file);
$this->assertTableExist($this->table1);
$this->assertTableExist($this->table2);
}
示例11: testBrokenLastIndexId
public function testBrokenLastIndexId()
{
// create test table
$this->checkLastIndexId();
\OC_DB::createDbFromStructure(__DIR__ . '/encryption_table.xml');
$this->checkLastIndexId();
}
示例12: installShippedApp
/**
* install an app already placed in the app folder
* @param string $app id of the app to install
* @returns array see OC_App::getAppInfo
*/
public static function installShippedApp($app)
{
//install the database
if (is_file(OC::$APPSROOT . "/apps/{$app}/appinfo/database.xml")) {
OC_DB::createDbFromStructure(OC::$APPSROOT . "/apps/{$app}/appinfo/database.xml");
}
//run appinfo/install.php
if (is_file(OC::$APPSROOT . "/apps/{$app}/appinfo/install.php")) {
include OC::$APPSROOT . "/apps/{$app}/appinfo/install.php";
}
$info = OC_App::getAppInfo($app);
OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
//set remote/public handelers
foreach ($info['remote'] as $name => $path) {
OCP\CONFIG::setAppValue('core', 'remote_' . $name, '/apps/' . $app . '/' . $path);
}
foreach ($info['public'] as $name => $path) {
OCP\CONFIG::setAppValue('core', 'public_' . $name, '/apps/' . $app . '/' . $path);
}
OC_App::setAppTypes($info['id']);
return $info;
}
示例13: installShippedApp
/**
* install an app already placed in the app folder
* @param string $app id of the app to install
* @returns array see OC_App::getAppInfo
*/
public static function installShippedApp($app)
{
//install the database
if (is_file(OC::$SERVERROOT . "/apps/{$app}/appinfo/database.xml")) {
OC_DB::createDbFromStructure(OC::$SERVERROOT . "/apps/{$app}/appinfo/database.xml");
}
//run appinfo/install.php
if (is_file(OC::$SERVERROOT . "/apps/{$app}/appinfo/install.php")) {
include OC::$SERVERROOT . "/apps/{$app}/appinfo/install.php";
}
$info = OC_App::getAppInfo(OC::$SERVERROOT . "/apps/{$app}/appinfo/info.xml");
OC_Appconfig::setValue($app, 'installed_version', $info['version']);
return $info;
}
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:19,代码来源:owncloud_lib_installer.php
示例14: setupDatabase
public function setupDatabase($username)
{
$e_host = addslashes($this->dbhost);
$e_user = addslashes($this->dbuser);
$e_password = addslashes($this->dbpassword);
//check if the database user has admin rights
$connection_string = "host='{$e_host}' dbname=postgres user='{$e_user}' password='{$e_password}'";
$connection = @pg_connect($connection_string);
if (!$connection) {
// Try if we can connect to the DB with the specified name
$e_dbname = addslashes($this->dbname);
$connection_string = "host='{$e_host}' dbname='{$e_dbname}' user='{$e_user}' password='{$e_password}'";
$connection = @pg_connect($connection_string);
if (!$connection) {
throw new \DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.'));
}
}
$e_user = pg_escape_string($this->dbuser);
//check for roles creation rights in postgresql
$query = "SELECT 1 FROM pg_roles WHERE rolcreaterole=TRUE AND rolname='{$e_user}'";
$result = pg_query($connection, $query);
if ($result and pg_num_rows($result) > 0) {
//use the admin login data for the new database user
//add prefix to the postgresql user name to prevent collisions
$this->dbuser = 'oc_' . $username;
//create a new password so we don't need to store the admin config in the config file
$this->dbpassword = \OC_Util::generateRandomBytes(30);
$this->createDBUser($connection);
\OC_Config::setValue('dbuser', $this->dbuser);
\OC_Config::setValue('dbpassword', $this->dbpassword);
//create the database
$this->createDatabase($connection);
} else {
\OC_Config::setValue('dbuser', $this->dbuser);
\OC_Config::setValue('dbpassword', $this->dbpassword);
//create the database
$this->createDatabase($connection);
}
// the connection to dbname=postgres is not needed anymore
pg_close($connection);
// connect to the ownCloud database (dbname=$this->dbname) and check if it needs to be filled
$this->dbuser = \OC_Config::getValue('dbuser');
$this->dbpassword = \OC_Config::getValue('dbpassword');
$e_host = addslashes($this->dbhost);
$e_dbname = addslashes($this->dbname);
$e_user = addslashes($this->dbuser);
$e_password = addslashes($this->dbpassword);
$connection_string = "host='{$e_host}' dbname='{$e_dbname}' user='{$e_user}' password='{$e_password}'";
$connection = @pg_connect($connection_string);
if (!$connection) {
throw new \DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'), $this->trans->t('You need to enter either an existing account or the administrator.'));
}
$query = "select count(*) FROM pg_class WHERE relname='" . $this->tableprefix . "users' limit 1";
$result = pg_query($connection, $query);
if ($result) {
$row = pg_fetch_row($result);
}
if (!$result or $row[0] == 0) {
\OC_DB::createDbFromStructure($this->dbDefinitionFile);
}
}
示例15: setupOCIDatabase
private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username)
{
$e_host = addslashes($dbhost);
$e_dbname = addslashes($dbname);
//check if the database user has admin right
if ($e_host == '') {
$easy_connect_string = $e_dbname;
// use dbname as easy connect name
} else {
$easy_connect_string = '//' . $e_host . '/' . $e_dbname;
}
$connection = @oci_connect($dbuser, $dbpass, $easy_connect_string);
if (!$connection) {
$e = oci_error();
throw new Exception('Oracle username and/or password not valid');
}
//check for roles creation rights in oracle
$query = "SELECT count(*) FROM user_role_privs, role_sys_privs WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'";
$stmt = oci_parse($connection, $query);
if (!$stmt) {
$entry = 'DB Error: "' . oci_last_error($connection) . '"<br />';
$entry .= 'Offending command was: ' . $query . '<br />';
echo $entry;
}
$result = oci_execute($stmt);
if ($result) {
$row = oci_fetch_row($stmt);
}
if ($result and $row[0] > 0) {
//use the admin login data for the new database user
//add prefix to the oracle user name to prevent collisions
$dbusername = 'oc_' . $username;
//create a new password so we don't need to store the admin config in the config file
$dbpassword = md5(time() . $dbpass);
//oracle passwords are treated as identifiers:
// must start with aphanumeric char
// needs to be shortened to 30 bytes, as the two " needed to escape the identifier count towards the identifier length.
$dbpassword = substr($dbpassword, 0, 30);
self::oci_createDBUser($dbusername, $dbpassword, $dbtablespace, $connection);
OC_Config::setValue('dbuser', $dbusername);
OC_Config::setValue('dbname', $dbusername);
OC_Config::setValue('dbpassword', $dbpassword);
//create the database not neccessary, oracle implies user = schema
//self::oci_createDatabase($dbname, $dbusername, $connection);
} else {
OC_Config::setValue('dbuser', $dbuser);
OC_Config::setValue('dbname', $dbname);
OC_Config::setValue('dbpassword', $dbpass);
//create the database not neccessary, oracle implies user = schema
//self::oci_createDatabase($dbname, $dbuser, $connection);
}
//FIXME check tablespace exists: select * from user_tablespaces
// the connection to dbname=oracle is not needed anymore
oci_close($connection);
// connect to the oracle database (schema=$dbuser) an check if the schema needs to be filled
$dbuser = OC_Config::getValue('dbuser');
//$dbname = OC_Config::getValue('dbname');
$dbpass = OC_Config::getValue('dbpassword');
$e_host = addslashes($dbhost);
$e_dbname = addslashes($dbname);
if ($e_host == '') {
$easy_connect_string = $e_dbname;
// use dbname as easy connect name
} else {
$easy_connect_string = '//' . $e_host . '/' . $e_dbname;
}
$connection = @oci_connect($dbuser, $dbpass, $easy_connect_string);
if (!$connection) {
throw new Exception('Oracle username and/or password not valid');
}
$query = "SELECT count(*) FROM user_tables WHERE table_name = :un";
$stmt = oci_parse($connection, $query);
$un = $dbtableprefix . 'users';
oci_bind_by_name($stmt, ':un', $un);
if (!$stmt) {
$entry = 'DB Error: "' . oci_last_error($connection) . '"<br />';
$entry .= 'Offending command was: ' . $query . '<br />';
echo $entry;
}
$result = oci_execute($stmt);
if ($result) {
$row = oci_fetch_row($stmt);
}
if (!$result or $row[0] == 0) {
OC_DB::createDbFromStructure('db_structure.xml');
}
}