@@ -25,17 +25,17 @@ |
||
25 | 25 | use OCP\DB\QueryBuilder\ILiteral; |
26 | 26 | |
27 | 27 | class Literal implements ILiteral { |
28 | - /** @var mixed */ |
|
29 | - protected $literal; |
|
28 | + /** @var mixed */ |
|
29 | + protected $literal; |
|
30 | 30 | |
31 | - public function __construct($literal) { |
|
32 | - $this->literal = $literal; |
|
33 | - } |
|
31 | + public function __construct($literal) { |
|
32 | + $this->literal = $literal; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function __toString() { |
|
39 | - return (string) $this->literal; |
|
40 | - } |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function __toString() { |
|
39 | + return (string) $this->literal; |
|
40 | + } |
|
41 | 41 | } |
@@ -29,47 +29,47 @@ |
||
29 | 29 | use Doctrine\DBAL\Schema\Table; |
30 | 30 | |
31 | 31 | class MySQLMigrator extends Migrator { |
32 | - /** |
|
33 | - * @param Schema $targetSchema |
|
34 | - * @param \Doctrine\DBAL\Connection $connection |
|
35 | - * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
36 | - */ |
|
37 | - protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
38 | - $platform = $connection->getDatabasePlatform(); |
|
39 | - $platform->registerDoctrineTypeMapping('enum', 'string'); |
|
40 | - $platform->registerDoctrineTypeMapping('bit', 'string'); |
|
32 | + /** |
|
33 | + * @param Schema $targetSchema |
|
34 | + * @param \Doctrine\DBAL\Connection $connection |
|
35 | + * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
36 | + */ |
|
37 | + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
38 | + $platform = $connection->getDatabasePlatform(); |
|
39 | + $platform->registerDoctrineTypeMapping('enum', 'string'); |
|
40 | + $platform->registerDoctrineTypeMapping('bit', 'string'); |
|
41 | 41 | |
42 | - $schemaDiff = parent::getDiff($targetSchema, $connection); |
|
42 | + $schemaDiff = parent::getDiff($targetSchema, $connection); |
|
43 | 43 | |
44 | - // identifiers need to be quoted for mysql |
|
45 | - foreach ($schemaDiff->changedTables as $tableDiff) { |
|
46 | - $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); |
|
47 | - foreach ($tableDiff->changedColumns as $column) { |
|
48 | - $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); |
|
49 | - } |
|
50 | - } |
|
44 | + // identifiers need to be quoted for mysql |
|
45 | + foreach ($schemaDiff->changedTables as $tableDiff) { |
|
46 | + $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); |
|
47 | + foreach ($tableDiff->changedColumns as $column) { |
|
48 | + $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - return $schemaDiff; |
|
53 | - } |
|
52 | + return $schemaDiff; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Speed up migration test by disabling autocommit and unique indexes check |
|
57 | - * |
|
58 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
59 | - * @throws \OC\DB\MigrationException |
|
60 | - */ |
|
61 | - protected function checkTableMigrate(Table $table) { |
|
62 | - $this->connection->exec('SET autocommit=0'); |
|
63 | - $this->connection->exec('SET unique_checks=0'); |
|
55 | + /** |
|
56 | + * Speed up migration test by disabling autocommit and unique indexes check |
|
57 | + * |
|
58 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
59 | + * @throws \OC\DB\MigrationException |
|
60 | + */ |
|
61 | + protected function checkTableMigrate(Table $table) { |
|
62 | + $this->connection->exec('SET autocommit=0'); |
|
63 | + $this->connection->exec('SET unique_checks=0'); |
|
64 | 64 | |
65 | - try { |
|
66 | - parent::checkTableMigrate($table); |
|
67 | - } catch (\Exception $e) { |
|
68 | - $this->connection->exec('SET unique_checks=1'); |
|
69 | - $this->connection->exec('SET autocommit=1'); |
|
70 | - throw new MigrationException($table->getName(), $e->getMessage()); |
|
71 | - } |
|
72 | - $this->connection->exec('SET unique_checks=1'); |
|
73 | - $this->connection->exec('SET autocommit=1'); |
|
74 | - } |
|
65 | + try { |
|
66 | + parent::checkTableMigrate($table); |
|
67 | + } catch (\Exception $e) { |
|
68 | + $this->connection->exec('SET unique_checks=1'); |
|
69 | + $this->connection->exec('SET autocommit=1'); |
|
70 | + throw new MigrationException($table->getName(), $e->getMessage()); |
|
71 | + } |
|
72 | + $this->connection->exec('SET unique_checks=1'); |
|
73 | + $this->connection->exec('SET autocommit=1'); |
|
74 | + } |
|
75 | 75 | } |
@@ -32,41 +32,41 @@ |
||
32 | 32 | */ |
33 | 33 | class PgSqlTools { |
34 | 34 | |
35 | - /** @var \OCP\IConfig */ |
|
36 | - private $config; |
|
35 | + /** @var \OCP\IConfig */ |
|
36 | + private $config; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param \OCP\IConfig $config |
|
40 | - */ |
|
41 | - public function __construct(IConfig $config) { |
|
42 | - $this->config = $config; |
|
43 | - } |
|
38 | + /** |
|
39 | + * @param \OCP\IConfig $config |
|
40 | + */ |
|
41 | + public function __construct(IConfig $config) { |
|
42 | + $this->config = $config; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @brief Resynchronizes all sequences of a database after using INSERTs |
|
47 | - * without leaving out the auto-incremented column. |
|
48 | - * @param \OC\DB\Connection $conn |
|
49 | - * @return null |
|
50 | - */ |
|
51 | - public function resynchronizeDatabaseSequences(Connection $conn) { |
|
52 | - $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
53 | - $databaseName = $conn->getDatabase(); |
|
54 | - $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
45 | + /** |
|
46 | + * @brief Resynchronizes all sequences of a database after using INSERTs |
|
47 | + * without leaving out the auto-incremented column. |
|
48 | + * @param \OC\DB\Connection $conn |
|
49 | + * @return null |
|
50 | + */ |
|
51 | + public function resynchronizeDatabaseSequences(Connection $conn) { |
|
52 | + $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
53 | + $databaseName = $conn->getDatabase(); |
|
54 | + $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
55 | 55 | |
56 | - foreach ($conn->getSchemaManager()->listSequences() as $sequence) { |
|
57 | - $sequenceName = $sequence->getName(); |
|
58 | - $sqlInfo = 'SELECT table_schema, table_name, column_name |
|
56 | + foreach ($conn->getSchemaManager()->listSequences() as $sequence) { |
|
57 | + $sequenceName = $sequence->getName(); |
|
58 | + $sqlInfo = 'SELECT table_schema, table_name, column_name |
|
59 | 59 | FROM information_schema.columns |
60 | 60 | WHERE column_default = ? AND table_catalog = ?'; |
61 | - $sequenceInfo = $conn->fetchAssoc($sqlInfo, [ |
|
62 | - "nextval('$sequenceName'::regclass)", |
|
63 | - $databaseName |
|
64 | - ]); |
|
65 | - $tableName = $sequenceInfo['table_name']; |
|
66 | - $columnName = $sequenceInfo['column_name']; |
|
67 | - $sqlMaxId = "SELECT MAX($columnName) FROM $tableName"; |
|
68 | - $sqlSetval = "SELECT setval('$sequenceName', ($sqlMaxId))"; |
|
69 | - $conn->executeQuery($sqlSetval); |
|
70 | - } |
|
71 | - } |
|
61 | + $sequenceInfo = $conn->fetchAssoc($sqlInfo, [ |
|
62 | + "nextval('$sequenceName'::regclass)", |
|
63 | + $databaseName |
|
64 | + ]); |
|
65 | + $tableName = $sequenceInfo['table_name']; |
|
66 | + $columnName = $sequenceInfo['column_name']; |
|
67 | + $sqlMaxId = "SELECT MAX($columnName) FROM $tableName"; |
|
68 | + $sqlSetval = "SELECT setval('$sequenceName', ($sqlMaxId))"; |
|
69 | + $conn->executeQuery($sqlSetval); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | } |
@@ -37,312 +37,312 @@ |
||
37 | 37 | |
38 | 38 | class MDB2SchemaReader { |
39 | 39 | |
40 | - /** |
|
41 | - * @var string $DBTABLEPREFIX |
|
42 | - */ |
|
43 | - protected $DBTABLEPREFIX; |
|
40 | + /** |
|
41 | + * @var string $DBTABLEPREFIX |
|
42 | + */ |
|
43 | + protected $DBTABLEPREFIX; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @var \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
|
47 | - */ |
|
48 | - protected $platform; |
|
45 | + /** |
|
46 | + * @var \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
|
47 | + */ |
|
48 | + protected $platform; |
|
49 | 49 | |
50 | - /** @var IConfig */ |
|
51 | - protected $config; |
|
50 | + /** @var IConfig */ |
|
51 | + protected $config; |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param \OCP\IConfig $config |
|
55 | - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
|
56 | - */ |
|
57 | - public function __construct(IConfig $config, AbstractPlatform $platform) { |
|
58 | - $this->platform = $platform; |
|
59 | - $this->config = $config; |
|
60 | - $this->DBTABLEPREFIX = $config->getSystemValue('dbtableprefix', 'oc_'); |
|
61 | - } |
|
53 | + /** |
|
54 | + * @param \OCP\IConfig $config |
|
55 | + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform |
|
56 | + */ |
|
57 | + public function __construct(IConfig $config, AbstractPlatform $platform) { |
|
58 | + $this->platform = $platform; |
|
59 | + $this->config = $config; |
|
60 | + $this->DBTABLEPREFIX = $config->getSystemValue('dbtableprefix', 'oc_'); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param string $file |
|
65 | - * @param Schema $schema |
|
66 | - * @return Schema |
|
67 | - * @throws \DomainException |
|
68 | - */ |
|
69 | - public function loadSchemaFromFile($file, Schema $schema) { |
|
70 | - $loadEntities = libxml_disable_entity_loader(false); |
|
71 | - $xml = simplexml_load_file($file); |
|
72 | - libxml_disable_entity_loader($loadEntities); |
|
73 | - foreach ($xml->children() as $child) { |
|
74 | - /** |
|
75 | - * @var \SimpleXMLElement $child |
|
76 | - */ |
|
77 | - switch ($child->getName()) { |
|
78 | - case 'name': |
|
79 | - case 'create': |
|
80 | - case 'overwrite': |
|
81 | - case 'charset': |
|
82 | - break; |
|
83 | - case 'table': |
|
84 | - $this->loadTable($schema, $child); |
|
85 | - break; |
|
86 | - default: |
|
87 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
63 | + /** |
|
64 | + * @param string $file |
|
65 | + * @param Schema $schema |
|
66 | + * @return Schema |
|
67 | + * @throws \DomainException |
|
68 | + */ |
|
69 | + public function loadSchemaFromFile($file, Schema $schema) { |
|
70 | + $loadEntities = libxml_disable_entity_loader(false); |
|
71 | + $xml = simplexml_load_file($file); |
|
72 | + libxml_disable_entity_loader($loadEntities); |
|
73 | + foreach ($xml->children() as $child) { |
|
74 | + /** |
|
75 | + * @var \SimpleXMLElement $child |
|
76 | + */ |
|
77 | + switch ($child->getName()) { |
|
78 | + case 'name': |
|
79 | + case 'create': |
|
80 | + case 'overwrite': |
|
81 | + case 'charset': |
|
82 | + break; |
|
83 | + case 'table': |
|
84 | + $this->loadTable($schema, $child); |
|
85 | + break; |
|
86 | + default: |
|
87 | + throw new \DomainException('Unknown element: ' . $child->getName()); |
|
88 | 88 | |
89 | - } |
|
90 | - } |
|
91 | - return $schema; |
|
92 | - } |
|
89 | + } |
|
90 | + } |
|
91 | + return $schema; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @param \Doctrine\DBAL\Schema\Schema $schema |
|
96 | - * @param \SimpleXMLElement $xml |
|
97 | - * @throws \DomainException |
|
98 | - */ |
|
99 | - private function loadTable($schema, $xml) { |
|
100 | - $table = null; |
|
101 | - foreach ($xml->children() as $child) { |
|
102 | - /** |
|
103 | - * @var \SimpleXMLElement $child |
|
104 | - */ |
|
105 | - switch ($child->getName()) { |
|
106 | - case 'name': |
|
107 | - $name = (string)$child; |
|
108 | - $name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name); |
|
109 | - $name = $this->platform->quoteIdentifier($name); |
|
110 | - $table = $schema->createTable($name); |
|
111 | - break; |
|
112 | - case 'create': |
|
113 | - case 'overwrite': |
|
114 | - case 'charset': |
|
115 | - break; |
|
116 | - case 'declaration': |
|
117 | - if (is_null($table)) { |
|
118 | - throw new \DomainException('Table declaration before table name'); |
|
119 | - } |
|
120 | - $this->loadDeclaration($table, $child); |
|
121 | - break; |
|
122 | - default: |
|
123 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
94 | + /** |
|
95 | + * @param \Doctrine\DBAL\Schema\Schema $schema |
|
96 | + * @param \SimpleXMLElement $xml |
|
97 | + * @throws \DomainException |
|
98 | + */ |
|
99 | + private function loadTable($schema, $xml) { |
|
100 | + $table = null; |
|
101 | + foreach ($xml->children() as $child) { |
|
102 | + /** |
|
103 | + * @var \SimpleXMLElement $child |
|
104 | + */ |
|
105 | + switch ($child->getName()) { |
|
106 | + case 'name': |
|
107 | + $name = (string)$child; |
|
108 | + $name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name); |
|
109 | + $name = $this->platform->quoteIdentifier($name); |
|
110 | + $table = $schema->createTable($name); |
|
111 | + break; |
|
112 | + case 'create': |
|
113 | + case 'overwrite': |
|
114 | + case 'charset': |
|
115 | + break; |
|
116 | + case 'declaration': |
|
117 | + if (is_null($table)) { |
|
118 | + throw new \DomainException('Table declaration before table name'); |
|
119 | + } |
|
120 | + $this->loadDeclaration($table, $child); |
|
121 | + break; |
|
122 | + default: |
|
123 | + throw new \DomainException('Unknown element: ' . $child->getName()); |
|
124 | 124 | |
125 | - } |
|
126 | - } |
|
127 | - } |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | 128 | |
129 | - /** |
|
130 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
131 | - * @param \SimpleXMLElement $xml |
|
132 | - * @throws \DomainException |
|
133 | - */ |
|
134 | - private function loadDeclaration($table, $xml) { |
|
135 | - foreach ($xml->children() as $child) { |
|
136 | - /** |
|
137 | - * @var \SimpleXMLElement $child |
|
138 | - */ |
|
139 | - switch ($child->getName()) { |
|
140 | - case 'field': |
|
141 | - $this->loadField($table, $child); |
|
142 | - break; |
|
143 | - case 'index': |
|
144 | - $this->loadIndex($table, $child); |
|
145 | - break; |
|
146 | - default: |
|
147 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
129 | + /** |
|
130 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
131 | + * @param \SimpleXMLElement $xml |
|
132 | + * @throws \DomainException |
|
133 | + */ |
|
134 | + private function loadDeclaration($table, $xml) { |
|
135 | + foreach ($xml->children() as $child) { |
|
136 | + /** |
|
137 | + * @var \SimpleXMLElement $child |
|
138 | + */ |
|
139 | + switch ($child->getName()) { |
|
140 | + case 'field': |
|
141 | + $this->loadField($table, $child); |
|
142 | + break; |
|
143 | + case 'index': |
|
144 | + $this->loadIndex($table, $child); |
|
145 | + break; |
|
146 | + default: |
|
147 | + throw new \DomainException('Unknown element: ' . $child->getName()); |
|
148 | 148 | |
149 | - } |
|
150 | - } |
|
151 | - } |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
155 | - * @param \SimpleXMLElement $xml |
|
156 | - * @throws \DomainException |
|
157 | - */ |
|
158 | - private function loadField($table, $xml) { |
|
159 | - $options = [ 'notnull' => false ]; |
|
160 | - foreach ($xml->children() as $child) { |
|
161 | - /** |
|
162 | - * @var \SimpleXMLElement $child |
|
163 | - */ |
|
164 | - switch ($child->getName()) { |
|
165 | - case 'name': |
|
166 | - $name = (string)$child; |
|
167 | - $name = $this->platform->quoteIdentifier($name); |
|
168 | - break; |
|
169 | - case 'type': |
|
170 | - $type = (string)$child; |
|
171 | - switch ($type) { |
|
172 | - case 'text': |
|
173 | - $type = 'string'; |
|
174 | - break; |
|
175 | - case 'clob': |
|
176 | - $type = 'text'; |
|
177 | - break; |
|
178 | - case 'timestamp': |
|
179 | - $type = 'datetime'; |
|
180 | - break; |
|
181 | - case 'numeric': |
|
182 | - $type = 'decimal'; |
|
183 | - break; |
|
184 | - } |
|
185 | - break; |
|
186 | - case 'length': |
|
187 | - $length = (string)$child; |
|
188 | - $options['length'] = $length; |
|
189 | - break; |
|
190 | - case 'unsigned': |
|
191 | - $unsigned = $this->asBool($child); |
|
192 | - $options['unsigned'] = $unsigned; |
|
193 | - break; |
|
194 | - case 'notnull': |
|
195 | - $notnull = $this->asBool($child); |
|
196 | - $options['notnull'] = $notnull; |
|
197 | - break; |
|
198 | - case 'autoincrement': |
|
199 | - $autoincrement = $this->asBool($child); |
|
200 | - $options['autoincrement'] = $autoincrement; |
|
201 | - break; |
|
202 | - case 'default': |
|
203 | - $default = (string)$child; |
|
204 | - $options['default'] = $default; |
|
205 | - break; |
|
206 | - case 'comments': |
|
207 | - $comment = (string)$child; |
|
208 | - $options['comment'] = $comment; |
|
209 | - break; |
|
210 | - case 'primary': |
|
211 | - $primary = $this->asBool($child); |
|
212 | - $options['primary'] = $primary; |
|
213 | - break; |
|
214 | - case 'precision': |
|
215 | - $precision = (string)$child; |
|
216 | - $options['precision'] = $precision; |
|
217 | - break; |
|
218 | - case 'scale': |
|
219 | - $scale = (string)$child; |
|
220 | - $options['scale'] = $scale; |
|
221 | - break; |
|
222 | - default: |
|
223 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
153 | + /** |
|
154 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
155 | + * @param \SimpleXMLElement $xml |
|
156 | + * @throws \DomainException |
|
157 | + */ |
|
158 | + private function loadField($table, $xml) { |
|
159 | + $options = [ 'notnull' => false ]; |
|
160 | + foreach ($xml->children() as $child) { |
|
161 | + /** |
|
162 | + * @var \SimpleXMLElement $child |
|
163 | + */ |
|
164 | + switch ($child->getName()) { |
|
165 | + case 'name': |
|
166 | + $name = (string)$child; |
|
167 | + $name = $this->platform->quoteIdentifier($name); |
|
168 | + break; |
|
169 | + case 'type': |
|
170 | + $type = (string)$child; |
|
171 | + switch ($type) { |
|
172 | + case 'text': |
|
173 | + $type = 'string'; |
|
174 | + break; |
|
175 | + case 'clob': |
|
176 | + $type = 'text'; |
|
177 | + break; |
|
178 | + case 'timestamp': |
|
179 | + $type = 'datetime'; |
|
180 | + break; |
|
181 | + case 'numeric': |
|
182 | + $type = 'decimal'; |
|
183 | + break; |
|
184 | + } |
|
185 | + break; |
|
186 | + case 'length': |
|
187 | + $length = (string)$child; |
|
188 | + $options['length'] = $length; |
|
189 | + break; |
|
190 | + case 'unsigned': |
|
191 | + $unsigned = $this->asBool($child); |
|
192 | + $options['unsigned'] = $unsigned; |
|
193 | + break; |
|
194 | + case 'notnull': |
|
195 | + $notnull = $this->asBool($child); |
|
196 | + $options['notnull'] = $notnull; |
|
197 | + break; |
|
198 | + case 'autoincrement': |
|
199 | + $autoincrement = $this->asBool($child); |
|
200 | + $options['autoincrement'] = $autoincrement; |
|
201 | + break; |
|
202 | + case 'default': |
|
203 | + $default = (string)$child; |
|
204 | + $options['default'] = $default; |
|
205 | + break; |
|
206 | + case 'comments': |
|
207 | + $comment = (string)$child; |
|
208 | + $options['comment'] = $comment; |
|
209 | + break; |
|
210 | + case 'primary': |
|
211 | + $primary = $this->asBool($child); |
|
212 | + $options['primary'] = $primary; |
|
213 | + break; |
|
214 | + case 'precision': |
|
215 | + $precision = (string)$child; |
|
216 | + $options['precision'] = $precision; |
|
217 | + break; |
|
218 | + case 'scale': |
|
219 | + $scale = (string)$child; |
|
220 | + $options['scale'] = $scale; |
|
221 | + break; |
|
222 | + default: |
|
223 | + throw new \DomainException('Unknown element: ' . $child->getName()); |
|
224 | 224 | |
225 | - } |
|
226 | - } |
|
227 | - if (isset($name) && isset($type)) { |
|
228 | - if (isset($options['default']) && empty($options['default'])) { |
|
229 | - if (empty($options['notnull']) || !$options['notnull']) { |
|
230 | - unset($options['default']); |
|
231 | - $options['notnull'] = false; |
|
232 | - } else { |
|
233 | - $options['default'] = ''; |
|
234 | - } |
|
235 | - if ($type == 'integer' || $type == 'decimal') { |
|
236 | - $options['default'] = 0; |
|
237 | - } elseif ($type == 'boolean') { |
|
238 | - $options['default'] = false; |
|
239 | - } |
|
240 | - if (!empty($options['autoincrement']) && $options['autoincrement']) { |
|
241 | - unset($options['default']); |
|
242 | - } |
|
243 | - } |
|
244 | - if ($type === 'integer' && isset($options['default'])) { |
|
245 | - $options['default'] = (int)$options['default']; |
|
246 | - } |
|
247 | - if ($type === 'integer' && isset($options['length'])) { |
|
248 | - $length = $options['length']; |
|
249 | - if ($length < 4) { |
|
250 | - $type = 'smallint'; |
|
251 | - } elseif ($length > 4) { |
|
252 | - $type = 'bigint'; |
|
253 | - } |
|
254 | - } |
|
255 | - if ($type === 'boolean' && isset($options['default'])) { |
|
256 | - $options['default'] = $this->asBool($options['default']); |
|
257 | - } |
|
258 | - if (!empty($options['autoincrement']) |
|
259 | - && !empty($options['notnull']) |
|
260 | - ) { |
|
261 | - $options['primary'] = true; |
|
262 | - } |
|
225 | + } |
|
226 | + } |
|
227 | + if (isset($name) && isset($type)) { |
|
228 | + if (isset($options['default']) && empty($options['default'])) { |
|
229 | + if (empty($options['notnull']) || !$options['notnull']) { |
|
230 | + unset($options['default']); |
|
231 | + $options['notnull'] = false; |
|
232 | + } else { |
|
233 | + $options['default'] = ''; |
|
234 | + } |
|
235 | + if ($type == 'integer' || $type == 'decimal') { |
|
236 | + $options['default'] = 0; |
|
237 | + } elseif ($type == 'boolean') { |
|
238 | + $options['default'] = false; |
|
239 | + } |
|
240 | + if (!empty($options['autoincrement']) && $options['autoincrement']) { |
|
241 | + unset($options['default']); |
|
242 | + } |
|
243 | + } |
|
244 | + if ($type === 'integer' && isset($options['default'])) { |
|
245 | + $options['default'] = (int)$options['default']; |
|
246 | + } |
|
247 | + if ($type === 'integer' && isset($options['length'])) { |
|
248 | + $length = $options['length']; |
|
249 | + if ($length < 4) { |
|
250 | + $type = 'smallint'; |
|
251 | + } elseif ($length > 4) { |
|
252 | + $type = 'bigint'; |
|
253 | + } |
|
254 | + } |
|
255 | + if ($type === 'boolean' && isset($options['default'])) { |
|
256 | + $options['default'] = $this->asBool($options['default']); |
|
257 | + } |
|
258 | + if (!empty($options['autoincrement']) |
|
259 | + && !empty($options['notnull']) |
|
260 | + ) { |
|
261 | + $options['primary'] = true; |
|
262 | + } |
|
263 | 263 | |
264 | - $table->addColumn($name, $type, $options); |
|
265 | - if (!empty($options['primary']) && $options['primary']) { |
|
266 | - $table->setPrimaryKey([$name]); |
|
267 | - } |
|
268 | - } |
|
269 | - } |
|
264 | + $table->addColumn($name, $type, $options); |
|
265 | + if (!empty($options['primary']) && $options['primary']) { |
|
266 | + $table->setPrimaryKey([$name]); |
|
267 | + } |
|
268 | + } |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
273 | - * @param \SimpleXMLElement $xml |
|
274 | - * @throws \DomainException |
|
275 | - */ |
|
276 | - private function loadIndex($table, $xml) { |
|
277 | - $name = null; |
|
278 | - $fields = []; |
|
279 | - foreach ($xml->children() as $child) { |
|
280 | - /** |
|
281 | - * @var \SimpleXMLElement $child |
|
282 | - */ |
|
283 | - switch ($child->getName()) { |
|
284 | - case 'name': |
|
285 | - $name = (string)$child; |
|
286 | - break; |
|
287 | - case 'primary': |
|
288 | - $primary = $this->asBool($child); |
|
289 | - break; |
|
290 | - case 'unique': |
|
291 | - $unique = $this->asBool($child); |
|
292 | - break; |
|
293 | - case 'field': |
|
294 | - foreach ($child->children() as $field) { |
|
295 | - /** |
|
296 | - * @var \SimpleXMLElement $field |
|
297 | - */ |
|
298 | - switch ($field->getName()) { |
|
299 | - case 'name': |
|
300 | - $field_name = (string)$field; |
|
301 | - $field_name = $this->platform->quoteIdentifier($field_name); |
|
302 | - $fields[] = $field_name; |
|
303 | - break; |
|
304 | - case 'sorting': |
|
305 | - break; |
|
306 | - default: |
|
307 | - throw new \DomainException('Unknown element: ' . $field->getName()); |
|
271 | + /** |
|
272 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
273 | + * @param \SimpleXMLElement $xml |
|
274 | + * @throws \DomainException |
|
275 | + */ |
|
276 | + private function loadIndex($table, $xml) { |
|
277 | + $name = null; |
|
278 | + $fields = []; |
|
279 | + foreach ($xml->children() as $child) { |
|
280 | + /** |
|
281 | + * @var \SimpleXMLElement $child |
|
282 | + */ |
|
283 | + switch ($child->getName()) { |
|
284 | + case 'name': |
|
285 | + $name = (string)$child; |
|
286 | + break; |
|
287 | + case 'primary': |
|
288 | + $primary = $this->asBool($child); |
|
289 | + break; |
|
290 | + case 'unique': |
|
291 | + $unique = $this->asBool($child); |
|
292 | + break; |
|
293 | + case 'field': |
|
294 | + foreach ($child->children() as $field) { |
|
295 | + /** |
|
296 | + * @var \SimpleXMLElement $field |
|
297 | + */ |
|
298 | + switch ($field->getName()) { |
|
299 | + case 'name': |
|
300 | + $field_name = (string)$field; |
|
301 | + $field_name = $this->platform->quoteIdentifier($field_name); |
|
302 | + $fields[] = $field_name; |
|
303 | + break; |
|
304 | + case 'sorting': |
|
305 | + break; |
|
306 | + default: |
|
307 | + throw new \DomainException('Unknown element: ' . $field->getName()); |
|
308 | 308 | |
309 | - } |
|
310 | - } |
|
311 | - break; |
|
312 | - default: |
|
313 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
309 | + } |
|
310 | + } |
|
311 | + break; |
|
312 | + default: |
|
313 | + throw new \DomainException('Unknown element: ' . $child->getName()); |
|
314 | 314 | |
315 | - } |
|
316 | - } |
|
317 | - if (!empty($fields)) { |
|
318 | - if (isset($primary) && $primary) { |
|
319 | - if ($table->hasPrimaryKey()) { |
|
320 | - return; |
|
321 | - } |
|
322 | - $table->setPrimaryKey($fields, $name); |
|
323 | - } else { |
|
324 | - if (isset($unique) && $unique) { |
|
325 | - $table->addUniqueIndex($fields, $name); |
|
326 | - } else { |
|
327 | - $table->addIndex($fields, $name); |
|
328 | - } |
|
329 | - } |
|
330 | - } else { |
|
331 | - throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true)); |
|
332 | - } |
|
333 | - } |
|
315 | + } |
|
316 | + } |
|
317 | + if (!empty($fields)) { |
|
318 | + if (isset($primary) && $primary) { |
|
319 | + if ($table->hasPrimaryKey()) { |
|
320 | + return; |
|
321 | + } |
|
322 | + $table->setPrimaryKey($fields, $name); |
|
323 | + } else { |
|
324 | + if (isset($unique) && $unique) { |
|
325 | + $table->addUniqueIndex($fields, $name); |
|
326 | + } else { |
|
327 | + $table->addIndex($fields, $name); |
|
328 | + } |
|
329 | + } |
|
330 | + } else { |
|
331 | + throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true)); |
|
332 | + } |
|
333 | + } |
|
334 | 334 | |
335 | - /** |
|
336 | - * @param \SimpleXMLElement|string $xml |
|
337 | - * @return bool |
|
338 | - */ |
|
339 | - private function asBool($xml) { |
|
340 | - $result = (string)$xml; |
|
341 | - if ($result == 'true') { |
|
342 | - $result = true; |
|
343 | - } elseif ($result == 'false') { |
|
344 | - $result = false; |
|
345 | - } |
|
346 | - return (bool)$result; |
|
347 | - } |
|
335 | + /** |
|
336 | + * @param \SimpleXMLElement|string $xml |
|
337 | + * @return bool |
|
338 | + */ |
|
339 | + private function asBool($xml) { |
|
340 | + $result = (string)$xml; |
|
341 | + if ($result == 'true') { |
|
342 | + $result = true; |
|
343 | + } elseif ($result == 'false') { |
|
344 | + $result = false; |
|
345 | + } |
|
346 | + return (bool)$result; |
|
347 | + } |
|
348 | 348 | } |
@@ -26,80 +26,80 @@ |
||
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 = []; |
|
34 | - $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
35 | - foreach ($data as $key => $value) { |
|
36 | - if ($key[0] !== $c) { |
|
37 | - $return[$this->quoteIdentifier($key)] = $value; |
|
38 | - } else { |
|
39 | - $return[$key] = $value; |
|
40 | - } |
|
41 | - } |
|
42 | - return $return; |
|
43 | - } |
|
29 | + /** |
|
30 | + * Quote the keys of the array |
|
31 | + */ |
|
32 | + private function quoteKeys(array $data) { |
|
33 | + $return = []; |
|
34 | + $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
35 | + foreach ($data as $key => $value) { |
|
36 | + if ($key[0] !== $c) { |
|
37 | + $return[$this->quoteIdentifier($key)] = $value; |
|
38 | + } else { |
|
39 | + $return[$key] = $value; |
|
40 | + } |
|
41 | + } |
|
42 | + return $return; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritDoc} |
|
47 | - */ |
|
48 | - public function insert($tableName, array $data, array $types = []) { |
|
49 | - if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
50 | - $tableName = $this->quoteIdentifier($tableName); |
|
51 | - } |
|
52 | - $data = $this->quoteKeys($data); |
|
53 | - return parent::insert($tableName, $data, $types); |
|
54 | - } |
|
45 | + /** |
|
46 | + * {@inheritDoc} |
|
47 | + */ |
|
48 | + public function insert($tableName, array $data, array $types = []) { |
|
49 | + if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
50 | + $tableName = $this->quoteIdentifier($tableName); |
|
51 | + } |
|
52 | + $data = $this->quoteKeys($data); |
|
53 | + return parent::insert($tableName, $data, $types); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - */ |
|
59 | - public function update($tableName, array $data, array $identifier, array $types = []) { |
|
60 | - if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
61 | - $tableName = $this->quoteIdentifier($tableName); |
|
62 | - } |
|
63 | - $data = $this->quoteKeys($data); |
|
64 | - $identifier = $this->quoteKeys($identifier); |
|
65 | - return parent::update($tableName, $data, $identifier, $types); |
|
66 | - } |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + */ |
|
59 | + public function update($tableName, array $data, array $identifier, array $types = []) { |
|
60 | + if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
61 | + $tableName = $this->quoteIdentifier($tableName); |
|
62 | + } |
|
63 | + $data = $this->quoteKeys($data); |
|
64 | + $identifier = $this->quoteKeys($identifier); |
|
65 | + return parent::update($tableName, $data, $identifier, $types); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * {@inheritDoc} |
|
70 | - */ |
|
71 | - public function delete($tableExpression, array $identifier, array $types = []) { |
|
72 | - if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
73 | - $tableExpression = $this->quoteIdentifier($tableExpression); |
|
74 | - } |
|
75 | - $identifier = $this->quoteKeys($identifier); |
|
76 | - return parent::delete($tableExpression, $identifier); |
|
77 | - } |
|
68 | + /** |
|
69 | + * {@inheritDoc} |
|
70 | + */ |
|
71 | + public function delete($tableExpression, array $identifier, array $types = []) { |
|
72 | + if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
73 | + $tableExpression = $this->quoteIdentifier($tableExpression); |
|
74 | + } |
|
75 | + $identifier = $this->quoteKeys($identifier); |
|
76 | + return parent::delete($tableExpression, $identifier); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Drop a table from the database if it exists |
|
81 | - * |
|
82 | - * @param string $table table name without the prefix |
|
83 | - */ |
|
84 | - public function dropTable($table) { |
|
85 | - $table = $this->tablePrefix . trim($table); |
|
86 | - $table = $this->quoteIdentifier($table); |
|
87 | - $schema = $this->getSchemaManager(); |
|
88 | - if ($schema->tablesExist([$table])) { |
|
89 | - $schema->dropTable($table); |
|
90 | - } |
|
91 | - } |
|
79 | + /** |
|
80 | + * Drop a table from the database if it exists |
|
81 | + * |
|
82 | + * @param string $table table name without the prefix |
|
83 | + */ |
|
84 | + public function dropTable($table) { |
|
85 | + $table = $this->tablePrefix . trim($table); |
|
86 | + $table = $this->quoteIdentifier($table); |
|
87 | + $schema = $this->getSchemaManager(); |
|
88 | + if ($schema->tablesExist([$table])) { |
|
89 | + $schema->dropTable($table); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Check if a table exists |
|
95 | - * |
|
96 | - * @param string $table table name without the prefix |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function tableExists($table) { |
|
100 | - $table = $this->tablePrefix . trim($table); |
|
101 | - $table = $this->quoteIdentifier($table); |
|
102 | - $schema = $this->getSchemaManager(); |
|
103 | - return $schema->tablesExist([$table]); |
|
104 | - } |
|
93 | + /** |
|
94 | + * Check if a table exists |
|
95 | + * |
|
96 | + * @param string $table table name without the prefix |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function tableExists($table) { |
|
100 | + $table = $this->tablePrefix . trim($table); |
|
101 | + $table = $this->quoteIdentifier($table); |
|
102 | + $schema = $this->getSchemaManager(); |
|
103 | + return $schema->tablesExist([$table]); |
|
104 | + } |
|
105 | 105 | } |
@@ -31,150 +31,150 @@ |
||
31 | 31 | |
32 | 32 | class MDB2SchemaWriter { |
33 | 33 | |
34 | - /** |
|
35 | - * @param string $file |
|
36 | - * @param \OC\DB\Connection $conn |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public static 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 | + public static 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 | - if ($config->getSystemValue('dbtype', 'sqlite') === 'mysql' && $config->getSystemValue('mysql.utf8mb4', false)) { |
|
47 | - $xml->addChild('charset', 'utf8mb4'); |
|
48 | - } else { |
|
49 | - $xml->addChild('charset', 'utf8'); |
|
50 | - } |
|
42 | + $xml = new \SimpleXMLElement('<database/>'); |
|
43 | + $xml->addChild('name', $config->getSystemValue('dbname', 'owncloud')); |
|
44 | + $xml->addChild('create', 'true'); |
|
45 | + $xml->addChild('overwrite', 'false'); |
|
46 | + if ($config->getSystemValue('dbtype', 'sqlite') === 'mysql' && $config->getSystemValue('mysql.utf8mb4', false)) { |
|
47 | + $xml->addChild('charset', 'utf8mb4'); |
|
48 | + } else { |
|
49 | + $xml->addChild('charset', 'utf8'); |
|
50 | + } |
|
51 | 51 | |
52 | - // FIX ME: bloody work around |
|
53 | - if ($config->getSystemValue('dbtype', 'sqlite') === 'oci') { |
|
54 | - $filterExpression = '/^"' . preg_quote($conn->getPrefix()) . '/'; |
|
55 | - } else { |
|
56 | - $filterExpression = '/^' . preg_quote($conn->getPrefix()) . '/'; |
|
57 | - } |
|
58 | - $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
52 | + // FIX ME: bloody work around |
|
53 | + if ($config->getSystemValue('dbtype', 'sqlite') === 'oci') { |
|
54 | + $filterExpression = '/^"' . preg_quote($conn->getPrefix()) . '/'; |
|
55 | + } else { |
|
56 | + $filterExpression = '/^' . preg_quote($conn->getPrefix()) . '/'; |
|
57 | + } |
|
58 | + $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
59 | 59 | |
60 | - foreach ($conn->getSchemaManager()->listTables() as $table) { |
|
61 | - self::saveTable($table, $xml->addChild('table')); |
|
62 | - } |
|
63 | - file_put_contents($file, $xml->asXML()); |
|
64 | - return true; |
|
65 | - } |
|
60 | + foreach ($conn->getSchemaManager()->listTables() as $table) { |
|
61 | + self::saveTable($table, $xml->addChild('table')); |
|
62 | + } |
|
63 | + file_put_contents($file, $xml->asXML()); |
|
64 | + return true; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
69 | - * @param \SimpleXMLElement $xml |
|
70 | - */ |
|
71 | - private static function saveTable($table, $xml) { |
|
72 | - $xml->addChild('name', $table->getName()); |
|
73 | - $declaration = $xml->addChild('declaration'); |
|
74 | - foreach ($table->getColumns() as $column) { |
|
75 | - self::saveColumn($column, $declaration->addChild('field')); |
|
76 | - } |
|
77 | - foreach ($table->getIndexes() as $index) { |
|
78 | - if ($index->getName() == 'PRIMARY') { |
|
79 | - $autoincrement = false; |
|
80 | - foreach ($index->getColumns() as $column) { |
|
81 | - if ($table->getColumn($column)->getAutoincrement()) { |
|
82 | - $autoincrement = true; |
|
83 | - } |
|
84 | - } |
|
85 | - if ($autoincrement) { |
|
86 | - continue; |
|
87 | - } |
|
88 | - } |
|
89 | - self::saveIndex($index, $declaration->addChild('index')); |
|
90 | - } |
|
91 | - } |
|
67 | + /** |
|
68 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
69 | + * @param \SimpleXMLElement $xml |
|
70 | + */ |
|
71 | + private static function saveTable($table, $xml) { |
|
72 | + $xml->addChild('name', $table->getName()); |
|
73 | + $declaration = $xml->addChild('declaration'); |
|
74 | + foreach ($table->getColumns() as $column) { |
|
75 | + self::saveColumn($column, $declaration->addChild('field')); |
|
76 | + } |
|
77 | + foreach ($table->getIndexes() as $index) { |
|
78 | + if ($index->getName() == 'PRIMARY') { |
|
79 | + $autoincrement = false; |
|
80 | + foreach ($index->getColumns() as $column) { |
|
81 | + if ($table->getColumn($column)->getAutoincrement()) { |
|
82 | + $autoincrement = true; |
|
83 | + } |
|
84 | + } |
|
85 | + if ($autoincrement) { |
|
86 | + continue; |
|
87 | + } |
|
88 | + } |
|
89 | + self::saveIndex($index, $declaration->addChild('index')); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @param Column $column |
|
95 | - * @param \SimpleXMLElement $xml |
|
96 | - */ |
|
97 | - private static function saveColumn($column, $xml) { |
|
98 | - $xml->addChild('name', $column->getName()); |
|
99 | - switch ($column->getType()) { |
|
100 | - case 'SmallInt': |
|
101 | - case 'Integer': |
|
102 | - case 'BigInt': |
|
103 | - $xml->addChild('type', 'integer'); |
|
104 | - $default = $column->getDefault(); |
|
105 | - if (is_null($default) && $column->getAutoincrement()) { |
|
106 | - $default = '0'; |
|
107 | - } |
|
108 | - $xml->addChild('default', $default); |
|
109 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
110 | - if ($column->getAutoincrement()) { |
|
111 | - $xml->addChild('autoincrement', '1'); |
|
112 | - } |
|
113 | - if ($column->getUnsigned()) { |
|
114 | - $xml->addChild('unsigned', 'true'); |
|
115 | - } |
|
116 | - $length = '4'; |
|
117 | - if ($column->getType() == 'SmallInt') { |
|
118 | - $length = '2'; |
|
119 | - } elseif ($column->getType() == 'BigInt') { |
|
120 | - $length = '8'; |
|
121 | - } |
|
122 | - $xml->addChild('length', $length); |
|
123 | - break; |
|
124 | - case 'String': |
|
125 | - $xml->addChild('type', 'text'); |
|
126 | - $default = trim($column->getDefault()); |
|
127 | - if ($default === '') { |
|
128 | - $default = false; |
|
129 | - } |
|
130 | - $xml->addChild('default', $default); |
|
131 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
132 | - $xml->addChild('length', $column->getLength()); |
|
133 | - break; |
|
134 | - case 'Text': |
|
135 | - $xml->addChild('type', 'clob'); |
|
136 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
137 | - break; |
|
138 | - case 'Decimal': |
|
139 | - $xml->addChild('type', 'decimal'); |
|
140 | - $xml->addChild('default', $column->getDefault()); |
|
141 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
142 | - $xml->addChild('length', '15'); |
|
143 | - break; |
|
144 | - case 'Boolean': |
|
145 | - $xml->addChild('type', 'integer'); |
|
146 | - $xml->addChild('default', $column->getDefault()); |
|
147 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
148 | - $xml->addChild('length', '1'); |
|
149 | - break; |
|
150 | - case 'DateTime': |
|
151 | - $xml->addChild('type', 'timestamp'); |
|
152 | - $xml->addChild('default', $column->getDefault()); |
|
153 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
154 | - break; |
|
93 | + /** |
|
94 | + * @param Column $column |
|
95 | + * @param \SimpleXMLElement $xml |
|
96 | + */ |
|
97 | + private static function saveColumn($column, $xml) { |
|
98 | + $xml->addChild('name', $column->getName()); |
|
99 | + switch ($column->getType()) { |
|
100 | + case 'SmallInt': |
|
101 | + case 'Integer': |
|
102 | + case 'BigInt': |
|
103 | + $xml->addChild('type', 'integer'); |
|
104 | + $default = $column->getDefault(); |
|
105 | + if (is_null($default) && $column->getAutoincrement()) { |
|
106 | + $default = '0'; |
|
107 | + } |
|
108 | + $xml->addChild('default', $default); |
|
109 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
110 | + if ($column->getAutoincrement()) { |
|
111 | + $xml->addChild('autoincrement', '1'); |
|
112 | + } |
|
113 | + if ($column->getUnsigned()) { |
|
114 | + $xml->addChild('unsigned', 'true'); |
|
115 | + } |
|
116 | + $length = '4'; |
|
117 | + if ($column->getType() == 'SmallInt') { |
|
118 | + $length = '2'; |
|
119 | + } elseif ($column->getType() == 'BigInt') { |
|
120 | + $length = '8'; |
|
121 | + } |
|
122 | + $xml->addChild('length', $length); |
|
123 | + break; |
|
124 | + case 'String': |
|
125 | + $xml->addChild('type', 'text'); |
|
126 | + $default = trim($column->getDefault()); |
|
127 | + if ($default === '') { |
|
128 | + $default = false; |
|
129 | + } |
|
130 | + $xml->addChild('default', $default); |
|
131 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
132 | + $xml->addChild('length', $column->getLength()); |
|
133 | + break; |
|
134 | + case 'Text': |
|
135 | + $xml->addChild('type', 'clob'); |
|
136 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
137 | + break; |
|
138 | + case 'Decimal': |
|
139 | + $xml->addChild('type', 'decimal'); |
|
140 | + $xml->addChild('default', $column->getDefault()); |
|
141 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
142 | + $xml->addChild('length', '15'); |
|
143 | + break; |
|
144 | + case 'Boolean': |
|
145 | + $xml->addChild('type', 'integer'); |
|
146 | + $xml->addChild('default', $column->getDefault()); |
|
147 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
148 | + $xml->addChild('length', '1'); |
|
149 | + break; |
|
150 | + case 'DateTime': |
|
151 | + $xml->addChild('type', 'timestamp'); |
|
152 | + $xml->addChild('default', $column->getDefault()); |
|
153 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
154 | + break; |
|
155 | 155 | |
156 | - } |
|
157 | - } |
|
156 | + } |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * @param Index $index |
|
161 | - * @param \SimpleXMLElement $xml |
|
162 | - */ |
|
163 | - private static function saveIndex($index, $xml) { |
|
164 | - $xml->addChild('name', $index->getName()); |
|
165 | - if ($index->isPrimary()) { |
|
166 | - $xml->addChild('primary', 'true'); |
|
167 | - } elseif ($index->isUnique()) { |
|
168 | - $xml->addChild('unique', 'true'); |
|
169 | - } |
|
170 | - foreach ($index->getColumns() as $column) { |
|
171 | - $field = $xml->addChild('field'); |
|
172 | - $field->addChild('name', $column); |
|
173 | - $field->addChild('sorting', 'ascending'); |
|
174 | - } |
|
175 | - } |
|
159 | + /** |
|
160 | + * @param Index $index |
|
161 | + * @param \SimpleXMLElement $xml |
|
162 | + */ |
|
163 | + private static function saveIndex($index, $xml) { |
|
164 | + $xml->addChild('name', $index->getName()); |
|
165 | + if ($index->isPrimary()) { |
|
166 | + $xml->addChild('primary', 'true'); |
|
167 | + } elseif ($index->isUnique()) { |
|
168 | + $xml->addChild('unique', 'true'); |
|
169 | + } |
|
170 | + foreach ($index->getColumns() as $column) { |
|
171 | + $field = $xml->addChild('field'); |
|
172 | + $field->addChild('name', $column); |
|
173 | + $field->addChild('sorting', 'ascending'); |
|
174 | + } |
|
175 | + } |
|
176 | 176 | |
177 | - private static function toBool($bool) { |
|
178 | - return $bool ? 'true' : 'false'; |
|
179 | - } |
|
177 | + private static function toBool($bool) { |
|
178 | + return $bool ? 'true' : 'false'; |
|
179 | + } |
|
180 | 180 | } |
@@ -32,62 +32,62 @@ |
||
32 | 32 | |
33 | 33 | class SQLiteMigrator extends Migrator { |
34 | 34 | |
35 | - /** |
|
36 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
37 | - * @throws \OC\DB\MigrationException |
|
38 | - * |
|
39 | - * For sqlite we simple make a copy of the entire database, and test the migration on that |
|
40 | - */ |
|
41 | - public function checkMigrate(\Doctrine\DBAL\Schema\Schema $targetSchema) { |
|
42 | - $dbFile = $this->connection->getDatabase(); |
|
43 | - $tmpFile = $this->buildTempDatabase(); |
|
44 | - copy($dbFile, $tmpFile); |
|
35 | + /** |
|
36 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
37 | + * @throws \OC\DB\MigrationException |
|
38 | + * |
|
39 | + * For sqlite we simple make a copy of the entire database, and test the migration on that |
|
40 | + */ |
|
41 | + public function checkMigrate(\Doctrine\DBAL\Schema\Schema $targetSchema) { |
|
42 | + $dbFile = $this->connection->getDatabase(); |
|
43 | + $tmpFile = $this->buildTempDatabase(); |
|
44 | + copy($dbFile, $tmpFile); |
|
45 | 45 | |
46 | - $connectionParams = [ |
|
47 | - 'path' => $tmpFile, |
|
48 | - 'driver' => 'pdo_sqlite', |
|
49 | - ]; |
|
50 | - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams); |
|
51 | - try { |
|
52 | - $this->applySchema($targetSchema, $conn); |
|
53 | - $conn->close(); |
|
54 | - unlink($tmpFile); |
|
55 | - } catch (DBALException $e) { |
|
56 | - $conn->close(); |
|
57 | - unlink($tmpFile); |
|
58 | - throw new MigrationException('', $e->getMessage()); |
|
59 | - } |
|
60 | - } |
|
46 | + $connectionParams = [ |
|
47 | + 'path' => $tmpFile, |
|
48 | + 'driver' => 'pdo_sqlite', |
|
49 | + ]; |
|
50 | + $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams); |
|
51 | + try { |
|
52 | + $this->applySchema($targetSchema, $conn); |
|
53 | + $conn->close(); |
|
54 | + unlink($tmpFile); |
|
55 | + } catch (DBALException $e) { |
|
56 | + $conn->close(); |
|
57 | + unlink($tmpFile); |
|
58 | + throw new MigrationException('', $e->getMessage()); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - private function buildTempDatabase() { |
|
66 | - $dataDir = $this->config->getSystemValue("datadirectory", \OC::$SERVERROOT . '/data'); |
|
67 | - $tmpFile = uniqid("oc_"); |
|
68 | - return "$dataDir/$tmpFile.db"; |
|
69 | - } |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + private function buildTempDatabase() { |
|
66 | + $dataDir = $this->config->getSystemValue("datadirectory", \OC::$SERVERROOT . '/data'); |
|
67 | + $tmpFile = uniqid("oc_"); |
|
68 | + return "$dataDir/$tmpFile.db"; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @param Schema $targetSchema |
|
73 | - * @param \Doctrine\DBAL\Connection $connection |
|
74 | - * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
75 | - */ |
|
76 | - protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
77 | - $platform = $connection->getDatabasePlatform(); |
|
78 | - $platform->registerDoctrineTypeMapping('tinyint unsigned', 'integer'); |
|
79 | - $platform->registerDoctrineTypeMapping('smallint unsigned', 'integer'); |
|
80 | - $platform->registerDoctrineTypeMapping('varchar ', 'string'); |
|
71 | + /** |
|
72 | + * @param Schema $targetSchema |
|
73 | + * @param \Doctrine\DBAL\Connection $connection |
|
74 | + * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
75 | + */ |
|
76 | + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
77 | + $platform = $connection->getDatabasePlatform(); |
|
78 | + $platform->registerDoctrineTypeMapping('tinyint unsigned', 'integer'); |
|
79 | + $platform->registerDoctrineTypeMapping('smallint unsigned', 'integer'); |
|
80 | + $platform->registerDoctrineTypeMapping('varchar ', 'string'); |
|
81 | 81 | |
82 | - // with sqlite autoincrement columns is of type integer |
|
83 | - foreach ($targetSchema->getTables() as $table) { |
|
84 | - foreach ($table->getColumns() as $column) { |
|
85 | - if ($column->getType() instanceof BigIntType && $column->getAutoincrement()) { |
|
86 | - $column->setType(Type::getType('integer')); |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
82 | + // with sqlite autoincrement columns is of type integer |
|
83 | + foreach ($targetSchema->getTables() as $table) { |
|
84 | + foreach ($table->getColumns() as $column) { |
|
85 | + if ($column->getType() instanceof BigIntType && $column->getAutoincrement()) { |
|
86 | + $column->setType(Type::getType('integer')); |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - return parent::getDiff($targetSchema, $connection); |
|
92 | - } |
|
91 | + return parent::getDiff($targetSchema, $connection); |
|
92 | + } |
|
93 | 93 | } |
@@ -25,12 +25,12 @@ |
||
25 | 25 | use OCP\IUser; |
26 | 26 | |
27 | 27 | trait FileAccess { |
28 | - protected function setupFS(IUser $user) { |
|
29 | - \OC_Util::setupFS($user->getUID()); |
|
30 | - } |
|
28 | + protected function setupFS(IUser $user) { |
|
29 | + \OC_Util::setupFS($user->getUID()); |
|
30 | + } |
|
31 | 31 | |
32 | - protected function getUserFolder(IUser $user) { |
|
33 | - $this->setupFS($user); |
|
34 | - return \OC::$server->getUserFolder($user->getUID()); |
|
35 | - } |
|
32 | + protected function getUserFolder(IUser $user) { |
|
33 | + $this->setupFS($user); |
|
34 | + return \OC::$server->getUserFolder($user->getUID()); |
|
35 | + } |
|
36 | 36 | } |
@@ -27,47 +27,47 @@ |
||
27 | 27 | namespace OC\Memcache; |
28 | 28 | |
29 | 29 | class NullCache extends Cache implements \OCP\IMemcache { |
30 | - public function get($key) { |
|
31 | - return null; |
|
32 | - } |
|
30 | + public function get($key) { |
|
31 | + return null; |
|
32 | + } |
|
33 | 33 | |
34 | - public function set($key, $value, $ttl = 0) { |
|
35 | - return true; |
|
36 | - } |
|
34 | + public function set($key, $value, $ttl = 0) { |
|
35 | + return true; |
|
36 | + } |
|
37 | 37 | |
38 | - public function hasKey($key) { |
|
39 | - return false; |
|
40 | - } |
|
38 | + public function hasKey($key) { |
|
39 | + return false; |
|
40 | + } |
|
41 | 41 | |
42 | - public function remove($key) { |
|
43 | - return true; |
|
44 | - } |
|
42 | + public function remove($key) { |
|
43 | + return true; |
|
44 | + } |
|
45 | 45 | |
46 | - public function add($key, $value, $ttl = 0) { |
|
47 | - return true; |
|
48 | - } |
|
46 | + public function add($key, $value, $ttl = 0) { |
|
47 | + return true; |
|
48 | + } |
|
49 | 49 | |
50 | - public function inc($key, $step = 1) { |
|
51 | - return true; |
|
52 | - } |
|
50 | + public function inc($key, $step = 1) { |
|
51 | + return true; |
|
52 | + } |
|
53 | 53 | |
54 | - public function dec($key, $step = 1) { |
|
55 | - return true; |
|
56 | - } |
|
54 | + public function dec($key, $step = 1) { |
|
55 | + return true; |
|
56 | + } |
|
57 | 57 | |
58 | - public function cas($key, $old, $new) { |
|
59 | - return true; |
|
60 | - } |
|
58 | + public function cas($key, $old, $new) { |
|
59 | + return true; |
|
60 | + } |
|
61 | 61 | |
62 | - public function cad($key, $old) { |
|
63 | - return true; |
|
64 | - } |
|
62 | + public function cad($key, $old) { |
|
63 | + return true; |
|
64 | + } |
|
65 | 65 | |
66 | - public function clear($prefix = '') { |
|
67 | - return true; |
|
68 | - } |
|
66 | + public function clear($prefix = '') { |
|
67 | + return true; |
|
68 | + } |
|
69 | 69 | |
70 | - public static function isAvailable() { |
|
71 | - return true; |
|
72 | - } |
|
70 | + public static function isAvailable() { |
|
71 | + return true; |
|
72 | + } |
|
73 | 73 | } |