@@ -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 | } |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | * @return null |
| 50 | 50 | */ |
| 51 | 51 | public function resynchronizeDatabaseSequences(Connection $conn) { |
| 52 | - $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 52 | + $filterExpression = '/^'.preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')).'/'; |
|
| 53 | 53 | $databaseName = $conn->getDatabase(); |
| 54 | 54 | $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
| 55 | 55 | |
@@ -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 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $this->loadTable($schema, $child); |
| 85 | 85 | break; |
| 86 | 86 | default: |
| 87 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 87 | + throw new \DomainException('Unknown element: '.$child->getName()); |
|
| 88 | 88 | |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | switch ($child->getName()) { |
| 106 | 106 | case 'name': |
| 107 | - $name = (string)$child; |
|
| 107 | + $name = (string) $child; |
|
| 108 | 108 | $name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name); |
| 109 | 109 | $name = $this->platform->quoteIdentifier($name); |
| 110 | 110 | $table = $schema->createTable($name); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $this->loadDeclaration($table, $child); |
| 121 | 121 | break; |
| 122 | 122 | default: |
| 123 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 123 | + throw new \DomainException('Unknown element: '.$child->getName()); |
|
| 124 | 124 | |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $this->loadIndex($table, $child); |
| 145 | 145 | break; |
| 146 | 146 | default: |
| 147 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 147 | + throw new \DomainException('Unknown element: '.$child->getName()); |
|
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | } |
@@ -156,18 +156,18 @@ discard block |
||
| 156 | 156 | * @throws \DomainException |
| 157 | 157 | */ |
| 158 | 158 | private function loadField($table, $xml) { |
| 159 | - $options = [ 'notnull' => false ]; |
|
| 159 | + $options = ['notnull' => false]; |
|
| 160 | 160 | foreach ($xml->children() as $child) { |
| 161 | 161 | /** |
| 162 | 162 | * @var \SimpleXMLElement $child |
| 163 | 163 | */ |
| 164 | 164 | switch ($child->getName()) { |
| 165 | 165 | case 'name': |
| 166 | - $name = (string)$child; |
|
| 166 | + $name = (string) $child; |
|
| 167 | 167 | $name = $this->platform->quoteIdentifier($name); |
| 168 | 168 | break; |
| 169 | 169 | case 'type': |
| 170 | - $type = (string)$child; |
|
| 170 | + $type = (string) $child; |
|
| 171 | 171 | switch ($type) { |
| 172 | 172 | case 'text': |
| 173 | 173 | $type = 'string'; |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | break; |
| 186 | 186 | case 'length': |
| 187 | - $length = (string)$child; |
|
| 187 | + $length = (string) $child; |
|
| 188 | 188 | $options['length'] = $length; |
| 189 | 189 | break; |
| 190 | 190 | case 'unsigned': |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | $options['autoincrement'] = $autoincrement; |
| 201 | 201 | break; |
| 202 | 202 | case 'default': |
| 203 | - $default = (string)$child; |
|
| 203 | + $default = (string) $child; |
|
| 204 | 204 | $options['default'] = $default; |
| 205 | 205 | break; |
| 206 | 206 | case 'comments': |
| 207 | - $comment = (string)$child; |
|
| 207 | + $comment = (string) $child; |
|
| 208 | 208 | $options['comment'] = $comment; |
| 209 | 209 | break; |
| 210 | 210 | case 'primary': |
@@ -212,15 +212,15 @@ discard block |
||
| 212 | 212 | $options['primary'] = $primary; |
| 213 | 213 | break; |
| 214 | 214 | case 'precision': |
| 215 | - $precision = (string)$child; |
|
| 215 | + $precision = (string) $child; |
|
| 216 | 216 | $options['precision'] = $precision; |
| 217 | 217 | break; |
| 218 | 218 | case 'scale': |
| 219 | - $scale = (string)$child; |
|
| 219 | + $scale = (string) $child; |
|
| 220 | 220 | $options['scale'] = $scale; |
| 221 | 221 | break; |
| 222 | 222 | default: |
| 223 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 223 | + throw new \DomainException('Unknown element: '.$child->getName()); |
|
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | if ($type === 'integer' && isset($options['default'])) { |
| 245 | - $options['default'] = (int)$options['default']; |
|
| 245 | + $options['default'] = (int) $options['default']; |
|
| 246 | 246 | } |
| 247 | 247 | if ($type === 'integer' && isset($options['length'])) { |
| 248 | 248 | $length = $options['length']; |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | switch ($child->getName()) { |
| 284 | 284 | case 'name': |
| 285 | - $name = (string)$child; |
|
| 285 | + $name = (string) $child; |
|
| 286 | 286 | break; |
| 287 | 287 | case 'primary': |
| 288 | 288 | $primary = $this->asBool($child); |
@@ -297,20 +297,20 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | switch ($field->getName()) { |
| 299 | 299 | case 'name': |
| 300 | - $field_name = (string)$field; |
|
| 300 | + $field_name = (string) $field; |
|
| 301 | 301 | $field_name = $this->platform->quoteIdentifier($field_name); |
| 302 | 302 | $fields[] = $field_name; |
| 303 | 303 | break; |
| 304 | 304 | case 'sorting': |
| 305 | 305 | break; |
| 306 | 306 | default: |
| 307 | - throw new \DomainException('Unknown element: ' . $field->getName()); |
|
| 307 | + throw new \DomainException('Unknown element: '.$field->getName()); |
|
| 308 | 308 | |
| 309 | 309 | } |
| 310 | 310 | } |
| 311 | 311 | break; |
| 312 | 312 | default: |
| 313 | - throw new \DomainException('Unknown element: ' . $child->getName()); |
|
| 313 | + throw new \DomainException('Unknown element: '.$child->getName()); |
|
| 314 | 314 | |
| 315 | 315 | } |
| 316 | 316 | } |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | } else { |
| 331 | - throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true)); |
|
| 331 | + throw new \DomainException('Empty index definition: '.$name.' options:'.print_r($fields, true)); |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | |
@@ -337,12 +337,12 @@ discard block |
||
| 337 | 337 | * @return bool |
| 338 | 338 | */ |
| 339 | 339 | private function asBool($xml) { |
| 340 | - $result = (string)$xml; |
|
| 340 | + $result = (string) $xml; |
|
| 341 | 341 | if ($result == 'true') { |
| 342 | 342 | $result = true; |
| 343 | 343 | } elseif ($result == 'false') { |
| 344 | 344 | $result = false; |
| 345 | 345 | } |
| 346 | - return (bool)$result; |
|
| 346 | + return (bool) $result; |
|
| 347 | 347 | } |
| 348 | 348 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function getTableNamesWithoutPrefix() { |
| 64 | 64 | $tableNames = $this->schema->getTableNames(); |
| 65 | - return array_map(function ($tableName) { |
|
| 65 | + return array_map(function($tableName) { |
|
| 66 | 66 | if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
| 67 | 67 | return substr($tableName, strlen($this->connection->getPrefix())); |
| 68 | 68 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @throws \Doctrine\DBAL\Schema\SchemaException |
| 81 | 81 | */ |
| 82 | 82 | public function getTable($tableName) { |
| 83 | - return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
| 83 | + return $this->schema->getTable($this->connection->getPrefix().$tableName); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return boolean |
| 92 | 92 | */ |
| 93 | 93 | public function hasTable($tableName) { |
| 94 | - return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
| 94 | + return $this->schema->hasTable($this->connection->getPrefix().$tableName); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @return \Doctrine\DBAL\Schema\Table |
| 102 | 102 | */ |
| 103 | 103 | public function createTable($tableName) { |
| 104 | - return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
| 104 | + return $this->schema->createTable($this->connection->getPrefix().$tableName); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function dropTable($tableName) { |
| 127 | 127 | $this->tablesToDelete[$tableName] = true; |
| 128 | - return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
| 128 | + return $this->schema->dropTable($this->connection->getPrefix().$tableName); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -29,107 +29,107 @@ |
||
| 29 | 29 | |
| 30 | 30 | class SchemaWrapper implements ISchemaWrapper { |
| 31 | 31 | |
| 32 | - /** @var IDBConnection|Connection */ |
|
| 33 | - protected $connection; |
|
| 34 | - |
|
| 35 | - /** @var Schema */ |
|
| 36 | - protected $schema; |
|
| 37 | - |
|
| 38 | - /** @var array */ |
|
| 39 | - protected $tablesToDelete = []; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param IDBConnection $connection |
|
| 43 | - */ |
|
| 44 | - public function __construct(IDBConnection $connection) { |
|
| 45 | - $this->connection = $connection; |
|
| 46 | - $this->schema = $this->connection->createSchema(); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - public function getWrappedSchema() { |
|
| 50 | - return $this->schema; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - public function performDropTableCalls() { |
|
| 54 | - foreach ($this->tablesToDelete as $tableName => $true) { |
|
| 55 | - $this->connection->dropTable($tableName); |
|
| 56 | - unset($this->tablesToDelete[$tableName]); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Gets all table names |
|
| 62 | - * |
|
| 63 | - * @return array |
|
| 64 | - */ |
|
| 65 | - public function getTableNamesWithoutPrefix() { |
|
| 66 | - $tableNames = $this->schema->getTableNames(); |
|
| 67 | - return array_map(function ($tableName) { |
|
| 68 | - if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
| 69 | - return substr($tableName, strlen($this->connection->getPrefix())); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return $tableName; |
|
| 73 | - }, $tableNames); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // Overwritten methods |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public function getTableNames() { |
|
| 82 | - return $this->schema->getTableNames(); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param string $tableName |
|
| 87 | - * |
|
| 88 | - * @return \Doctrine\DBAL\Schema\Table |
|
| 89 | - * @throws \Doctrine\DBAL\Schema\SchemaException |
|
| 90 | - */ |
|
| 91 | - public function getTable($tableName) { |
|
| 92 | - return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Does this schema have a table with the given name? |
|
| 97 | - * |
|
| 98 | - * @param string $tableName |
|
| 99 | - * |
|
| 100 | - * @return boolean |
|
| 101 | - */ |
|
| 102 | - public function hasTable($tableName) { |
|
| 103 | - return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Creates a new table. |
|
| 108 | - * |
|
| 109 | - * @param string $tableName |
|
| 110 | - * @return \Doctrine\DBAL\Schema\Table |
|
| 111 | - */ |
|
| 112 | - public function createTable($tableName) { |
|
| 113 | - return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Drops a table from the schema. |
|
| 118 | - * |
|
| 119 | - * @param string $tableName |
|
| 120 | - * @return \Doctrine\DBAL\Schema\Schema |
|
| 121 | - */ |
|
| 122 | - public function dropTable($tableName) { |
|
| 123 | - $this->tablesToDelete[$tableName] = true; |
|
| 124 | - return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Gets all tables of this schema. |
|
| 129 | - * |
|
| 130 | - * @return \Doctrine\DBAL\Schema\Table[] |
|
| 131 | - */ |
|
| 132 | - public function getTables() { |
|
| 133 | - return $this->schema->getTables(); |
|
| 134 | - } |
|
| 32 | + /** @var IDBConnection|Connection */ |
|
| 33 | + protected $connection; |
|
| 34 | + |
|
| 35 | + /** @var Schema */ |
|
| 36 | + protected $schema; |
|
| 37 | + |
|
| 38 | + /** @var array */ |
|
| 39 | + protected $tablesToDelete = []; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param IDBConnection $connection |
|
| 43 | + */ |
|
| 44 | + public function __construct(IDBConnection $connection) { |
|
| 45 | + $this->connection = $connection; |
|
| 46 | + $this->schema = $this->connection->createSchema(); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + public function getWrappedSchema() { |
|
| 50 | + return $this->schema; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + public function performDropTableCalls() { |
|
| 54 | + foreach ($this->tablesToDelete as $tableName => $true) { |
|
| 55 | + $this->connection->dropTable($tableName); |
|
| 56 | + unset($this->tablesToDelete[$tableName]); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Gets all table names |
|
| 62 | + * |
|
| 63 | + * @return array |
|
| 64 | + */ |
|
| 65 | + public function getTableNamesWithoutPrefix() { |
|
| 66 | + $tableNames = $this->schema->getTableNames(); |
|
| 67 | + return array_map(function ($tableName) { |
|
| 68 | + if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
| 69 | + return substr($tableName, strlen($this->connection->getPrefix())); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return $tableName; |
|
| 73 | + }, $tableNames); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // Overwritten methods |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public function getTableNames() { |
|
| 82 | + return $this->schema->getTableNames(); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param string $tableName |
|
| 87 | + * |
|
| 88 | + * @return \Doctrine\DBAL\Schema\Table |
|
| 89 | + * @throws \Doctrine\DBAL\Schema\SchemaException |
|
| 90 | + */ |
|
| 91 | + public function getTable($tableName) { |
|
| 92 | + return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Does this schema have a table with the given name? |
|
| 97 | + * |
|
| 98 | + * @param string $tableName |
|
| 99 | + * |
|
| 100 | + * @return boolean |
|
| 101 | + */ |
|
| 102 | + public function hasTable($tableName) { |
|
| 103 | + return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Creates a new table. |
|
| 108 | + * |
|
| 109 | + * @param string $tableName |
|
| 110 | + * @return \Doctrine\DBAL\Schema\Table |
|
| 111 | + */ |
|
| 112 | + public function createTable($tableName) { |
|
| 113 | + return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Drops a table from the schema. |
|
| 118 | + * |
|
| 119 | + * @param string $tableName |
|
| 120 | + * @return \Doctrine\DBAL\Schema\Schema |
|
| 121 | + */ |
|
| 122 | + public function dropTable($tableName) { |
|
| 123 | + $this->tablesToDelete[$tableName] = true; |
|
| 124 | + return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Gets all tables of this schema. |
|
| 129 | + * |
|
| 130 | + * @return \Doctrine\DBAL\Schema\Table[] |
|
| 131 | + */ |
|
| 132 | + public function getTables() { |
|
| 133 | + return $this->schema->getTables(); |
|
| 134 | + } |
|
| 135 | 135 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param string $table table name without the prefix |
| 83 | 83 | */ |
| 84 | 84 | public function dropTable($table) { |
| 85 | - $table = $this->tablePrefix . trim($table); |
|
| 85 | + $table = $this->tablePrefix.trim($table); |
|
| 86 | 86 | $table = $this->quoteIdentifier($table); |
| 87 | 87 | $schema = $this->getSchemaManager(); |
| 88 | 88 | if ($schema->tablesExist([$table])) { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * @return bool |
| 98 | 98 | */ |
| 99 | 99 | public function tableExists($table) { |
| 100 | - $table = $this->tablePrefix . trim($table); |
|
| 100 | + $table = $this->tablePrefix.trim($table); |
|
| 101 | 101 | $table = $this->quoteIdentifier($table); |
| 102 | 102 | $schema = $this->getSchemaManager(); |
| 103 | 103 | return $schema->tablesExist([$table]); |
@@ -28,80 +28,80 @@ |
||
| 28 | 28 | namespace OC\DB; |
| 29 | 29 | |
| 30 | 30 | class OracleConnection extends Connection { |
| 31 | - /** |
|
| 32 | - * Quote the keys of the array |
|
| 33 | - */ |
|
| 34 | - private function quoteKeys(array $data) { |
|
| 35 | - $return = []; |
|
| 36 | - $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
| 37 | - foreach ($data as $key => $value) { |
|
| 38 | - if ($key[0] !== $c) { |
|
| 39 | - $return[$this->quoteIdentifier($key)] = $value; |
|
| 40 | - } else { |
|
| 41 | - $return[$key] = $value; |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - return $return; |
|
| 45 | - } |
|
| 31 | + /** |
|
| 32 | + * Quote the keys of the array |
|
| 33 | + */ |
|
| 34 | + private function quoteKeys(array $data) { |
|
| 35 | + $return = []; |
|
| 36 | + $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
| 37 | + foreach ($data as $key => $value) { |
|
| 38 | + if ($key[0] !== $c) { |
|
| 39 | + $return[$this->quoteIdentifier($key)] = $value; |
|
| 40 | + } else { |
|
| 41 | + $return[$key] = $value; |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + return $return; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * {@inheritDoc} |
|
| 49 | - */ |
|
| 50 | - public function insert($tableExpression, array $data, array $types = []) { |
|
| 51 | - if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 52 | - $tableExpression = $this->quoteIdentifier($tableExpression); |
|
| 53 | - } |
|
| 54 | - $data = $this->quoteKeys($data); |
|
| 55 | - return parent::insert($tableExpression, $data, $types); |
|
| 56 | - } |
|
| 47 | + /** |
|
| 48 | + * {@inheritDoc} |
|
| 49 | + */ |
|
| 50 | + public function insert($tableExpression, array $data, array $types = []) { |
|
| 51 | + if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 52 | + $tableExpression = $this->quoteIdentifier($tableExpression); |
|
| 53 | + } |
|
| 54 | + $data = $this->quoteKeys($data); |
|
| 55 | + return parent::insert($tableExpression, $data, $types); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * {@inheritDoc} |
|
| 60 | - */ |
|
| 61 | - public function update($tableExpression, array $data, array $identifier, array $types = []) { |
|
| 62 | - if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 63 | - $tableExpression = $this->quoteIdentifier($tableExpression); |
|
| 64 | - } |
|
| 65 | - $data = $this->quoteKeys($data); |
|
| 66 | - $identifier = $this->quoteKeys($identifier); |
|
| 67 | - return parent::update($tableExpression, $data, $identifier, $types); |
|
| 68 | - } |
|
| 58 | + /** |
|
| 59 | + * {@inheritDoc} |
|
| 60 | + */ |
|
| 61 | + public function update($tableExpression, array $data, array $identifier, array $types = []) { |
|
| 62 | + if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 63 | + $tableExpression = $this->quoteIdentifier($tableExpression); |
|
| 64 | + } |
|
| 65 | + $data = $this->quoteKeys($data); |
|
| 66 | + $identifier = $this->quoteKeys($identifier); |
|
| 67 | + return parent::update($tableExpression, $data, $identifier, $types); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * {@inheritDoc} |
|
| 72 | - */ |
|
| 73 | - public function delete($tableExpression, array $identifier, array $types = []) { |
|
| 74 | - if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 75 | - $tableExpression = $this->quoteIdentifier($tableExpression); |
|
| 76 | - } |
|
| 77 | - $identifier = $this->quoteKeys($identifier); |
|
| 78 | - return parent::delete($tableExpression, $identifier); |
|
| 79 | - } |
|
| 70 | + /** |
|
| 71 | + * {@inheritDoc} |
|
| 72 | + */ |
|
| 73 | + public function delete($tableExpression, array $identifier, array $types = []) { |
|
| 74 | + if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 75 | + $tableExpression = $this->quoteIdentifier($tableExpression); |
|
| 76 | + } |
|
| 77 | + $identifier = $this->quoteKeys($identifier); |
|
| 78 | + return parent::delete($tableExpression, $identifier); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Drop a table from the database if it exists |
|
| 83 | - * |
|
| 84 | - * @param string $table table name without the prefix |
|
| 85 | - */ |
|
| 86 | - public function dropTable($table) { |
|
| 87 | - $table = $this->tablePrefix . trim($table); |
|
| 88 | - $table = $this->quoteIdentifier($table); |
|
| 89 | - $schema = $this->getSchemaManager(); |
|
| 90 | - if ($schema->tablesExist([$table])) { |
|
| 91 | - $schema->dropTable($table); |
|
| 92 | - } |
|
| 93 | - } |
|
| 81 | + /** |
|
| 82 | + * Drop a table from the database if it exists |
|
| 83 | + * |
|
| 84 | + * @param string $table table name without the prefix |
|
| 85 | + */ |
|
| 86 | + public function dropTable($table) { |
|
| 87 | + $table = $this->tablePrefix . trim($table); |
|
| 88 | + $table = $this->quoteIdentifier($table); |
|
| 89 | + $schema = $this->getSchemaManager(); |
|
| 90 | + if ($schema->tablesExist([$table])) { |
|
| 91 | + $schema->dropTable($table); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Check if a table exists |
|
| 97 | - * |
|
| 98 | - * @param string $table table name without the prefix |
|
| 99 | - * @return bool |
|
| 100 | - */ |
|
| 101 | - public function tableExists($table) { |
|
| 102 | - $table = $this->tablePrefix . trim($table); |
|
| 103 | - $table = $this->quoteIdentifier($table); |
|
| 104 | - $schema = $this->getSchemaManager(); |
|
| 105 | - return $schema->tablesExist([$table]); |
|
| 106 | - } |
|
| 95 | + /** |
|
| 96 | + * Check if a table exists |
|
| 97 | + * |
|
| 98 | + * @param string $table table name without the prefix |
|
| 99 | + * @return bool |
|
| 100 | + */ |
|
| 101 | + public function tableExists($table) { |
|
| 102 | + $table = $this->tablePrefix . trim($table); |
|
| 103 | + $table = $this->quoteIdentifier($table); |
|
| 104 | + $schema = $this->getSchemaManager(); |
|
| 105 | + return $schema->tablesExist([$table]); |
|
| 106 | + } |
|
| 107 | 107 | } |
@@ -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 | } |
@@ -51,9 +51,9 @@ |
||
| 51 | 51 | |
| 52 | 52 | // FIX ME: bloody work around |
| 53 | 53 | if ($config->getSystemValue('dbtype', 'sqlite') === 'oci') { |
| 54 | - $filterExpression = '/^"' . preg_quote($conn->getPrefix()) . '/'; |
|
| 54 | + $filterExpression = '/^"'.preg_quote($conn->getPrefix()).'/'; |
|
| 55 | 55 | } else { |
| 56 | - $filterExpression = '/^' . preg_quote($conn->getPrefix()) . '/'; |
|
| 56 | + $filterExpression = '/^'.preg_quote($conn->getPrefix()).'/'; |
|
| 57 | 57 | } |
| 58 | 58 | $conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
| 59 | 59 | |
@@ -333,7 +333,7 @@ |
||
| 333 | 333 | */ |
| 334 | 334 | protected function registerCoreProvider($class, $mimeType, $options = []) { |
| 335 | 335 | if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
| 336 | - $this->registerProvider($mimeType, function () use ($class, $options) { |
|
| 336 | + $this->registerProvider($mimeType, function() use ($class, $options) { |
|
| 337 | 337 | return new $class($options); |
| 338 | 338 | }); |
| 339 | 339 | } |
@@ -44,389 +44,389 @@ |
||
| 44 | 44 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
| 45 | 45 | |
| 46 | 46 | class PreviewManager implements IPreview { |
| 47 | - /** @var IConfig */ |
|
| 48 | - protected $config; |
|
| 47 | + /** @var IConfig */ |
|
| 48 | + protected $config; |
|
| 49 | 49 | |
| 50 | - /** @var IRootFolder */ |
|
| 51 | - protected $rootFolder; |
|
| 50 | + /** @var IRootFolder */ |
|
| 51 | + protected $rootFolder; |
|
| 52 | 52 | |
| 53 | - /** @var IAppData */ |
|
| 54 | - protected $appData; |
|
| 53 | + /** @var IAppData */ |
|
| 54 | + protected $appData; |
|
| 55 | 55 | |
| 56 | - /** @var EventDispatcherInterface */ |
|
| 57 | - protected $eventDispatcher; |
|
| 56 | + /** @var EventDispatcherInterface */ |
|
| 57 | + protected $eventDispatcher; |
|
| 58 | 58 | |
| 59 | - /** @var Generator */ |
|
| 60 | - private $generator; |
|
| 59 | + /** @var Generator */ |
|
| 60 | + private $generator; |
|
| 61 | 61 | |
| 62 | - /** @var GeneratorHelper */ |
|
| 63 | - private $helper; |
|
| 64 | - |
|
| 65 | - /** @var bool */ |
|
| 66 | - protected $providerListDirty = false; |
|
| 67 | - |
|
| 68 | - /** @var bool */ |
|
| 69 | - protected $registeredCoreProviders = false; |
|
| 70 | - |
|
| 71 | - /** @var array */ |
|
| 72 | - protected $providers = []; |
|
| 73 | - |
|
| 74 | - /** @var array mime type => support status */ |
|
| 75 | - protected $mimeTypeSupportMap = []; |
|
| 76 | - |
|
| 77 | - /** @var array */ |
|
| 78 | - protected $defaultProviders; |
|
| 79 | - |
|
| 80 | - /** @var string */ |
|
| 81 | - protected $userId; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * PreviewManager constructor. |
|
| 85 | - * |
|
| 86 | - * @param IConfig $config |
|
| 87 | - * @param IRootFolder $rootFolder |
|
| 88 | - * @param IAppData $appData |
|
| 89 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 90 | - * @param string $userId |
|
| 91 | - */ |
|
| 92 | - public function __construct(IConfig $config, |
|
| 93 | - IRootFolder $rootFolder, |
|
| 94 | - IAppData $appData, |
|
| 95 | - EventDispatcherInterface $eventDispatcher, |
|
| 96 | - GeneratorHelper $helper, |
|
| 97 | - $userId) { |
|
| 98 | - $this->config = $config; |
|
| 99 | - $this->rootFolder = $rootFolder; |
|
| 100 | - $this->appData = $appData; |
|
| 101 | - $this->eventDispatcher = $eventDispatcher; |
|
| 102 | - $this->helper = $helper; |
|
| 103 | - $this->userId = $userId; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * In order to improve lazy loading a closure can be registered which will be |
|
| 108 | - * called in case preview providers are actually requested |
|
| 109 | - * |
|
| 110 | - * $callable has to return an instance of \OCP\Preview\IProvider or \OCP\Preview\IProviderV2 |
|
| 111 | - * |
|
| 112 | - * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider |
|
| 113 | - * @param \Closure $callable |
|
| 114 | - * @return void |
|
| 115 | - */ |
|
| 116 | - public function registerProvider($mimeTypeRegex, \Closure $callable) { |
|
| 117 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 118 | - return; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if (!isset($this->providers[$mimeTypeRegex])) { |
|
| 122 | - $this->providers[$mimeTypeRegex] = []; |
|
| 123 | - } |
|
| 124 | - $this->providers[$mimeTypeRegex][] = $callable; |
|
| 125 | - $this->providerListDirty = true; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Get all providers |
|
| 130 | - * @return array |
|
| 131 | - */ |
|
| 132 | - public function getProviders() { |
|
| 133 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 134 | - return []; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $this->registerCoreProviders(); |
|
| 138 | - if ($this->providerListDirty) { |
|
| 139 | - $keys = array_map('strlen', array_keys($this->providers)); |
|
| 140 | - array_multisort($keys, SORT_DESC, $this->providers); |
|
| 141 | - $this->providerListDirty = false; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $this->providers; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Does the manager have any providers |
|
| 149 | - * @return bool |
|
| 150 | - */ |
|
| 151 | - public function hasProviders() { |
|
| 152 | - $this->registerCoreProviders(); |
|
| 153 | - return !empty($this->providers); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - private function getGenerator(): Generator { |
|
| 157 | - if ($this->generator === null) { |
|
| 158 | - $this->generator = new Generator( |
|
| 159 | - $this->config, |
|
| 160 | - $this, |
|
| 161 | - $this->appData, |
|
| 162 | - new GeneratorHelper( |
|
| 163 | - $this->rootFolder, |
|
| 164 | - $this->config |
|
| 165 | - ), |
|
| 166 | - $this->eventDispatcher |
|
| 167 | - ); |
|
| 168 | - } |
|
| 169 | - return $this->generator; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Returns a preview of a file |
|
| 174 | - * |
|
| 175 | - * The cache is searched first and if nothing usable was found then a preview is |
|
| 176 | - * generated by one of the providers |
|
| 177 | - * |
|
| 178 | - * @param File $file |
|
| 179 | - * @param int $width |
|
| 180 | - * @param int $height |
|
| 181 | - * @param bool $crop |
|
| 182 | - * @param string $mode |
|
| 183 | - * @param string $mimeType |
|
| 184 | - * @return ISimpleFile |
|
| 185 | - * @throws NotFoundException |
|
| 186 | - * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
| 187 | - * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 |
|
| 188 | - */ |
|
| 189 | - public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { |
|
| 190 | - return $this->getGenerator()->getPreview($file, $width, $height, $crop, $mode, $mimeType); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Generates previews of a file |
|
| 195 | - * |
|
| 196 | - * @param File $file |
|
| 197 | - * @param array $specifications |
|
| 198 | - * @param string $mimeType |
|
| 199 | - * @return ISimpleFile the last preview that was generated |
|
| 200 | - * @throws NotFoundException |
|
| 201 | - * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
| 202 | - * @since 19.0.0 |
|
| 203 | - */ |
|
| 204 | - public function generatePreviews(File $file, array $specifications, $mimeType = null) { |
|
| 205 | - return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * returns true if the passed mime type is supported |
|
| 210 | - * |
|
| 211 | - * @param string $mimeType |
|
| 212 | - * @return boolean |
|
| 213 | - */ |
|
| 214 | - public function isMimeSupported($mimeType = '*') { |
|
| 215 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 216 | - return false; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - if (isset($this->mimeTypeSupportMap[$mimeType])) { |
|
| 220 | - return $this->mimeTypeSupportMap[$mimeType]; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $this->registerCoreProviders(); |
|
| 224 | - $providerMimeTypes = array_keys($this->providers); |
|
| 225 | - foreach ($providerMimeTypes as $supportedMimeType) { |
|
| 226 | - if (preg_match($supportedMimeType, $mimeType)) { |
|
| 227 | - $this->mimeTypeSupportMap[$mimeType] = true; |
|
| 228 | - return true; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - $this->mimeTypeSupportMap[$mimeType] = false; |
|
| 232 | - return false; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Check if a preview can be generated for a file |
|
| 237 | - * |
|
| 238 | - * @param \OCP\Files\FileInfo $file |
|
| 239 | - * @return bool |
|
| 240 | - */ |
|
| 241 | - public function isAvailable(\OCP\Files\FileInfo $file) { |
|
| 242 | - if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $this->registerCoreProviders(); |
|
| 247 | - if (!$this->isMimeSupported($file->getMimetype())) { |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $mount = $file->getMountPoint(); |
|
| 252 | - if ($mount and !$mount->getOption('previews', true)) { |
|
| 253 | - return false; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - foreach ($this->providers as $supportedMimeType => $providers) { |
|
| 257 | - if (preg_match($supportedMimeType, $file->getMimetype())) { |
|
| 258 | - foreach ($providers as $providerClosure) { |
|
| 259 | - $provider = $this->helper->getProvider($providerClosure); |
|
| 260 | - if (!($provider instanceof IProviderV2)) { |
|
| 261 | - continue; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - if ($provider->isAvailable($file)) { |
|
| 265 | - return true; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - return false; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * List of enabled default providers |
|
| 275 | - * |
|
| 276 | - * The following providers are enabled by default: |
|
| 277 | - * - OC\Preview\PNG |
|
| 278 | - * - OC\Preview\JPEG |
|
| 279 | - * - OC\Preview\GIF |
|
| 280 | - * - OC\Preview\BMP |
|
| 281 | - * - OC\Preview\HEIC |
|
| 282 | - * - OC\Preview\XBitmap |
|
| 283 | - * - OC\Preview\MarkDown |
|
| 284 | - * - OC\Preview\MP3 |
|
| 285 | - * - OC\Preview\TXT |
|
| 286 | - * |
|
| 287 | - * The following providers are disabled by default due to performance or privacy concerns: |
|
| 288 | - * - OC\Preview\Font |
|
| 289 | - * - OC\Preview\Illustrator |
|
| 290 | - * - OC\Preview\Movie |
|
| 291 | - * - OC\Preview\MSOfficeDoc |
|
| 292 | - * - OC\Preview\MSOffice2003 |
|
| 293 | - * - OC\Preview\MSOffice2007 |
|
| 294 | - * - OC\Preview\OpenDocument |
|
| 295 | - * - OC\Preview\PDF |
|
| 296 | - * - OC\Preview\Photoshop |
|
| 297 | - * - OC\Preview\Postscript |
|
| 298 | - * - OC\Preview\StarOffice |
|
| 299 | - * - OC\Preview\SVG |
|
| 300 | - * - OC\Preview\TIFF |
|
| 301 | - * |
|
| 302 | - * @return array |
|
| 303 | - */ |
|
| 304 | - protected function getEnabledDefaultProvider() { |
|
| 305 | - if ($this->defaultProviders !== null) { |
|
| 306 | - return $this->defaultProviders; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $imageProviders = [ |
|
| 310 | - Preview\PNG::class, |
|
| 311 | - Preview\JPEG::class, |
|
| 312 | - Preview\GIF::class, |
|
| 313 | - Preview\BMP::class, |
|
| 314 | - Preview\HEIC::class, |
|
| 315 | - Preview\XBitmap::class, |
|
| 316 | - Preview\Krita::class, |
|
| 317 | - ]; |
|
| 318 | - |
|
| 319 | - $this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([ |
|
| 320 | - Preview\MarkDown::class, |
|
| 321 | - Preview\MP3::class, |
|
| 322 | - Preview\TXT::class, |
|
| 323 | - Preview\OpenDocument::class, |
|
| 324 | - ], $imageProviders)); |
|
| 325 | - |
|
| 326 | - if (in_array(Preview\Image::class, $this->defaultProviders)) { |
|
| 327 | - $this->defaultProviders = array_merge($this->defaultProviders, $imageProviders); |
|
| 328 | - } |
|
| 329 | - $this->defaultProviders = array_unique($this->defaultProviders); |
|
| 330 | - return $this->defaultProviders; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * Register the default providers (if enabled) |
|
| 335 | - * |
|
| 336 | - * @param string $class |
|
| 337 | - * @param string $mimeType |
|
| 338 | - */ |
|
| 339 | - protected function registerCoreProvider($class, $mimeType, $options = []) { |
|
| 340 | - if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
| 341 | - $this->registerProvider($mimeType, function () use ($class, $options) { |
|
| 342 | - return new $class($options); |
|
| 343 | - }); |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Register the default providers (if enabled) |
|
| 349 | - */ |
|
| 350 | - protected function registerCoreProviders() { |
|
| 351 | - if ($this->registeredCoreProviders) { |
|
| 352 | - return; |
|
| 353 | - } |
|
| 354 | - $this->registeredCoreProviders = true; |
|
| 355 | - |
|
| 356 | - $this->registerCoreProvider(Preview\TXT::class, '/text\/plain/'); |
|
| 357 | - $this->registerCoreProvider(Preview\MarkDown::class, '/text\/(x-)?markdown/'); |
|
| 358 | - $this->registerCoreProvider(Preview\PNG::class, '/image\/png/'); |
|
| 359 | - $this->registerCoreProvider(Preview\JPEG::class, '/image\/jpeg/'); |
|
| 360 | - $this->registerCoreProvider(Preview\GIF::class, '/image\/gif/'); |
|
| 361 | - $this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/'); |
|
| 362 | - $this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/'); |
|
| 363 | - $this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/'); |
|
| 364 | - $this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/'); |
|
| 365 | - $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
| 366 | - |
|
| 367 | - // SVG, Office and Bitmap require imagick |
|
| 368 | - if (extension_loaded('imagick')) { |
|
| 369 | - $checkImagick = new \Imagick(); |
|
| 370 | - |
|
| 371 | - $imagickProviders = [ |
|
| 372 | - 'SVG' => ['mimetype' => '/image\/svg\+xml/', 'class' => Preview\SVG::class], |
|
| 373 | - 'TIFF' => ['mimetype' => '/image\/tiff/', 'class' => Preview\TIFF::class], |
|
| 374 | - 'PDF' => ['mimetype' => '/application\/pdf/', 'class' => Preview\PDF::class], |
|
| 375 | - 'AI' => ['mimetype' => '/application\/illustrator/', 'class' => Preview\Illustrator::class], |
|
| 376 | - 'PSD' => ['mimetype' => '/application\/x-photoshop/', 'class' => Preview\Photoshop::class], |
|
| 377 | - 'EPS' => ['mimetype' => '/application\/postscript/', 'class' => Preview\Postscript::class], |
|
| 378 | - 'TTF' => ['mimetype' => '/application\/(?:font-sfnt|x-font$)/', 'class' => Preview\Font::class], |
|
| 379 | - 'HEIC' => ['mimetype' => '/image\/hei(f|c)/', 'class' => Preview\HEIC::class], |
|
| 380 | - ]; |
|
| 381 | - |
|
| 382 | - foreach ($imagickProviders as $queryFormat => $provider) { |
|
| 383 | - $class = $provider['class']; |
|
| 384 | - if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
| 385 | - continue; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if (count($checkImagick->queryFormats($queryFormat)) === 1) { |
|
| 389 | - $this->registerCoreProvider($class, $provider['mimetype']); |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if (count($checkImagick->queryFormats('PDF')) === 1) { |
|
| 394 | - if (\OC_Helper::is_function_enabled('shell_exec')) { |
|
| 395 | - $officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null)); |
|
| 396 | - |
|
| 397 | - if (!$officeFound) { |
|
| 398 | - //let's see if there is libreoffice or openoffice on this machine |
|
| 399 | - $whichLibreOffice = shell_exec('command -v libreoffice'); |
|
| 400 | - $officeFound = !empty($whichLibreOffice); |
|
| 401 | - if (!$officeFound) { |
|
| 402 | - $whichOpenOffice = shell_exec('command -v openoffice'); |
|
| 403 | - $officeFound = !empty($whichOpenOffice); |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - if ($officeFound) { |
|
| 408 | - $this->registerCoreProvider(Preview\MSOfficeDoc::class, '/application\/msword/'); |
|
| 409 | - $this->registerCoreProvider(Preview\MSOffice2003::class, '/application\/vnd.ms-.*/'); |
|
| 410 | - $this->registerCoreProvider(Preview\MSOffice2007::class, '/application\/vnd.openxmlformats-officedocument.*/'); |
|
| 411 | - $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
| 412 | - $this->registerCoreProvider(Preview\StarOffice::class, '/application\/vnd.sun.xml.*/'); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - // Video requires avconv or ffmpeg |
|
| 419 | - if (in_array(Preview\Movie::class, $this->getEnabledDefaultProvider())) { |
|
| 420 | - $avconvBinary = \OC_Helper::findBinaryPath('avconv'); |
|
| 421 | - $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg'); |
|
| 422 | - |
|
| 423 | - if ($avconvBinary || $ffmpegBinary) { |
|
| 424 | - // FIXME // a bit hacky but didn't want to use subclasses |
|
| 425 | - \OC\Preview\Movie::$avconvBinary = $avconvBinary; |
|
| 426 | - \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary; |
|
| 427 | - |
|
| 428 | - $this->registerCoreProvider(Preview\Movie::class, '/video\/.*/'); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 62 | + /** @var GeneratorHelper */ |
|
| 63 | + private $helper; |
|
| 64 | + |
|
| 65 | + /** @var bool */ |
|
| 66 | + protected $providerListDirty = false; |
|
| 67 | + |
|
| 68 | + /** @var bool */ |
|
| 69 | + protected $registeredCoreProviders = false; |
|
| 70 | + |
|
| 71 | + /** @var array */ |
|
| 72 | + protected $providers = []; |
|
| 73 | + |
|
| 74 | + /** @var array mime type => support status */ |
|
| 75 | + protected $mimeTypeSupportMap = []; |
|
| 76 | + |
|
| 77 | + /** @var array */ |
|
| 78 | + protected $defaultProviders; |
|
| 79 | + |
|
| 80 | + /** @var string */ |
|
| 81 | + protected $userId; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * PreviewManager constructor. |
|
| 85 | + * |
|
| 86 | + * @param IConfig $config |
|
| 87 | + * @param IRootFolder $rootFolder |
|
| 88 | + * @param IAppData $appData |
|
| 89 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 90 | + * @param string $userId |
|
| 91 | + */ |
|
| 92 | + public function __construct(IConfig $config, |
|
| 93 | + IRootFolder $rootFolder, |
|
| 94 | + IAppData $appData, |
|
| 95 | + EventDispatcherInterface $eventDispatcher, |
|
| 96 | + GeneratorHelper $helper, |
|
| 97 | + $userId) { |
|
| 98 | + $this->config = $config; |
|
| 99 | + $this->rootFolder = $rootFolder; |
|
| 100 | + $this->appData = $appData; |
|
| 101 | + $this->eventDispatcher = $eventDispatcher; |
|
| 102 | + $this->helper = $helper; |
|
| 103 | + $this->userId = $userId; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * In order to improve lazy loading a closure can be registered which will be |
|
| 108 | + * called in case preview providers are actually requested |
|
| 109 | + * |
|
| 110 | + * $callable has to return an instance of \OCP\Preview\IProvider or \OCP\Preview\IProviderV2 |
|
| 111 | + * |
|
| 112 | + * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider |
|
| 113 | + * @param \Closure $callable |
|
| 114 | + * @return void |
|
| 115 | + */ |
|
| 116 | + public function registerProvider($mimeTypeRegex, \Closure $callable) { |
|
| 117 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 118 | + return; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if (!isset($this->providers[$mimeTypeRegex])) { |
|
| 122 | + $this->providers[$mimeTypeRegex] = []; |
|
| 123 | + } |
|
| 124 | + $this->providers[$mimeTypeRegex][] = $callable; |
|
| 125 | + $this->providerListDirty = true; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Get all providers |
|
| 130 | + * @return array |
|
| 131 | + */ |
|
| 132 | + public function getProviders() { |
|
| 133 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 134 | + return []; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $this->registerCoreProviders(); |
|
| 138 | + if ($this->providerListDirty) { |
|
| 139 | + $keys = array_map('strlen', array_keys($this->providers)); |
|
| 140 | + array_multisort($keys, SORT_DESC, $this->providers); |
|
| 141 | + $this->providerListDirty = false; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $this->providers; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Does the manager have any providers |
|
| 149 | + * @return bool |
|
| 150 | + */ |
|
| 151 | + public function hasProviders() { |
|
| 152 | + $this->registerCoreProviders(); |
|
| 153 | + return !empty($this->providers); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + private function getGenerator(): Generator { |
|
| 157 | + if ($this->generator === null) { |
|
| 158 | + $this->generator = new Generator( |
|
| 159 | + $this->config, |
|
| 160 | + $this, |
|
| 161 | + $this->appData, |
|
| 162 | + new GeneratorHelper( |
|
| 163 | + $this->rootFolder, |
|
| 164 | + $this->config |
|
| 165 | + ), |
|
| 166 | + $this->eventDispatcher |
|
| 167 | + ); |
|
| 168 | + } |
|
| 169 | + return $this->generator; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Returns a preview of a file |
|
| 174 | + * |
|
| 175 | + * The cache is searched first and if nothing usable was found then a preview is |
|
| 176 | + * generated by one of the providers |
|
| 177 | + * |
|
| 178 | + * @param File $file |
|
| 179 | + * @param int $width |
|
| 180 | + * @param int $height |
|
| 181 | + * @param bool $crop |
|
| 182 | + * @param string $mode |
|
| 183 | + * @param string $mimeType |
|
| 184 | + * @return ISimpleFile |
|
| 185 | + * @throws NotFoundException |
|
| 186 | + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
| 187 | + * @since 11.0.0 - \InvalidArgumentException was added in 12.0.0 |
|
| 188 | + */ |
|
| 189 | + public function getPreview(File $file, $width = -1, $height = -1, $crop = false, $mode = IPreview::MODE_FILL, $mimeType = null) { |
|
| 190 | + return $this->getGenerator()->getPreview($file, $width, $height, $crop, $mode, $mimeType); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Generates previews of a file |
|
| 195 | + * |
|
| 196 | + * @param File $file |
|
| 197 | + * @param array $specifications |
|
| 198 | + * @param string $mimeType |
|
| 199 | + * @return ISimpleFile the last preview that was generated |
|
| 200 | + * @throws NotFoundException |
|
| 201 | + * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid) |
|
| 202 | + * @since 19.0.0 |
|
| 203 | + */ |
|
| 204 | + public function generatePreviews(File $file, array $specifications, $mimeType = null) { |
|
| 205 | + return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * returns true if the passed mime type is supported |
|
| 210 | + * |
|
| 211 | + * @param string $mimeType |
|
| 212 | + * @return boolean |
|
| 213 | + */ |
|
| 214 | + public function isMimeSupported($mimeType = '*') { |
|
| 215 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + if (isset($this->mimeTypeSupportMap[$mimeType])) { |
|
| 220 | + return $this->mimeTypeSupportMap[$mimeType]; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $this->registerCoreProviders(); |
|
| 224 | + $providerMimeTypes = array_keys($this->providers); |
|
| 225 | + foreach ($providerMimeTypes as $supportedMimeType) { |
|
| 226 | + if (preg_match($supportedMimeType, $mimeType)) { |
|
| 227 | + $this->mimeTypeSupportMap[$mimeType] = true; |
|
| 228 | + return true; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + $this->mimeTypeSupportMap[$mimeType] = false; |
|
| 232 | + return false; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Check if a preview can be generated for a file |
|
| 237 | + * |
|
| 238 | + * @param \OCP\Files\FileInfo $file |
|
| 239 | + * @return bool |
|
| 240 | + */ |
|
| 241 | + public function isAvailable(\OCP\Files\FileInfo $file) { |
|
| 242 | + if (!$this->config->getSystemValue('enable_previews', true)) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $this->registerCoreProviders(); |
|
| 247 | + if (!$this->isMimeSupported($file->getMimetype())) { |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $mount = $file->getMountPoint(); |
|
| 252 | + if ($mount and !$mount->getOption('previews', true)) { |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + foreach ($this->providers as $supportedMimeType => $providers) { |
|
| 257 | + if (preg_match($supportedMimeType, $file->getMimetype())) { |
|
| 258 | + foreach ($providers as $providerClosure) { |
|
| 259 | + $provider = $this->helper->getProvider($providerClosure); |
|
| 260 | + if (!($provider instanceof IProviderV2)) { |
|
| 261 | + continue; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + if ($provider->isAvailable($file)) { |
|
| 265 | + return true; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + return false; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * List of enabled default providers |
|
| 275 | + * |
|
| 276 | + * The following providers are enabled by default: |
|
| 277 | + * - OC\Preview\PNG |
|
| 278 | + * - OC\Preview\JPEG |
|
| 279 | + * - OC\Preview\GIF |
|
| 280 | + * - OC\Preview\BMP |
|
| 281 | + * - OC\Preview\HEIC |
|
| 282 | + * - OC\Preview\XBitmap |
|
| 283 | + * - OC\Preview\MarkDown |
|
| 284 | + * - OC\Preview\MP3 |
|
| 285 | + * - OC\Preview\TXT |
|
| 286 | + * |
|
| 287 | + * The following providers are disabled by default due to performance or privacy concerns: |
|
| 288 | + * - OC\Preview\Font |
|
| 289 | + * - OC\Preview\Illustrator |
|
| 290 | + * - OC\Preview\Movie |
|
| 291 | + * - OC\Preview\MSOfficeDoc |
|
| 292 | + * - OC\Preview\MSOffice2003 |
|
| 293 | + * - OC\Preview\MSOffice2007 |
|
| 294 | + * - OC\Preview\OpenDocument |
|
| 295 | + * - OC\Preview\PDF |
|
| 296 | + * - OC\Preview\Photoshop |
|
| 297 | + * - OC\Preview\Postscript |
|
| 298 | + * - OC\Preview\StarOffice |
|
| 299 | + * - OC\Preview\SVG |
|
| 300 | + * - OC\Preview\TIFF |
|
| 301 | + * |
|
| 302 | + * @return array |
|
| 303 | + */ |
|
| 304 | + protected function getEnabledDefaultProvider() { |
|
| 305 | + if ($this->defaultProviders !== null) { |
|
| 306 | + return $this->defaultProviders; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $imageProviders = [ |
|
| 310 | + Preview\PNG::class, |
|
| 311 | + Preview\JPEG::class, |
|
| 312 | + Preview\GIF::class, |
|
| 313 | + Preview\BMP::class, |
|
| 314 | + Preview\HEIC::class, |
|
| 315 | + Preview\XBitmap::class, |
|
| 316 | + Preview\Krita::class, |
|
| 317 | + ]; |
|
| 318 | + |
|
| 319 | + $this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([ |
|
| 320 | + Preview\MarkDown::class, |
|
| 321 | + Preview\MP3::class, |
|
| 322 | + Preview\TXT::class, |
|
| 323 | + Preview\OpenDocument::class, |
|
| 324 | + ], $imageProviders)); |
|
| 325 | + |
|
| 326 | + if (in_array(Preview\Image::class, $this->defaultProviders)) { |
|
| 327 | + $this->defaultProviders = array_merge($this->defaultProviders, $imageProviders); |
|
| 328 | + } |
|
| 329 | + $this->defaultProviders = array_unique($this->defaultProviders); |
|
| 330 | + return $this->defaultProviders; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * Register the default providers (if enabled) |
|
| 335 | + * |
|
| 336 | + * @param string $class |
|
| 337 | + * @param string $mimeType |
|
| 338 | + */ |
|
| 339 | + protected function registerCoreProvider($class, $mimeType, $options = []) { |
|
| 340 | + if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
| 341 | + $this->registerProvider($mimeType, function () use ($class, $options) { |
|
| 342 | + return new $class($options); |
|
| 343 | + }); |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Register the default providers (if enabled) |
|
| 349 | + */ |
|
| 350 | + protected function registerCoreProviders() { |
|
| 351 | + if ($this->registeredCoreProviders) { |
|
| 352 | + return; |
|
| 353 | + } |
|
| 354 | + $this->registeredCoreProviders = true; |
|
| 355 | + |
|
| 356 | + $this->registerCoreProvider(Preview\TXT::class, '/text\/plain/'); |
|
| 357 | + $this->registerCoreProvider(Preview\MarkDown::class, '/text\/(x-)?markdown/'); |
|
| 358 | + $this->registerCoreProvider(Preview\PNG::class, '/image\/png/'); |
|
| 359 | + $this->registerCoreProvider(Preview\JPEG::class, '/image\/jpeg/'); |
|
| 360 | + $this->registerCoreProvider(Preview\GIF::class, '/image\/gif/'); |
|
| 361 | + $this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/'); |
|
| 362 | + $this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/'); |
|
| 363 | + $this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/'); |
|
| 364 | + $this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg/'); |
|
| 365 | + $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
| 366 | + |
|
| 367 | + // SVG, Office and Bitmap require imagick |
|
| 368 | + if (extension_loaded('imagick')) { |
|
| 369 | + $checkImagick = new \Imagick(); |
|
| 370 | + |
|
| 371 | + $imagickProviders = [ |
|
| 372 | + 'SVG' => ['mimetype' => '/image\/svg\+xml/', 'class' => Preview\SVG::class], |
|
| 373 | + 'TIFF' => ['mimetype' => '/image\/tiff/', 'class' => Preview\TIFF::class], |
|
| 374 | + 'PDF' => ['mimetype' => '/application\/pdf/', 'class' => Preview\PDF::class], |
|
| 375 | + 'AI' => ['mimetype' => '/application\/illustrator/', 'class' => Preview\Illustrator::class], |
|
| 376 | + 'PSD' => ['mimetype' => '/application\/x-photoshop/', 'class' => Preview\Photoshop::class], |
|
| 377 | + 'EPS' => ['mimetype' => '/application\/postscript/', 'class' => Preview\Postscript::class], |
|
| 378 | + 'TTF' => ['mimetype' => '/application\/(?:font-sfnt|x-font$)/', 'class' => Preview\Font::class], |
|
| 379 | + 'HEIC' => ['mimetype' => '/image\/hei(f|c)/', 'class' => Preview\HEIC::class], |
|
| 380 | + ]; |
|
| 381 | + |
|
| 382 | + foreach ($imagickProviders as $queryFormat => $provider) { |
|
| 383 | + $class = $provider['class']; |
|
| 384 | + if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) { |
|
| 385 | + continue; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if (count($checkImagick->queryFormats($queryFormat)) === 1) { |
|
| 389 | + $this->registerCoreProvider($class, $provider['mimetype']); |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if (count($checkImagick->queryFormats('PDF')) === 1) { |
|
| 394 | + if (\OC_Helper::is_function_enabled('shell_exec')) { |
|
| 395 | + $officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null)); |
|
| 396 | + |
|
| 397 | + if (!$officeFound) { |
|
| 398 | + //let's see if there is libreoffice or openoffice on this machine |
|
| 399 | + $whichLibreOffice = shell_exec('command -v libreoffice'); |
|
| 400 | + $officeFound = !empty($whichLibreOffice); |
|
| 401 | + if (!$officeFound) { |
|
| 402 | + $whichOpenOffice = shell_exec('command -v openoffice'); |
|
| 403 | + $officeFound = !empty($whichOpenOffice); |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + if ($officeFound) { |
|
| 408 | + $this->registerCoreProvider(Preview\MSOfficeDoc::class, '/application\/msword/'); |
|
| 409 | + $this->registerCoreProvider(Preview\MSOffice2003::class, '/application\/vnd.ms-.*/'); |
|
| 410 | + $this->registerCoreProvider(Preview\MSOffice2007::class, '/application\/vnd.openxmlformats-officedocument.*/'); |
|
| 411 | + $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/'); |
|
| 412 | + $this->registerCoreProvider(Preview\StarOffice::class, '/application\/vnd.sun.xml.*/'); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + // Video requires avconv or ffmpeg |
|
| 419 | + if (in_array(Preview\Movie::class, $this->getEnabledDefaultProvider())) { |
|
| 420 | + $avconvBinary = \OC_Helper::findBinaryPath('avconv'); |
|
| 421 | + $ffmpegBinary = $avconvBinary ? null : \OC_Helper::findBinaryPath('ffmpeg'); |
|
| 422 | + |
|
| 423 | + if ($avconvBinary || $ffmpegBinary) { |
|
| 424 | + // FIXME // a bit hacky but didn't want to use subclasses |
|
| 425 | + \OC\Preview\Movie::$avconvBinary = $avconvBinary; |
|
| 426 | + \OC\Preview\Movie::$ffmpegBinary = $ffmpegBinary; |
|
| 427 | + |
|
| 428 | + $this->registerCoreProvider(Preview\Movie::class, '/video\/.*/'); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | 432 | } |
@@ -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 | } |