*/
namespace OC\DB;
+use Doctrine\Common\EventManager;
+use Doctrine\DBAL\Configuration;
+use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Event\Listeners\OracleSessionInit;
use Doctrine\DBAL\Event\Listeners\SQLSessionInit;
-use Doctrine\DBAL\Event\Listeners\MysqlSessionInit;
use OCP\IConfig;
/**
* Array mapping DBMS type to default connection parameters passed to
* \Doctrine\DBAL\DriverManager::getConnection().
*/
- protected $defaultConnectionParams = array(
- 'mysql' => array(
+ protected $defaultConnectionParams = [
+ 'mysql' => [
'adapter' => '\OC\DB\AdapterMySQL',
'charset' => 'UTF8',
'driver' => 'pdo_mysql',
'wrapperClass' => 'OC\DB\Connection',
- ),
- 'oci' => array(
+ ],
+ 'oci' => [
'adapter' => '\OC\DB\AdapterOCI8',
'charset' => 'AL32UTF8',
'driver' => 'oci8',
'wrapperClass' => 'OC\DB\OracleConnection',
- ),
- 'pgsql' => array(
+ ],
+ 'pgsql' => [
'adapter' => '\OC\DB\AdapterPgSql',
'driver' => 'pdo_pgsql',
'wrapperClass' => 'OC\DB\Connection',
- ),
- 'sqlite3' => array(
+ ],
+ 'sqlite3' => [
'adapter' => '\OC\DB\AdapterSqlite',
'driver' => 'pdo_sqlite',
'wrapperClass' => 'OC\DB\Connection',
- ),
- );
+ ],
+ ];
public function __construct(IConfig $config) {
if($config->getSystemValue('mysql.utf8mb4', false)) {
*/
public function getConnection($type, $additionalConnectionParams) {
$normalizedType = $this->normalizeType($type);
- $eventManager = new \Doctrine\Common\EventManager();
+ $eventManager = new EventManager();
switch ($normalizedType) {
case 'mysql':
- // Send "SET NAMES utf8". Only required on PHP 5.3 below 5.3.6.
- // See http://stackoverflow.com/questions/4361459/php-pdo-charset-set-names#4361485
- $eventManager->addEventSubscriber(new MysqlSessionInit(
- $this->defaultConnectionParams['mysql']['charset']
- ));
$eventManager->addEventSubscriber(
new SQLSessionInit("SET SESSION AUTOCOMMIT=1"));
break;
$eventManager->addEventSubscriber(new SQLiteSessionInit(true, $journalMode));
break;
}
- $connection = \Doctrine\DBAL\DriverManager::getConnection(
+ /** @var Connection $connection */
+ $connection = DriverManager::getConnection(
array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams),
- new \Doctrine\DBAL\Configuration(),
+ new Configuration(),
$eventManager
);
return $connection;
}
/**
- * @brief Checks whether the specified DBMS type is valid.
- * @return bool
- */
+ * Checks whether the specified DBMS type is valid.
+ *
+ * @param string $type
+ * @return bool
+ */
public function isValidType($type) {
$normalizedType = $this->normalizeType($type);
return isset($this->defaultConnectionParams[$normalizedType]);
public function createConnectionParams($config) {
$type = $config->getValue('dbtype', 'sqlite');
- $connectionParams = array(
+ $connectionParams = [
'user' => $config->getValue('dbuser', ''),
'password' => $config->getValue('dbpassword', ''),
- );
+ ];
$name = $config->getValue('dbname', 'owncloud');
if ($this->normalizeType($type) === 'sqlite3') {
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\SchemaConfig;
use Doctrine\DBAL\Platforms\MySqlPlatform;
+use Doctrine\DBAL\Schema\Schema;
use OCP\IConfig;
class MDB2SchemaReader {
/**
* @param string $file
- * @return \Doctrine\DBAL\Schema\Schema
+ * @return Schema
* @throws \DomainException
*/
public function loadSchemaFromFile($file) {
) {
$options['primary'] = true;
}
+
$table->addColumn($name, $type, $options);
if (!empty($options['primary']) && $options['primary']) {
$table->setPrimaryKey(array($name));
$this->random = $random;
}
- static $dbSetupClasses = array(
- 'mysql' => '\OC\Setup\MySQL',
- 'pgsql' => '\OC\Setup\PostgreSQL',
- 'oci' => '\OC\Setup\OCI',
- 'sqlite' => '\OC\Setup\Sqlite',
- 'sqlite3' => '\OC\Setup\Sqlite',
- );
+ static $dbSetupClasses = [
+ 'mysql' => \OC\Setup\MySQL::class,
+ 'pgsql' => \OC\Setup\PostgreSQL::class,
+ 'oci' => \OC\Setup\OCI::class,
+ 'sqlite' => \OC\Setup\Sqlite::class,
+ 'sqlite3' => \OC\Setup\Sqlite::class,
+ ];
/**
* Wrapper around the "class_exists" PHP function to be able to mock it
namespace Test\DB;
use Doctrine\DBAL\Platforms\MySqlPlatform;
+use Doctrine\DBAL\Schema\Schema;
+use OC\DB\MDB2SchemaReader;
+use OCP\IConfig;
+use Test\TestCase;
-class MDB2SchemaReaderTest extends \Test\TestCase {
+/**
+ * Class MDB2SchemaReaderTest
+ *
+ * @group DB
+ *
+ * @package Test\DB
+ */
+class MDB2SchemaReaderTest extends TestCase {
/**
- * @var \OC\DB\MDB2SchemaReader $reader
+ * @var MDB2SchemaReader $reader
*/
protected $reader;
/**
- * @return \OC\Config
+ * @return IConfig
*/
protected function getConfig() {
- $config = $this->getMockBuilder('\OCP\IConfig')
+ /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject $config */
+ $config = $this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock();
$config->expects($this->any())
}
public function testRead() {
- $reader = new \OC\DB\MDB2SchemaReader($this->getConfig(), new MySqlPlatform());
+ $reader = new MDB2SchemaReader($this->getConfig(), new MySqlPlatform());
$schema = $reader->loadSchemaFromFile(__DIR__ . '/testschema.xml');
$this->assertCount(1, $schema->getTables());