本文整理汇总了PHP中OC_DB::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_DB::getConnection方法的具体用法?PHP OC_DB::getConnection怎么用?PHP OC_DB::getConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_DB
的用法示例。
在下文中一共展示了OC_DB::getConnection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->validateInput($input, $output);
$this->readPassword($input, $output);
$fromDB = \OC_DB::getConnection();
$toDB = $this->getToDBConnection($input, $output);
if ($input->getOption('clear-schema')) {
$this->clearSchema($toDB, $input, $output);
}
$this->createSchema($toDB, $input, $output);
$toTables = $this->getTables($toDB);
$fromTables = $this->getTables($fromDB);
// warn/fail if there are more tables in 'from' database
$extraFromTables = array_diff($fromTables, $toTables);
if (!empty($extraFromTables)) {
$output->writeln('<comment>The following tables will not be converted:</comment>');
$output->writeln($extraFromTables);
if (!$input->getOption('all-apps')) {
$output->writeln('<comment>Please note that tables belonging to available but currently not installed apps</comment>');
$output->writeln('<comment>can be included by specifying the --all-apps option.</comment>');
}
/** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
$dialog = $this->getHelperSet()->get('dialog');
if (!$dialog->askConfirmation($output, '<question>Continue with the conversion (y/n)? [n] </question>', false)) {
return;
}
}
$intersectingTables = array_intersect($toTables, $fromTables);
$this->convertDB($fromDB, $toDB, $intersectingTables, $input, $output);
}
示例2: __construct
/**
* @param \OC\Files\Storage\Storage|string $storage
* @throws \RuntimeException
*/
public function __construct($storage)
{
if ($storage instanceof \OC\Files\Storage\Storage) {
$this->storageId = $storage->getId();
} else {
$this->storageId = $storage;
}
$this->storageId = self::adjustStorageId($this->storageId);
$sql = 'SELECT `numeric_id` FROM `*PREFIX*storages` WHERE `id` = ?';
$result = \OC_DB::executeAudited($sql, array($this->storageId));
if ($row = $result->fetchRow()) {
$this->numericId = $row['numeric_id'];
} else {
$connection = \OC_DB::getConnection();
if ($connection->insertIfNotExist('*PREFIX*storages', ['id' => $this->storageId])) {
$this->numericId = \OC_DB::insertid('*PREFIX*storages');
} else {
$result = \OC_DB::executeAudited($sql, array($this->storageId));
if ($row = $result->fetchRow()) {
$this->numericId = $row['numeric_id'];
} else {
throw new \RuntimeException('Storage could neither be inserted nor be selected from the database');
}
}
}
}
示例3: setUp
public function setUp()
{
$this->config = \OC::$server->getConfig();
$this->connection = \OC_DB::getConnection();
$this->oldDataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
$this->repair = new \OC\Repair\RepairLegacyStorages($this->config, $this->connection);
}
示例4: runStep
/**
* Send an email to {$limit} users
*
* @param int $limit Number of users we want to send an email to
* @return int Number of users we sent an email to
*/
protected function runStep($limit)
{
// Get all users which should receive an email
$affectedUsers = $this->mqHandler->getAffectedUsers($limit);
if (empty($affectedUsers)) {
// No users found to notify, mission abort
return 0;
}
$preferences = new \OC\Preferences(\OC_DB::getConnection());
$userLanguages = $preferences->getValueForUsers('core', 'lang', $affectedUsers);
$userEmails = $preferences->getValueForUsers('settings', 'email', $affectedUsers);
// Get all items for these users
// We don't use time() but "time() - 1" here, so we don't run into
// runtime issues and delete emails later, which were created in the
// same second, but were not collected for the emails.
$sendTime = time() - 1;
$mailData = $this->mqHandler->getItemsForUsers($affectedUsers, $sendTime);
// Send Email
$default_lang = \OC_Config::getValue('default_language', 'en');
foreach ($mailData as $user => $data) {
if (!isset($userEmails[$user])) {
// The user did not setup an email address
// So we will not send an email :(
continue;
}
$language = isset($userLanguages[$user]) ? $userLanguages[$user] : $default_lang;
$this->mqHandler->sendEmailToUser($user, $userEmails[$user], $language, $data);
}
// Delete all entries we dealt with
$this->mqHandler->deleteSentItems($affectedUsers, $sendTime);
return sizeof($affectedUsers);
}
示例5: setUp
public function setUp()
{
$this->connection = \OC_DB::getConnection();
if ($this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\OCI8\Driver) {
$this->markTestSkipped('DB migration tests arent supported on OCI');
}
$this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
$this->tableName = 'test_' . uniqid();
}
示例6: setUp
public function setUp()
{
$this->connection = \OC_DB::getConnection();
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
$this->markTestSkipped("Test only relevant on MySql");
}
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
$this->tableName = uniqid($dbPrefix . "_enum_bit_test");
$this->connection->exec("CREATE TABLE {$this->tableName}(b BIT, e ENUM('1','2','3','4'))");
}
示例7: assertTableNotExist
/**
* @param string $table
*/
public function assertTableNotExist($table)
{
$platform = \OC_DB::getConnection()->getDatabasePlatform();
if ($platform instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
// sqlite removes the tables after closing the DB
$this->assertTrue(true);
} else {
$this->assertFalse(OC_DB::tableExists($table), 'Table ' . $table . ' exists.');
}
}
示例8: setUp
public function setUp()
{
$this->connection = \OC_DB::getConnection();
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
$this->markTestSkipped("Test only relevant on Sqlite");
}
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
$this->tableName = uniqid($dbPrefix . "_enum_bit_test");
$this->connection->exec("CREATE TABLE {$this->tableName}(t0 tinyint unsigned, t1 tinyint)");
}
示例9: setUp
public function setUp()
{
$this->connection = \OC_DB::getConnection();
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
$this->markTestSkipped("Test only relevant on MySql");
}
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix");
$this->tableName = uniqid($dbPrefix . "_innodb_test");
$this->connection->exec("CREATE TABLE {$this->tableName}(id INT) ENGINE MyISAM");
$this->repair = new \OC\Repair\InnoDB();
}
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$file = $input->getArgument('schema-xml');
$schemaManager = new \OC\DB\MDB2SchemaManager(\OC_DB::getConnection());
try {
$result = $schemaManager->updateDbFromStructure($file, true);
$output->writeln($result);
} catch (\Exception $e) {
$output->writeln('Failed to update database structure (' . $e . ')');
}
}
示例11: setUp
protected function setUp()
{
parent::setUp();
$this->config = \OC::$server->getConfig();
$this->connection = \OC_DB::getConnection();
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
$this->markTestSkipped('DB migration tests are not supported on OCI');
}
$this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
$this->tableName = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_') . 'test_'));
}
示例12: getBeforeUpgradeRepairSteps
/**
* Returns the repair steps to be run before an
* upgrade.
*
* @return array of RepairStep instances
*/
public static function getBeforeUpgradeRepairSteps()
{
$steps = array(new \OC\Repair\InnoDB(), new \OC\Repair\Collation(\OC::$server->getConfig(), \OC_DB::getConnection()), new \OC\Repair\SearchLuceneTables(), new \OC\Repair\RepairConfig());
//There is no need to delete all previews on every single update
//only 7.0.0 thru 7.0.2 generated broken previews
$currentVersion = \OC_Config::getValue('version');
if (version_compare($currentVersion, '7.0.0.0', '>=') && version_compare($currentVersion, '7.0.3.4', '<=')) {
$steps[] = new \OC\Repair\Preview();
}
return $steps;
}
示例13: setUp
public function setUp()
{
$this->connection = \OC_DB::getConnection();
$this->config = \OC::$server->getConfig();
if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) {
$this->markTestSkipped("Test only relevant on MySql");
}
$dbPrefix = $this->config->getSystemValue("dbtableprefix");
$this->tableName = uniqid($dbPrefix . "_collation_test");
$this->connection->exec("CREATE TABLE {$this->tableName}(text VARCHAR(16)) COLLATE utf8_unicode_ci");
$this->repair = new TestCollationRepair($this->config, $this->connection);
}
示例14: setUp
protected function setUp()
{
parent::setUp();
$this->config = \OC::$server->getConfig();
$this->connection = \OC_DB::getConnection();
$this->oldDataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
$this->repair = new \OC\Repair\RepairLegacyStorages($this->config, $this->connection);
$this->warnings = [];
$this->repair->listen('\\OC\\Repair', 'warning', function ($description) {
$this->warnings[] = $description;
});
}
示例15: setUp
public function setUp()
{
$this->connection = \OC_DB::getConnection();
if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) {
$this->markTestSkipped('DB migration tests are not supported on OCI');
}
if ($this->connection->getDatabasePlatform() instanceof SQLServerPlatform) {
$this->markTestSkipped('DB migration tests are not supported on MSSQL');
}
$this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
$this->tableName = 'test_' . uniqid();
}