@@ -31,41 +31,41 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class PgSqlTools { |
| 33 | 33 | |
| 34 | - /** @var \OCP\IConfig */ |
|
| 35 | - private $config; |
|
| 34 | + /** @var \OCP\IConfig */ |
|
| 35 | + private $config; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param \OCP\IConfig $config |
|
| 39 | - */ |
|
| 40 | - public function __construct(IConfig $config) { |
|
| 41 | - $this->config = $config; |
|
| 42 | - } |
|
| 37 | + /** |
|
| 38 | + * @param \OCP\IConfig $config |
|
| 39 | + */ |
|
| 40 | + public function __construct(IConfig $config) { |
|
| 41 | + $this->config = $config; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @brief Resynchronizes all sequences of a database after using INSERTs |
|
| 46 | - * without leaving out the auto-incremented column. |
|
| 47 | - * @param \OC\DB\Connection $conn |
|
| 48 | - * @return null |
|
| 49 | - */ |
|
| 50 | - public function resynchronizeDatabaseSequences(Connection $conn) { |
|
| 51 | - $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 52 | - $databaseName = $conn->getDatabase(); |
|
| 53 | - $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 44 | + /** |
|
| 45 | + * @brief Resynchronizes all sequences of a database after using INSERTs |
|
| 46 | + * without leaving out the auto-incremented column. |
|
| 47 | + * @param \OC\DB\Connection $conn |
|
| 48 | + * @return null |
|
| 49 | + */ |
|
| 50 | + public function resynchronizeDatabaseSequences(Connection $conn) { |
|
| 51 | + $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 52 | + $databaseName = $conn->getDatabase(); |
|
| 53 | + $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 54 | 54 | |
| 55 | - foreach ($conn->getSchemaManager()->listSequences() as $sequence) { |
|
| 56 | - $sequenceName = $sequence->getName(); |
|
| 57 | - $sqlInfo = 'SELECT table_schema, table_name, column_name |
|
| 55 | + foreach ($conn->getSchemaManager()->listSequences() as $sequence) { |
|
| 56 | + $sequenceName = $sequence->getName(); |
|
| 57 | + $sqlInfo = 'SELECT table_schema, table_name, column_name |
|
| 58 | 58 | FROM information_schema.columns |
| 59 | 59 | WHERE column_default = ? AND table_catalog = ?'; |
| 60 | - $sequenceInfo = $conn->fetchAssoc($sqlInfo, array( |
|
| 61 | - "nextval('$sequenceName'::regclass)", |
|
| 62 | - $databaseName |
|
| 63 | - )); |
|
| 64 | - $tableName = $sequenceInfo['table_name']; |
|
| 65 | - $columnName = $sequenceInfo['column_name']; |
|
| 66 | - $sqlMaxId = "SELECT MAX($columnName) FROM $tableName"; |
|
| 67 | - $sqlSetval = "SELECT setval('$sequenceName', ($sqlMaxId))"; |
|
| 68 | - $conn->executeQuery($sqlSetval); |
|
| 69 | - } |
|
| 70 | - } |
|
| 60 | + $sequenceInfo = $conn->fetchAssoc($sqlInfo, array( |
|
| 61 | + "nextval('$sequenceName'::regclass)", |
|
| 62 | + $databaseName |
|
| 63 | + )); |
|
| 64 | + $tableName = $sequenceInfo['table_name']; |
|
| 65 | + $columnName = $sequenceInfo['column_name']; |
|
| 66 | + $sqlMaxId = "SELECT MAX($columnName) FROM $tableName"; |
|
| 67 | + $sqlSetval = "SELECT setval('$sequenceName', ($sqlMaxId))"; |
|
| 68 | + $conn->executeQuery($sqlSetval); |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | * @return null |
| 49 | 49 | */ |
| 50 | 50 | public function resynchronizeDatabaseSequences(Connection $conn) { |
| 51 | - $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 51 | + $filterExpression = '/^'.preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')).'/'; |
|
| 52 | 52 | $databaseName = $conn->getDatabase(); |
| 53 | 53 | $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
| 54 | 54 | |
@@ -25,32 +25,32 @@ |
||
| 25 | 25 | use Doctrine\DBAL\Schema\Schema; |
| 26 | 26 | |
| 27 | 27 | class PostgreSqlMigrator extends Migrator { |
| 28 | - /** |
|
| 29 | - * @param Schema $targetSchema |
|
| 30 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 31 | - * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 32 | - */ |
|
| 33 | - protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 34 | - $schemaDiff = parent::getDiff($targetSchema, $connection); |
|
| 28 | + /** |
|
| 29 | + * @param Schema $targetSchema |
|
| 30 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 31 | + * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 32 | + */ |
|
| 33 | + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 34 | + $schemaDiff = parent::getDiff($targetSchema, $connection); |
|
| 35 | 35 | |
| 36 | - foreach ($schemaDiff->changedTables as $tableDiff) { |
|
| 37 | - // fix default value in brackets - pg 9.4 is returning a negative default value in () |
|
| 38 | - // see https://github.com/doctrine/dbal/issues/2427 |
|
| 39 | - foreach ($tableDiff->changedColumns as $column) { |
|
| 40 | - $column->changedProperties = array_filter($column->changedProperties, function ($changedProperties) use ($column) { |
|
| 41 | - if ($changedProperties !== 'default') { |
|
| 42 | - return true; |
|
| 43 | - } |
|
| 44 | - $fromDefault = $column->fromColumn->getDefault(); |
|
| 45 | - $toDefault = $column->column->getDefault(); |
|
| 46 | - $fromDefault = trim($fromDefault, "()"); |
|
| 36 | + foreach ($schemaDiff->changedTables as $tableDiff) { |
|
| 37 | + // fix default value in brackets - pg 9.4 is returning a negative default value in () |
|
| 38 | + // see https://github.com/doctrine/dbal/issues/2427 |
|
| 39 | + foreach ($tableDiff->changedColumns as $column) { |
|
| 40 | + $column->changedProperties = array_filter($column->changedProperties, function ($changedProperties) use ($column) { |
|
| 41 | + if ($changedProperties !== 'default') { |
|
| 42 | + return true; |
|
| 43 | + } |
|
| 44 | + $fromDefault = $column->fromColumn->getDefault(); |
|
| 45 | + $toDefault = $column->column->getDefault(); |
|
| 46 | + $fromDefault = trim($fromDefault, "()"); |
|
| 47 | 47 | |
| 48 | - // by intention usage of != |
|
| 49 | - return $fromDefault != $toDefault; |
|
| 50 | - }); |
|
| 51 | - } |
|
| 52 | - } |
|
| 48 | + // by intention usage of != |
|
| 49 | + return $fromDefault != $toDefault; |
|
| 50 | + }); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - return $schemaDiff; |
|
| 55 | - } |
|
| 54 | + return $schemaDiff; |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -37,7 +37,7 @@ |
||
| 37 | 37 | // fix default value in brackets - pg 9.4 is returning a negative default value in () |
| 38 | 38 | // see https://github.com/doctrine/dbal/issues/2427 |
| 39 | 39 | foreach ($tableDiff->changedColumns as $column) { |
| 40 | - $column->changedProperties = array_filter($column->changedProperties, function ($changedProperties) use ($column) { |
|
| 40 | + $column->changedProperties = array_filter($column->changedProperties, function($changedProperties) use ($column) { |
|
| 41 | 41 | if ($changedProperties !== 'default') { |
| 42 | 42 | return true; |
| 43 | 43 | } |
@@ -26,69 +26,69 @@ |
||
| 26 | 26 | namespace OC\DB; |
| 27 | 27 | |
| 28 | 28 | class OracleConnection extends Connection { |
| 29 | - /** |
|
| 30 | - * Quote the keys of the array |
|
| 31 | - */ |
|
| 32 | - private function quoteKeys(array $data) { |
|
| 33 | - $return = array(); |
|
| 34 | - foreach($data as $key => $value) { |
|
| 35 | - $return[$this->quoteIdentifier($key)] = $value; |
|
| 36 | - } |
|
| 37 | - return $return; |
|
| 38 | - } |
|
| 29 | + /** |
|
| 30 | + * Quote the keys of the array |
|
| 31 | + */ |
|
| 32 | + private function quoteKeys(array $data) { |
|
| 33 | + $return = array(); |
|
| 34 | + foreach($data as $key => $value) { |
|
| 35 | + $return[$this->quoteIdentifier($key)] = $value; |
|
| 36 | + } |
|
| 37 | + return $return; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * {@inheritDoc} |
|
| 42 | - */ |
|
| 43 | - public function insert($tableName, array $data, array $types = array()) { |
|
| 44 | - $tableName = $this->quoteIdentifier($tableName); |
|
| 45 | - $data = $this->quoteKeys($data); |
|
| 46 | - return parent::insert($tableName, $data, $types); |
|
| 47 | - } |
|
| 40 | + /** |
|
| 41 | + * {@inheritDoc} |
|
| 42 | + */ |
|
| 43 | + public function insert($tableName, array $data, array $types = array()) { |
|
| 44 | + $tableName = $this->quoteIdentifier($tableName); |
|
| 45 | + $data = $this->quoteKeys($data); |
|
| 46 | + return parent::insert($tableName, $data, $types); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * {@inheritDoc} |
|
| 51 | - */ |
|
| 52 | - public function update($tableName, array $data, array $identifier, array $types = array()) { |
|
| 53 | - $tableName = $this->quoteIdentifier($tableName); |
|
| 54 | - $data = $this->quoteKeys($data); |
|
| 55 | - $identifier = $this->quoteKeys($identifier); |
|
| 56 | - return parent::update($tableName, $data, $identifier, $types); |
|
| 57 | - } |
|
| 49 | + /** |
|
| 50 | + * {@inheritDoc} |
|
| 51 | + */ |
|
| 52 | + public function update($tableName, array $data, array $identifier, array $types = array()) { |
|
| 53 | + $tableName = $this->quoteIdentifier($tableName); |
|
| 54 | + $data = $this->quoteKeys($data); |
|
| 55 | + $identifier = $this->quoteKeys($identifier); |
|
| 56 | + return parent::update($tableName, $data, $identifier, $types); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * {@inheritDoc} |
|
| 61 | - */ |
|
| 62 | - public function delete($tableExpression, array $identifier, array $types = array()) { |
|
| 63 | - $tableName = $this->quoteIdentifier($tableExpression); |
|
| 64 | - $identifier = $this->quoteKeys($identifier); |
|
| 65 | - return parent::delete($tableName, $identifier); |
|
| 66 | - } |
|
| 59 | + /** |
|
| 60 | + * {@inheritDoc} |
|
| 61 | + */ |
|
| 62 | + public function delete($tableExpression, array $identifier, array $types = array()) { |
|
| 63 | + $tableName = $this->quoteIdentifier($tableExpression); |
|
| 64 | + $identifier = $this->quoteKeys($identifier); |
|
| 65 | + return parent::delete($tableName, $identifier); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Drop a table from the database if it exists |
|
| 70 | - * |
|
| 71 | - * @param string $table table name without the prefix |
|
| 72 | - */ |
|
| 73 | - public function dropTable($table) { |
|
| 74 | - $table = $this->tablePrefix . trim($table); |
|
| 75 | - $table = $this->quoteIdentifier($table); |
|
| 76 | - $schema = $this->getSchemaManager(); |
|
| 77 | - if($schema->tablesExist(array($table))) { |
|
| 78 | - $schema->dropTable($table); |
|
| 79 | - } |
|
| 80 | - } |
|
| 68 | + /** |
|
| 69 | + * Drop a table from the database if it exists |
|
| 70 | + * |
|
| 71 | + * @param string $table table name without the prefix |
|
| 72 | + */ |
|
| 73 | + public function dropTable($table) { |
|
| 74 | + $table = $this->tablePrefix . trim($table); |
|
| 75 | + $table = $this->quoteIdentifier($table); |
|
| 76 | + $schema = $this->getSchemaManager(); |
|
| 77 | + if($schema->tablesExist(array($table))) { |
|
| 78 | + $schema->dropTable($table); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Check if a table exists |
|
| 84 | - * |
|
| 85 | - * @param string $table table name without the prefix |
|
| 86 | - * @return bool |
|
| 87 | - */ |
|
| 88 | - public function tableExists($table){ |
|
| 89 | - $table = $this->tablePrefix . trim($table); |
|
| 90 | - $table = $this->quoteIdentifier($table); |
|
| 91 | - $schema = $this->getSchemaManager(); |
|
| 92 | - return $schema->tablesExist(array($table)); |
|
| 93 | - } |
|
| 82 | + /** |
|
| 83 | + * Check if a table exists |
|
| 84 | + * |
|
| 85 | + * @param string $table table name without the prefix |
|
| 86 | + * @return bool |
|
| 87 | + */ |
|
| 88 | + public function tableExists($table){ |
|
| 89 | + $table = $this->tablePrefix . trim($table); |
|
| 90 | + $table = $this->quoteIdentifier($table); |
|
| 91 | + $schema = $this->getSchemaManager(); |
|
| 92 | + return $schema->tablesExist(array($table)); |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | private function quoteKeys(array $data) { |
| 33 | 33 | $return = array(); |
| 34 | - foreach($data as $key => $value) { |
|
| 34 | + foreach ($data as $key => $value) { |
|
| 35 | 35 | $return[$this->quoteIdentifier($key)] = $value; |
| 36 | 36 | } |
| 37 | 37 | return $return; |
@@ -71,10 +71,10 @@ discard block |
||
| 71 | 71 | * @param string $table table name without the prefix |
| 72 | 72 | */ |
| 73 | 73 | public function dropTable($table) { |
| 74 | - $table = $this->tablePrefix . trim($table); |
|
| 74 | + $table = $this->tablePrefix.trim($table); |
|
| 75 | 75 | $table = $this->quoteIdentifier($table); |
| 76 | 76 | $schema = $this->getSchemaManager(); |
| 77 | - if($schema->tablesExist(array($table))) { |
|
| 77 | + if ($schema->tablesExist(array($table))) { |
|
| 78 | 78 | $schema->dropTable($table); |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -85,8 +85,8 @@ discard block |
||
| 85 | 85 | * @param string $table table name without the prefix |
| 86 | 86 | * @return bool |
| 87 | 87 | */ |
| 88 | - public function tableExists($table){ |
|
| 89 | - $table = $this->tablePrefix . trim($table); |
|
| 88 | + public function tableExists($table) { |
|
| 89 | + $table = $this->tablePrefix.trim($table); |
|
| 90 | 90 | $table = $this->quoteIdentifier($table); |
| 91 | 91 | $schema = $this->getSchemaManager(); |
| 92 | 92 | return $schema->tablesExist(array($table)); |
@@ -33,84 +33,84 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class Adapter { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var \OC\DB\Connection $conn |
|
| 38 | - */ |
|
| 39 | - protected $conn; |
|
| 36 | + /** |
|
| 37 | + * @var \OC\DB\Connection $conn |
|
| 38 | + */ |
|
| 39 | + protected $conn; |
|
| 40 | 40 | |
| 41 | - public function __construct($conn) { |
|
| 42 | - $this->conn = $conn; |
|
| 43 | - } |
|
| 41 | + public function __construct($conn) { |
|
| 42 | + $this->conn = $conn; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param string $table name |
|
| 47 | - * @return int id of last insert statement |
|
| 48 | - */ |
|
| 49 | - public function lastInsertId($table) { |
|
| 50 | - return $this->conn->realLastInsertId($table); |
|
| 51 | - } |
|
| 45 | + /** |
|
| 46 | + * @param string $table name |
|
| 47 | + * @return int id of last insert statement |
|
| 48 | + */ |
|
| 49 | + public function lastInsertId($table) { |
|
| 50 | + return $this->conn->realLastInsertId($table); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param string $statement that needs to be changed so the db can handle it |
|
| 55 | - * @return string changed statement |
|
| 56 | - */ |
|
| 57 | - public function fixupStatement($statement) { |
|
| 58 | - return $statement; |
|
| 59 | - } |
|
| 53 | + /** |
|
| 54 | + * @param string $statement that needs to be changed so the db can handle it |
|
| 55 | + * @return string changed statement |
|
| 56 | + */ |
|
| 57 | + public function fixupStatement($statement) { |
|
| 58 | + return $statement; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Create an exclusive read+write lock on a table |
|
| 63 | - * |
|
| 64 | - * @param string $tableName |
|
| 65 | - * @since 9.1.0 |
|
| 66 | - */ |
|
| 67 | - public function lockTable($tableName) { |
|
| 68 | - $this->conn->beginTransaction(); |
|
| 69 | - $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
| 70 | - } |
|
| 61 | + /** |
|
| 62 | + * Create an exclusive read+write lock on a table |
|
| 63 | + * |
|
| 64 | + * @param string $tableName |
|
| 65 | + * @since 9.1.0 |
|
| 66 | + */ |
|
| 67 | + public function lockTable($tableName) { |
|
| 68 | + $this->conn->beginTransaction(); |
|
| 69 | + $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Release a previous acquired lock again |
|
| 74 | - * |
|
| 75 | - * @since 9.1.0 |
|
| 76 | - */ |
|
| 77 | - public function unlockTable() { |
|
| 78 | - $this->conn->commit(); |
|
| 79 | - } |
|
| 72 | + /** |
|
| 73 | + * Release a previous acquired lock again |
|
| 74 | + * |
|
| 75 | + * @since 9.1.0 |
|
| 76 | + */ |
|
| 77 | + public function unlockTable() { |
|
| 78 | + $this->conn->commit(); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Insert a row if the matching row does not exists. |
|
| 83 | - * |
|
| 84 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
| 85 | - * @param array $input data that should be inserted into the table (column name => value) |
|
| 86 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
| 87 | - * If this is null or an empty array, all keys of $input will be compared |
|
| 88 | - * Please note: text fields (clob) must not be used in the compare array |
|
| 89 | - * @return int number of inserted rows |
|
| 90 | - * @throws \Doctrine\DBAL\DBALException |
|
| 91 | - */ |
|
| 92 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
| 93 | - if (empty($compare)) { |
|
| 94 | - $compare = array_keys($input); |
|
| 95 | - } |
|
| 96 | - $query = 'INSERT INTO `' .$table . '` (`' |
|
| 97 | - . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
| 98 | - . str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative? |
|
| 99 | - . 'FROM `' . $table . '` WHERE '; |
|
| 81 | + /** |
|
| 82 | + * Insert a row if the matching row does not exists. |
|
| 83 | + * |
|
| 84 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
| 85 | + * @param array $input data that should be inserted into the table (column name => value) |
|
| 86 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
| 87 | + * If this is null or an empty array, all keys of $input will be compared |
|
| 88 | + * Please note: text fields (clob) must not be used in the compare array |
|
| 89 | + * @return int number of inserted rows |
|
| 90 | + * @throws \Doctrine\DBAL\DBALException |
|
| 91 | + */ |
|
| 92 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
| 93 | + if (empty($compare)) { |
|
| 94 | + $compare = array_keys($input); |
|
| 95 | + } |
|
| 96 | + $query = 'INSERT INTO `' .$table . '` (`' |
|
| 97 | + . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
| 98 | + . str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative? |
|
| 99 | + . 'FROM `' . $table . '` WHERE '; |
|
| 100 | 100 | |
| 101 | - $inserts = array_values($input); |
|
| 102 | - foreach($compare as $key) { |
|
| 103 | - $query .= '`' . $key . '`'; |
|
| 104 | - if (is_null($input[$key])) { |
|
| 105 | - $query .= ' IS NULL AND '; |
|
| 106 | - } else { |
|
| 107 | - $inserts[] = $input[$key]; |
|
| 108 | - $query .= ' = ? AND '; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - $query = substr($query, 0, strlen($query) - 5); |
|
| 112 | - $query .= ' HAVING COUNT(*) = 0'; |
|
| 101 | + $inserts = array_values($input); |
|
| 102 | + foreach($compare as $key) { |
|
| 103 | + $query .= '`' . $key . '`'; |
|
| 104 | + if (is_null($input[$key])) { |
|
| 105 | + $query .= ' IS NULL AND '; |
|
| 106 | + } else { |
|
| 107 | + $inserts[] = $input[$key]; |
|
| 108 | + $query .= ' = ? AND '; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + $query = substr($query, 0, strlen($query) - 5); |
|
| 112 | + $query .= ' HAVING COUNT(*) = 0'; |
|
| 113 | 113 | |
| 114 | - return $this->conn->executeUpdate($query, $inserts); |
|
| 115 | - } |
|
| 114 | + return $this->conn->executeUpdate($query, $inserts); |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function lockTable($tableName) { |
| 68 | 68 | $this->conn->beginTransaction(); |
| 69 | - $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
| 69 | + $this->conn->executeUpdate('LOCK TABLE `'.$tableName.'` IN EXCLUSIVE MODE'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | if (empty($compare)) { |
| 94 | 94 | $compare = array_keys($input); |
| 95 | 95 | } |
| 96 | - $query = 'INSERT INTO `' .$table . '` (`' |
|
| 97 | - . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
| 98 | - . str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative? |
|
| 99 | - . 'FROM `' . $table . '` WHERE '; |
|
| 96 | + $query = 'INSERT INTO `'.$table.'` (`' |
|
| 97 | + . implode('`,`', array_keys($input)).'`) SELECT ' |
|
| 98 | + . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
|
| 99 | + . 'FROM `'.$table.'` WHERE '; |
|
| 100 | 100 | |
| 101 | 101 | $inserts = array_values($input); |
| 102 | - foreach($compare as $key) { |
|
| 103 | - $query .= '`' . $key . '`'; |
|
| 102 | + foreach ($compare as $key) { |
|
| 103 | + $query .= '`'.$key.'`'; |
|
| 104 | 104 | if (is_null($input[$key])) { |
| 105 | 105 | $query .= ' IS NULL AND '; |
| 106 | 106 | } else { |
@@ -31,9 +31,9 @@ |
||
| 31 | 31 | * @package OC\DB |
| 32 | 32 | */ |
| 33 | 33 | class NoCheckMigrator extends Migrator { |
| 34 | - /** |
|
| 35 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 36 | - * @throws \OC\DB\MigrationException |
|
| 37 | - */ |
|
| 38 | - public function checkMigrate(Schema $targetSchema) {} |
|
| 34 | + /** |
|
| 35 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 36 | + * @throws \OC\DB\MigrationException |
|
| 37 | + */ |
|
| 38 | + public function checkMigrate(Schema $targetSchema) {} |
|
| 39 | 39 | } |
@@ -29,38 +29,38 @@ |
||
| 29 | 29 | use Doctrine\Common\EventSubscriber; |
| 30 | 30 | |
| 31 | 31 | class SQLiteSessionInit implements EventSubscriber { |
| 32 | - /** |
|
| 33 | - * @var bool |
|
| 34 | - */ |
|
| 35 | - private $caseSensitiveLike; |
|
| 32 | + /** |
|
| 33 | + * @var bool |
|
| 34 | + */ |
|
| 35 | + private $caseSensitiveLike; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - private $journalMode; |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + private $journalMode; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Configure case sensitive like for each connection |
|
| 44 | - * |
|
| 45 | - * @param bool $caseSensitiveLike |
|
| 46 | - * @param string $journalMode |
|
| 47 | - */ |
|
| 48 | - public function __construct($caseSensitiveLike, $journalMode) { |
|
| 49 | - $this->caseSensitiveLike = $caseSensitiveLike; |
|
| 50 | - $this->journalMode = $journalMode; |
|
| 51 | - } |
|
| 42 | + /** |
|
| 43 | + * Configure case sensitive like for each connection |
|
| 44 | + * |
|
| 45 | + * @param bool $caseSensitiveLike |
|
| 46 | + * @param string $journalMode |
|
| 47 | + */ |
|
| 48 | + public function __construct($caseSensitiveLike, $journalMode) { |
|
| 49 | + $this->caseSensitiveLike = $caseSensitiveLike; |
|
| 50 | + $this->journalMode = $journalMode; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param ConnectionEventArgs $args |
|
| 55 | - * @return void |
|
| 56 | - */ |
|
| 57 | - public function postConnect(ConnectionEventArgs $args) { |
|
| 58 | - $sensitive = ($this->caseSensitiveLike) ? 'true' : 'false'; |
|
| 59 | - $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive); |
|
| 60 | - $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode); |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * @param ConnectionEventArgs $args |
|
| 55 | + * @return void |
|
| 56 | + */ |
|
| 57 | + public function postConnect(ConnectionEventArgs $args) { |
|
| 58 | + $sensitive = ($this->caseSensitiveLike) ? 'true' : 'false'; |
|
| 59 | + $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive); |
|
| 60 | + $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function getSubscribedEvents() { |
|
| 64 | - return array(Events::postConnect); |
|
| 65 | - } |
|
| 63 | + public function getSubscribedEvents() { |
|
| 64 | + return array(Events::postConnect); |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -56,8 +56,8 @@ |
||
| 56 | 56 | */ |
| 57 | 57 | public function postConnect(ConnectionEventArgs $args) { |
| 58 | 58 | $sensitive = ($this->caseSensitiveLike) ? 'true' : 'false'; |
| 59 | - $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = ' . $sensitive); |
|
| 60 | - $args->getConnection()->executeUpdate('PRAGMA journal_mode = ' . $this->journalMode); |
|
| 59 | + $args->getConnection()->executeUpdate('PRAGMA case_sensitive_like = '.$sensitive); |
|
| 60 | + $args->getConnection()->executeUpdate('PRAGMA journal_mode = '.$this->journalMode); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public function getSubscribedEvents() { |
@@ -25,17 +25,17 @@ |
||
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | class MigrationException extends \Exception { |
| 28 | - private $table; |
|
| 28 | + private $table; |
|
| 29 | 29 | |
| 30 | - public function __construct($table, $message) { |
|
| 31 | - $this->table = $table; |
|
| 32 | - parent::__construct($message); |
|
| 33 | - } |
|
| 30 | + public function __construct($table, $message) { |
|
| 31 | + $this->table = $table; |
|
| 32 | + parent::__construct($message); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function getTable() { |
|
| 39 | - return $this->table; |
|
| 40 | - } |
|
| 35 | + /** |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function getTable() { |
|
| 39 | + return $this->table; |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -116,8 +116,7 @@ discard block |
||
| 116 | 116 | $length = '4'; |
| 117 | 117 | if ($column->getType() == 'SmallInt') { |
| 118 | 118 | $length = '2'; |
| 119 | - } |
|
| 120 | - elseif ($column->getType() == 'BigInt') { |
|
| 119 | + } elseif ($column->getType() == 'BigInt') { |
|
| 121 | 120 | $length = '8'; |
| 122 | 121 | } |
| 123 | 122 | $xml->addChild('length', $length); |
@@ -165,8 +164,7 @@ discard block |
||
| 165 | 164 | $xml->addChild('name', $index->getName()); |
| 166 | 165 | if ($index->isPrimary()) { |
| 167 | 166 | $xml->addChild('primary', 'true'); |
| 168 | - } |
|
| 169 | - elseif ($index->isUnique()) { |
|
| 167 | + } elseif ($index->isUnique()) { |
|
| 170 | 168 | $xml->addChild('unique', 'true'); |
| 171 | 169 | } |
| 172 | 170 | foreach($index->getColumns() as $column) { |
@@ -31,149 +31,149 @@ |
||
| 31 | 31 | |
| 32 | 32 | class MDB2SchemaWriter { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param string $file |
|
| 36 | - * @param \OC\DB\Connection $conn |
|
| 37 | - * @return bool |
|
| 38 | - */ |
|
| 39 | - static public function saveSchemaToFile($file, \OC\DB\Connection $conn) { |
|
| 40 | - $config = \OC::$server->getConfig(); |
|
| 34 | + /** |
|
| 35 | + * @param string $file |
|
| 36 | + * @param \OC\DB\Connection $conn |
|
| 37 | + * @return bool |
|
| 38 | + */ |
|
| 39 | + static public function saveSchemaToFile($file, \OC\DB\Connection $conn) { |
|
| 40 | + $config = \OC::$server->getConfig(); |
|
| 41 | 41 | |
| 42 | - $xml = new \SimpleXMLElement('<database/>'); |
|
| 43 | - $xml->addChild('name', $config->getSystemValue('dbname', 'owncloud')); |
|
| 44 | - $xml->addChild('create', 'true'); |
|
| 45 | - $xml->addChild('overwrite', 'false'); |
|
| 46 | - $xml->addChild('charset', 'utf8'); |
|
| 42 | + $xml = new \SimpleXMLElement('<database/>'); |
|
| 43 | + $xml->addChild('name', $config->getSystemValue('dbname', 'owncloud')); |
|
| 44 | + $xml->addChild('create', 'true'); |
|
| 45 | + $xml->addChild('overwrite', 'false'); |
|
| 46 | + $xml->addChild('charset', 'utf8'); |
|
| 47 | 47 | |
| 48 | - // FIX ME: bloody work around |
|
| 49 | - if ($config->getSystemValue('dbtype', 'sqlite') === 'oci') { |
|
| 50 | - $filterExpression = '/^"' . preg_quote($conn->getPrefix()) . '/'; |
|
| 51 | - } else { |
|
| 52 | - $filterExpression = '/^' . preg_quote($conn->getPrefix()) . '/'; |
|
| 53 | - } |
|
| 54 | - $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 48 | + // FIX ME: bloody work around |
|
| 49 | + if ($config->getSystemValue('dbtype', 'sqlite') === 'oci') { |
|
| 50 | + $filterExpression = '/^"' . preg_quote($conn->getPrefix()) . '/'; |
|
| 51 | + } else { |
|
| 52 | + $filterExpression = '/^' . preg_quote($conn->getPrefix()) . '/'; |
|
| 53 | + } |
|
| 54 | + $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 55 | 55 | |
| 56 | - foreach ($conn->getSchemaManager()->listTables() as $table) { |
|
| 57 | - self::saveTable($table, $xml->addChild('table')); |
|
| 58 | - } |
|
| 59 | - file_put_contents($file, $xml->asXML()); |
|
| 60 | - return true; |
|
| 61 | - } |
|
| 56 | + foreach ($conn->getSchemaManager()->listTables() as $table) { |
|
| 57 | + self::saveTable($table, $xml->addChild('table')); |
|
| 58 | + } |
|
| 59 | + file_put_contents($file, $xml->asXML()); |
|
| 60 | + return true; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
| 65 | - * @param \SimpleXMLElement $xml |
|
| 66 | - */ |
|
| 67 | - private static function saveTable($table, $xml) { |
|
| 68 | - $xml->addChild('name', $table->getName()); |
|
| 69 | - $declaration = $xml->addChild('declaration'); |
|
| 70 | - foreach($table->getColumns() as $column) { |
|
| 71 | - self::saveColumn($column, $declaration->addChild('field')); |
|
| 72 | - } |
|
| 73 | - foreach($table->getIndexes() as $index) { |
|
| 74 | - if ($index->getName() == 'PRIMARY') { |
|
| 75 | - $autoincrement = false; |
|
| 76 | - foreach($index->getColumns() as $column) { |
|
| 77 | - if ($table->getColumn($column)->getAutoincrement()) { |
|
| 78 | - $autoincrement = true; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - if ($autoincrement) { |
|
| 82 | - continue; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - self::saveIndex($index, $declaration->addChild('index')); |
|
| 86 | - } |
|
| 87 | - } |
|
| 63 | + /** |
|
| 64 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
| 65 | + * @param \SimpleXMLElement $xml |
|
| 66 | + */ |
|
| 67 | + private static function saveTable($table, $xml) { |
|
| 68 | + $xml->addChild('name', $table->getName()); |
|
| 69 | + $declaration = $xml->addChild('declaration'); |
|
| 70 | + foreach($table->getColumns() as $column) { |
|
| 71 | + self::saveColumn($column, $declaration->addChild('field')); |
|
| 72 | + } |
|
| 73 | + foreach($table->getIndexes() as $index) { |
|
| 74 | + if ($index->getName() == 'PRIMARY') { |
|
| 75 | + $autoincrement = false; |
|
| 76 | + foreach($index->getColumns() as $column) { |
|
| 77 | + if ($table->getColumn($column)->getAutoincrement()) { |
|
| 78 | + $autoincrement = true; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + if ($autoincrement) { |
|
| 82 | + continue; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + self::saveIndex($index, $declaration->addChild('index')); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @param Column $column |
|
| 91 | - * @param \SimpleXMLElement $xml |
|
| 92 | - */ |
|
| 93 | - private static function saveColumn($column, $xml) { |
|
| 94 | - $xml->addChild('name', $column->getName()); |
|
| 95 | - switch($column->getType()) { |
|
| 96 | - case 'SmallInt': |
|
| 97 | - case 'Integer': |
|
| 98 | - case 'BigInt': |
|
| 99 | - $xml->addChild('type', 'integer'); |
|
| 100 | - $default = $column->getDefault(); |
|
| 101 | - if (is_null($default) && $column->getAutoincrement()) { |
|
| 102 | - $default = '0'; |
|
| 103 | - } |
|
| 104 | - $xml->addChild('default', $default); |
|
| 105 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 106 | - if ($column->getAutoincrement()) { |
|
| 107 | - $xml->addChild('autoincrement', '1'); |
|
| 108 | - } |
|
| 109 | - if ($column->getUnsigned()) { |
|
| 110 | - $xml->addChild('unsigned', 'true'); |
|
| 111 | - } |
|
| 112 | - $length = '4'; |
|
| 113 | - if ($column->getType() == 'SmallInt') { |
|
| 114 | - $length = '2'; |
|
| 115 | - } |
|
| 116 | - elseif ($column->getType() == 'BigInt') { |
|
| 117 | - $length = '8'; |
|
| 118 | - } |
|
| 119 | - $xml->addChild('length', $length); |
|
| 120 | - break; |
|
| 121 | - case 'String': |
|
| 122 | - $xml->addChild('type', 'text'); |
|
| 123 | - $default = trim($column->getDefault()); |
|
| 124 | - if ($default === '') { |
|
| 125 | - $default = false; |
|
| 126 | - } |
|
| 127 | - $xml->addChild('default', $default); |
|
| 128 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 129 | - $xml->addChild('length', $column->getLength()); |
|
| 130 | - break; |
|
| 131 | - case 'Text': |
|
| 132 | - $xml->addChild('type', 'clob'); |
|
| 133 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 134 | - break; |
|
| 135 | - case 'Decimal': |
|
| 136 | - $xml->addChild('type', 'decimal'); |
|
| 137 | - $xml->addChild('default', $column->getDefault()); |
|
| 138 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 139 | - $xml->addChild('length', '15'); |
|
| 140 | - break; |
|
| 141 | - case 'Boolean': |
|
| 142 | - $xml->addChild('type', 'integer'); |
|
| 143 | - $xml->addChild('default', $column->getDefault()); |
|
| 144 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 145 | - $xml->addChild('length', '1'); |
|
| 146 | - break; |
|
| 147 | - case 'DateTime': |
|
| 148 | - $xml->addChild('type', 'timestamp'); |
|
| 149 | - $xml->addChild('default', $column->getDefault()); |
|
| 150 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 151 | - break; |
|
| 89 | + /** |
|
| 90 | + * @param Column $column |
|
| 91 | + * @param \SimpleXMLElement $xml |
|
| 92 | + */ |
|
| 93 | + private static function saveColumn($column, $xml) { |
|
| 94 | + $xml->addChild('name', $column->getName()); |
|
| 95 | + switch($column->getType()) { |
|
| 96 | + case 'SmallInt': |
|
| 97 | + case 'Integer': |
|
| 98 | + case 'BigInt': |
|
| 99 | + $xml->addChild('type', 'integer'); |
|
| 100 | + $default = $column->getDefault(); |
|
| 101 | + if (is_null($default) && $column->getAutoincrement()) { |
|
| 102 | + $default = '0'; |
|
| 103 | + } |
|
| 104 | + $xml->addChild('default', $default); |
|
| 105 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 106 | + if ($column->getAutoincrement()) { |
|
| 107 | + $xml->addChild('autoincrement', '1'); |
|
| 108 | + } |
|
| 109 | + if ($column->getUnsigned()) { |
|
| 110 | + $xml->addChild('unsigned', 'true'); |
|
| 111 | + } |
|
| 112 | + $length = '4'; |
|
| 113 | + if ($column->getType() == 'SmallInt') { |
|
| 114 | + $length = '2'; |
|
| 115 | + } |
|
| 116 | + elseif ($column->getType() == 'BigInt') { |
|
| 117 | + $length = '8'; |
|
| 118 | + } |
|
| 119 | + $xml->addChild('length', $length); |
|
| 120 | + break; |
|
| 121 | + case 'String': |
|
| 122 | + $xml->addChild('type', 'text'); |
|
| 123 | + $default = trim($column->getDefault()); |
|
| 124 | + if ($default === '') { |
|
| 125 | + $default = false; |
|
| 126 | + } |
|
| 127 | + $xml->addChild('default', $default); |
|
| 128 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 129 | + $xml->addChild('length', $column->getLength()); |
|
| 130 | + break; |
|
| 131 | + case 'Text': |
|
| 132 | + $xml->addChild('type', 'clob'); |
|
| 133 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 134 | + break; |
|
| 135 | + case 'Decimal': |
|
| 136 | + $xml->addChild('type', 'decimal'); |
|
| 137 | + $xml->addChild('default', $column->getDefault()); |
|
| 138 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 139 | + $xml->addChild('length', '15'); |
|
| 140 | + break; |
|
| 141 | + case 'Boolean': |
|
| 142 | + $xml->addChild('type', 'integer'); |
|
| 143 | + $xml->addChild('default', $column->getDefault()); |
|
| 144 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 145 | + $xml->addChild('length', '1'); |
|
| 146 | + break; |
|
| 147 | + case 'DateTime': |
|
| 148 | + $xml->addChild('type', 'timestamp'); |
|
| 149 | + $xml->addChild('default', $column->getDefault()); |
|
| 150 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 151 | + break; |
|
| 152 | 152 | |
| 153 | - } |
|
| 154 | - } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @param Index $index |
|
| 158 | - * @param \SimpleXMLElement $xml |
|
| 159 | - */ |
|
| 160 | - private static function saveIndex($index, $xml) { |
|
| 161 | - $xml->addChild('name', $index->getName()); |
|
| 162 | - if ($index->isPrimary()) { |
|
| 163 | - $xml->addChild('primary', 'true'); |
|
| 164 | - } |
|
| 165 | - elseif ($index->isUnique()) { |
|
| 166 | - $xml->addChild('unique', 'true'); |
|
| 167 | - } |
|
| 168 | - foreach($index->getColumns() as $column) { |
|
| 169 | - $field = $xml->addChild('field'); |
|
| 170 | - $field->addChild('name', $column); |
|
| 171 | - $field->addChild('sorting', 'ascending'); |
|
| 156 | + /** |
|
| 157 | + * @param Index $index |
|
| 158 | + * @param \SimpleXMLElement $xml |
|
| 159 | + */ |
|
| 160 | + private static function saveIndex($index, $xml) { |
|
| 161 | + $xml->addChild('name', $index->getName()); |
|
| 162 | + if ($index->isPrimary()) { |
|
| 163 | + $xml->addChild('primary', 'true'); |
|
| 164 | + } |
|
| 165 | + elseif ($index->isUnique()) { |
|
| 166 | + $xml->addChild('unique', 'true'); |
|
| 167 | + } |
|
| 168 | + foreach($index->getColumns() as $column) { |
|
| 169 | + $field = $xml->addChild('field'); |
|
| 170 | + $field->addChild('name', $column); |
|
| 171 | + $field->addChild('sorting', 'ascending'); |
|
| 172 | 172 | |
| 173 | - } |
|
| 174 | - } |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - private static function toBool($bool) { |
|
| 177 | - return $bool ? 'true' : 'false'; |
|
| 178 | - } |
|
| 176 | + private static function toBool($bool) { |
|
| 177 | + return $bool ? 'true' : 'false'; |
|
| 178 | + } |
|
| 179 | 179 | } |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | // FIX ME: bloody work around |
| 49 | 49 | if ($config->getSystemValue('dbtype', 'sqlite') === 'oci') { |
| 50 | - $filterExpression = '/^"' . preg_quote($conn->getPrefix()) . '/'; |
|
| 50 | + $filterExpression = '/^"'.preg_quote($conn->getPrefix()).'/'; |
|
| 51 | 51 | } else { |
| 52 | - $filterExpression = '/^' . preg_quote($conn->getPrefix()) . '/'; |
|
| 52 | + $filterExpression = '/^'.preg_quote($conn->getPrefix()).'/'; |
|
| 53 | 53 | } |
| 54 | 54 | $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
| 55 | 55 | |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | private static function saveTable($table, $xml) { |
| 68 | 68 | $xml->addChild('name', $table->getName()); |
| 69 | 69 | $declaration = $xml->addChild('declaration'); |
| 70 | - foreach($table->getColumns() as $column) { |
|
| 70 | + foreach ($table->getColumns() as $column) { |
|
| 71 | 71 | self::saveColumn($column, $declaration->addChild('field')); |
| 72 | 72 | } |
| 73 | - foreach($table->getIndexes() as $index) { |
|
| 73 | + foreach ($table->getIndexes() as $index) { |
|
| 74 | 74 | if ($index->getName() == 'PRIMARY') { |
| 75 | 75 | $autoincrement = false; |
| 76 | - foreach($index->getColumns() as $column) { |
|
| 76 | + foreach ($index->getColumns() as $column) { |
|
| 77 | 77 | if ($table->getColumn($column)->getAutoincrement()) { |
| 78 | 78 | $autoincrement = true; |
| 79 | 79 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | private static function saveColumn($column, $xml) { |
| 94 | 94 | $xml->addChild('name', $column->getName()); |
| 95 | - switch($column->getType()) { |
|
| 95 | + switch ($column->getType()) { |
|
| 96 | 96 | case 'SmallInt': |
| 97 | 97 | case 'Integer': |
| 98 | 98 | case 'BigInt': |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | elseif ($index->isUnique()) { |
| 166 | 166 | $xml->addChild('unique', 'true'); |
| 167 | 167 | } |
| 168 | - foreach($index->getColumns() as $column) { |
|
| 168 | + foreach ($index->getColumns() as $column) { |
|
| 169 | 169 | $field = $xml->addChild('field'); |
| 170 | 170 | $field->addChild('name', $column); |
| 171 | 171 | $field->addChild('sorting', 'ascending'); |
@@ -28,54 +28,54 @@ |
||
| 28 | 28 | use Doctrine\DBAL\Schema\Schema; |
| 29 | 29 | |
| 30 | 30 | class OracleMigrator extends NoCheckMigrator { |
| 31 | - /** |
|
| 32 | - * @param Schema $targetSchema |
|
| 33 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 34 | - * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 35 | - */ |
|
| 36 | - protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 37 | - $schemaDiff = parent::getDiff($targetSchema, $connection); |
|
| 31 | + /** |
|
| 32 | + * @param Schema $targetSchema |
|
| 33 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 34 | + * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 35 | + */ |
|
| 36 | + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 37 | + $schemaDiff = parent::getDiff($targetSchema, $connection); |
|
| 38 | 38 | |
| 39 | - // oracle forces us to quote the identifiers |
|
| 40 | - foreach ($schemaDiff->changedTables as $tableDiff) { |
|
| 41 | - $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); |
|
| 42 | - foreach ($tableDiff->changedColumns as $column) { |
|
| 43 | - $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); |
|
| 44 | - // auto increment is not relevant for oracle and can anyhow not be applied on change |
|
| 45 | - $column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']); |
|
| 46 | - } |
|
| 47 | - $tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) { |
|
| 48 | - return count($column->changedProperties) > 0; |
|
| 49 | - }); |
|
| 50 | - } |
|
| 39 | + // oracle forces us to quote the identifiers |
|
| 40 | + foreach ($schemaDiff->changedTables as $tableDiff) { |
|
| 41 | + $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); |
|
| 42 | + foreach ($tableDiff->changedColumns as $column) { |
|
| 43 | + $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); |
|
| 44 | + // auto increment is not relevant for oracle and can anyhow not be applied on change |
|
| 45 | + $column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']); |
|
| 46 | + } |
|
| 47 | + $tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) { |
|
| 48 | + return count($column->changedProperties) > 0; |
|
| 49 | + }); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - return $schemaDiff; |
|
| 53 | - } |
|
| 52 | + return $schemaDiff; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param string $name |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - protected function generateTemporaryTableName($name) { |
|
| 60 | - return 'oc_' . uniqid(); |
|
| 61 | - } |
|
| 55 | + /** |
|
| 56 | + * @param string $name |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + protected function generateTemporaryTableName($name) { |
|
| 60 | + return 'oc_' . uniqid(); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @param $statement |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - protected function convertStatementToScript($statement) { |
|
| 68 | - if (substr($statement, -1) === ';') { |
|
| 69 | - return $statement . PHP_EOL . '/' . PHP_EOL; |
|
| 70 | - } |
|
| 71 | - $script = $statement . ';'; |
|
| 72 | - $script .= PHP_EOL; |
|
| 73 | - $script .= PHP_EOL; |
|
| 74 | - return $script; |
|
| 75 | - } |
|
| 63 | + /** |
|
| 64 | + * @param $statement |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + protected function convertStatementToScript($statement) { |
|
| 68 | + if (substr($statement, -1) === ';') { |
|
| 69 | + return $statement . PHP_EOL . '/' . PHP_EOL; |
|
| 70 | + } |
|
| 71 | + $script = $statement . ';'; |
|
| 72 | + $script .= PHP_EOL; |
|
| 73 | + $script .= PHP_EOL; |
|
| 74 | + return $script; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - protected function getFilterExpression() { |
|
| 78 | - return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 79 | - } |
|
| 77 | + protected function getFilterExpression() { |
|
| 78 | + return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | // auto increment is not relevant for oracle and can anyhow not be applied on change |
| 45 | 45 | $column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']); |
| 46 | 46 | } |
| 47 | - $tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) { |
|
| 47 | + $tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function(ColumnDiff $column) { |
|
| 48 | 48 | return count($column->changedProperties) > 0; |
| 49 | 49 | }); |
| 50 | 50 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @return string |
| 58 | 58 | */ |
| 59 | 59 | protected function generateTemporaryTableName($name) { |
| 60 | - return 'oc_' . uniqid(); |
|
| 60 | + return 'oc_'.uniqid(); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | protected function convertStatementToScript($statement) { |
| 68 | 68 | if (substr($statement, -1) === ';') { |
| 69 | - return $statement . PHP_EOL . '/' . PHP_EOL; |
|
| 69 | + return $statement.PHP_EOL.'/'.PHP_EOL; |
|
| 70 | 70 | } |
| 71 | - $script = $statement . ';'; |
|
| 71 | + $script = $statement.';'; |
|
| 72 | 72 | $script .= PHP_EOL; |
| 73 | 73 | $script .= PHP_EOL; |
| 74 | 74 | return $script; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | protected function getFilterExpression() { |
| 78 | - return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 78 | + return '/^"'.preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')).'/'; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | } |