@@ -33,84 +33,84 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class Adapter { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var \OC\DB\Connection $conn |
|
| 38 | - */ |
|
| 39 | - protected $conn; |
|
| 36 | + /** |
|
| 37 | + * @var \OC\DB\Connection $conn |
|
| 38 | + */ |
|
| 39 | + protected $conn; |
|
| 40 | 40 | |
| 41 | - public function __construct($conn) { |
|
| 42 | - $this->conn = $conn; |
|
| 43 | - } |
|
| 41 | + public function __construct($conn) { |
|
| 42 | + $this->conn = $conn; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param string $table name |
|
| 47 | - * @return int id of last insert statement |
|
| 48 | - */ |
|
| 49 | - public function lastInsertId($table) { |
|
| 50 | - return $this->conn->realLastInsertId($table); |
|
| 51 | - } |
|
| 45 | + /** |
|
| 46 | + * @param string $table name |
|
| 47 | + * @return int id of last insert statement |
|
| 48 | + */ |
|
| 49 | + public function lastInsertId($table) { |
|
| 50 | + return $this->conn->realLastInsertId($table); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @param string $statement that needs to be changed so the db can handle it |
|
| 55 | - * @return string changed statement |
|
| 56 | - */ |
|
| 57 | - public function fixupStatement($statement) { |
|
| 58 | - return $statement; |
|
| 59 | - } |
|
| 53 | + /** |
|
| 54 | + * @param string $statement that needs to be changed so the db can handle it |
|
| 55 | + * @return string changed statement |
|
| 56 | + */ |
|
| 57 | + public function fixupStatement($statement) { |
|
| 58 | + return $statement; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Create an exclusive read+write lock on a table |
|
| 63 | - * |
|
| 64 | - * @param string $tableName |
|
| 65 | - * @since 9.1.0 |
|
| 66 | - */ |
|
| 67 | - public function lockTable($tableName) { |
|
| 68 | - $this->conn->beginTransaction(); |
|
| 69 | - $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
| 70 | - } |
|
| 61 | + /** |
|
| 62 | + * Create an exclusive read+write lock on a table |
|
| 63 | + * |
|
| 64 | + * @param string $tableName |
|
| 65 | + * @since 9.1.0 |
|
| 66 | + */ |
|
| 67 | + public function lockTable($tableName) { |
|
| 68 | + $this->conn->beginTransaction(); |
|
| 69 | + $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Release a previous acquired lock again |
|
| 74 | - * |
|
| 75 | - * @since 9.1.0 |
|
| 76 | - */ |
|
| 77 | - public function unlockTable() { |
|
| 78 | - $this->conn->commit(); |
|
| 79 | - } |
|
| 72 | + /** |
|
| 73 | + * Release a previous acquired lock again |
|
| 74 | + * |
|
| 75 | + * @since 9.1.0 |
|
| 76 | + */ |
|
| 77 | + public function unlockTable() { |
|
| 78 | + $this->conn->commit(); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Insert a row if the matching row does not exists. |
|
| 83 | - * |
|
| 84 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
| 85 | - * @param array $input data that should be inserted into the table (column name => value) |
|
| 86 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
| 87 | - * If this is null or an empty array, all keys of $input will be compared |
|
| 88 | - * Please note: text fields (clob) must not be used in the compare array |
|
| 89 | - * @return int number of inserted rows |
|
| 90 | - * @throws \Doctrine\DBAL\DBALException |
|
| 91 | - */ |
|
| 92 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
| 93 | - if (empty($compare)) { |
|
| 94 | - $compare = array_keys($input); |
|
| 95 | - } |
|
| 96 | - $query = 'INSERT INTO `' .$table . '` (`' |
|
| 97 | - . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
| 98 | - . str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative? |
|
| 99 | - . 'FROM `' . $table . '` WHERE '; |
|
| 81 | + /** |
|
| 82 | + * Insert a row if the matching row does not exists. |
|
| 83 | + * |
|
| 84 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
| 85 | + * @param array $input data that should be inserted into the table (column name => value) |
|
| 86 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
| 87 | + * If this is null or an empty array, all keys of $input will be compared |
|
| 88 | + * Please note: text fields (clob) must not be used in the compare array |
|
| 89 | + * @return int number of inserted rows |
|
| 90 | + * @throws \Doctrine\DBAL\DBALException |
|
| 91 | + */ |
|
| 92 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
| 93 | + if (empty($compare)) { |
|
| 94 | + $compare = array_keys($input); |
|
| 95 | + } |
|
| 96 | + $query = 'INSERT INTO `' .$table . '` (`' |
|
| 97 | + . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
| 98 | + . str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative? |
|
| 99 | + . 'FROM `' . $table . '` WHERE '; |
|
| 100 | 100 | |
| 101 | - $inserts = array_values($input); |
|
| 102 | - foreach($compare as $key) { |
|
| 103 | - $query .= '`' . $key . '`'; |
|
| 104 | - if (is_null($input[$key])) { |
|
| 105 | - $query .= ' IS NULL AND '; |
|
| 106 | - } else { |
|
| 107 | - $inserts[] = $input[$key]; |
|
| 108 | - $query .= ' = ? AND '; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - $query = substr($query, 0, strlen($query) - 5); |
|
| 112 | - $query .= ' HAVING COUNT(*) = 0'; |
|
| 101 | + $inserts = array_values($input); |
|
| 102 | + foreach($compare as $key) { |
|
| 103 | + $query .= '`' . $key . '`'; |
|
| 104 | + if (is_null($input[$key])) { |
|
| 105 | + $query .= ' IS NULL AND '; |
|
| 106 | + } else { |
|
| 107 | + $inserts[] = $input[$key]; |
|
| 108 | + $query .= ' = ? AND '; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + $query = substr($query, 0, strlen($query) - 5); |
|
| 112 | + $query .= ' HAVING COUNT(*) = 0'; |
|
| 113 | 113 | |
| 114 | - return $this->conn->executeUpdate($query, $inserts); |
|
| 115 | - } |
|
| 114 | + return $this->conn->executeUpdate($query, $inserts); |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function lockTable($tableName) { |
| 68 | 68 | $this->conn->beginTransaction(); |
| 69 | - $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
| 69 | + $this->conn->executeUpdate('LOCK TABLE `'.$tableName.'` IN EXCLUSIVE MODE'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | if (empty($compare)) { |
| 94 | 94 | $compare = array_keys($input); |
| 95 | 95 | } |
| 96 | - $query = 'INSERT INTO `' .$table . '` (`' |
|
| 97 | - . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
| 98 | - . str_repeat('?,', count($input)-1).'? ' // Is there a prettier alternative? |
|
| 99 | - . 'FROM `' . $table . '` WHERE '; |
|
| 96 | + $query = 'INSERT INTO `'.$table.'` (`' |
|
| 97 | + . implode('`,`', array_keys($input)).'`) SELECT ' |
|
| 98 | + . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
|
| 99 | + . 'FROM `'.$table.'` WHERE '; |
|
| 100 | 100 | |
| 101 | 101 | $inserts = array_values($input); |
| 102 | - foreach($compare as $key) { |
|
| 103 | - $query .= '`' . $key . '`'; |
|
| 102 | + foreach ($compare as $key) { |
|
| 103 | + $query .= '`'.$key.'`'; |
|
| 104 | 104 | if (is_null($input[$key])) { |
| 105 | 105 | $query .= ' IS NULL AND '; |
| 106 | 106 | } else { |
@@ -27,31 +27,31 @@ |
||
| 27 | 27 | |
| 28 | 28 | class AdapterMySQL extends Adapter { |
| 29 | 29 | |
| 30 | - /** @var string */ |
|
| 31 | - protected $charset; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @param string $tableName |
|
| 35 | - */ |
|
| 36 | - public function lockTable($tableName) { |
|
| 37 | - $this->conn->executeUpdate('LOCK TABLES `' .$tableName . '` WRITE'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public function unlockTable() { |
|
| 41 | - $this->conn->executeUpdate('UNLOCK TABLES'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public function fixupStatement($statement) { |
|
| 45 | - $statement = str_replace(' ILIKE ', ' COLLATE ' . $this->getCharset() . '_general_ci LIKE ', $statement); |
|
| 46 | - return $statement; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - protected function getCharset() { |
|
| 50 | - if (!$this->charset) { |
|
| 51 | - $params = $this->conn->getParams(); |
|
| 52 | - $this->charset = isset($params['charset']) ? $params['charset'] : 'utf8'; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return $this->charset; |
|
| 56 | - } |
|
| 30 | + /** @var string */ |
|
| 31 | + protected $charset; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @param string $tableName |
|
| 35 | + */ |
|
| 36 | + public function lockTable($tableName) { |
|
| 37 | + $this->conn->executeUpdate('LOCK TABLES `' .$tableName . '` WRITE'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public function unlockTable() { |
|
| 41 | + $this->conn->executeUpdate('UNLOCK TABLES'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public function fixupStatement($statement) { |
|
| 45 | + $statement = str_replace(' ILIKE ', ' COLLATE ' . $this->getCharset() . '_general_ci LIKE ', $statement); |
|
| 46 | + return $statement; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + protected function getCharset() { |
|
| 50 | + if (!$this->charset) { |
|
| 51 | + $params = $this->conn->getParams(); |
|
| 52 | + $this->charset = isset($params['charset']) ? $params['charset'] : 'utf8'; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return $this->charset; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @param string $tableName |
| 35 | 35 | */ |
| 36 | 36 | public function lockTable($tableName) { |
| 37 | - $this->conn->executeUpdate('LOCK TABLES `' .$tableName . '` WRITE'); |
|
| 37 | + $this->conn->executeUpdate('LOCK TABLES `'.$tableName.'` WRITE'); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public function unlockTable() { |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public function fixupStatement($statement) { |
| 45 | - $statement = str_replace(' ILIKE ', ' COLLATE ' . $this->getCharset() . '_general_ci LIKE ', $statement); |
|
| 45 | + $statement = str_replace(' ILIKE ', ' COLLATE '.$this->getCharset().'_general_ci LIKE ', $statement); |
|
| 46 | 46 | return $statement; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -25,17 +25,17 @@ |
||
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | class MigrationException extends \Exception { |
| 28 | - private $table; |
|
| 28 | + private $table; |
|
| 29 | 29 | |
| 30 | - public function __construct($table, $message) { |
|
| 31 | - $this->table = $table; |
|
| 32 | - parent::__construct($message); |
|
| 33 | - } |
|
| 30 | + public function __construct($table, $message) { |
|
| 31 | + $this->table = $table; |
|
| 32 | + parent::__construct($message); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function getTable() { |
|
| 39 | - return $this->table; |
|
| 40 | - } |
|
| 35 | + /** |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function getTable() { |
|
| 39 | + return $this->table; |
|
| 40 | + } |
|
| 41 | 41 | } |
@@ -31,153 +31,153 @@ |
||
| 31 | 31 | |
| 32 | 32 | class MDB2SchemaWriter { |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param string $file |
|
| 36 | - * @param \OC\DB\Connection $conn |
|
| 37 | - * @return bool |
|
| 38 | - */ |
|
| 39 | - static public function saveSchemaToFile($file, \OC\DB\Connection $conn) { |
|
| 40 | - $config = \OC::$server->getConfig(); |
|
| 34 | + /** |
|
| 35 | + * @param string $file |
|
| 36 | + * @param \OC\DB\Connection $conn |
|
| 37 | + * @return bool |
|
| 38 | + */ |
|
| 39 | + static public function saveSchemaToFile($file, \OC\DB\Connection $conn) { |
|
| 40 | + $config = \OC::$server->getConfig(); |
|
| 41 | 41 | |
| 42 | - $xml = new \SimpleXMLElement('<database/>'); |
|
| 43 | - $xml->addChild('name', $config->getSystemValue('dbname', 'owncloud')); |
|
| 44 | - $xml->addChild('create', 'true'); |
|
| 45 | - $xml->addChild('overwrite', 'false'); |
|
| 46 | - 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 | - } |
|
| 120 | - elseif ($column->getType() == 'BigInt') { |
|
| 121 | - $length = '8'; |
|
| 122 | - } |
|
| 123 | - $xml->addChild('length', $length); |
|
| 124 | - break; |
|
| 125 | - case 'String': |
|
| 126 | - $xml->addChild('type', 'text'); |
|
| 127 | - $default = trim($column->getDefault()); |
|
| 128 | - if ($default === '') { |
|
| 129 | - $default = false; |
|
| 130 | - } |
|
| 131 | - $xml->addChild('default', $default); |
|
| 132 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 133 | - $xml->addChild('length', $column->getLength()); |
|
| 134 | - break; |
|
| 135 | - case 'Text': |
|
| 136 | - $xml->addChild('type', 'clob'); |
|
| 137 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 138 | - break; |
|
| 139 | - case 'Decimal': |
|
| 140 | - $xml->addChild('type', 'decimal'); |
|
| 141 | - $xml->addChild('default', $column->getDefault()); |
|
| 142 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 143 | - $xml->addChild('length', '15'); |
|
| 144 | - break; |
|
| 145 | - case 'Boolean': |
|
| 146 | - $xml->addChild('type', 'integer'); |
|
| 147 | - $xml->addChild('default', $column->getDefault()); |
|
| 148 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 149 | - $xml->addChild('length', '1'); |
|
| 150 | - break; |
|
| 151 | - case 'DateTime': |
|
| 152 | - $xml->addChild('type', 'timestamp'); |
|
| 153 | - $xml->addChild('default', $column->getDefault()); |
|
| 154 | - $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 155 | - 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 | + } |
|
| 120 | + elseif ($column->getType() == 'BigInt') { |
|
| 121 | + $length = '8'; |
|
| 122 | + } |
|
| 123 | + $xml->addChild('length', $length); |
|
| 124 | + break; |
|
| 125 | + case 'String': |
|
| 126 | + $xml->addChild('type', 'text'); |
|
| 127 | + $default = trim($column->getDefault()); |
|
| 128 | + if ($default === '') { |
|
| 129 | + $default = false; |
|
| 130 | + } |
|
| 131 | + $xml->addChild('default', $default); |
|
| 132 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 133 | + $xml->addChild('length', $column->getLength()); |
|
| 134 | + break; |
|
| 135 | + case 'Text': |
|
| 136 | + $xml->addChild('type', 'clob'); |
|
| 137 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 138 | + break; |
|
| 139 | + case 'Decimal': |
|
| 140 | + $xml->addChild('type', 'decimal'); |
|
| 141 | + $xml->addChild('default', $column->getDefault()); |
|
| 142 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 143 | + $xml->addChild('length', '15'); |
|
| 144 | + break; |
|
| 145 | + case 'Boolean': |
|
| 146 | + $xml->addChild('type', 'integer'); |
|
| 147 | + $xml->addChild('default', $column->getDefault()); |
|
| 148 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 149 | + $xml->addChild('length', '1'); |
|
| 150 | + break; |
|
| 151 | + case 'DateTime': |
|
| 152 | + $xml->addChild('type', 'timestamp'); |
|
| 153 | + $xml->addChild('default', $column->getDefault()); |
|
| 154 | + $xml->addChild('notnull', self::toBool($column->getNotnull())); |
|
| 155 | + break; |
|
| 156 | 156 | |
| 157 | - } |
|
| 158 | - } |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * @param Index $index |
|
| 162 | - * @param \SimpleXMLElement $xml |
|
| 163 | - */ |
|
| 164 | - private static function saveIndex($index, $xml) { |
|
| 165 | - $xml->addChild('name', $index->getName()); |
|
| 166 | - if ($index->isPrimary()) { |
|
| 167 | - $xml->addChild('primary', 'true'); |
|
| 168 | - } |
|
| 169 | - elseif ($index->isUnique()) { |
|
| 170 | - $xml->addChild('unique', 'true'); |
|
| 171 | - } |
|
| 172 | - foreach($index->getColumns() as $column) { |
|
| 173 | - $field = $xml->addChild('field'); |
|
| 174 | - $field->addChild('name', $column); |
|
| 175 | - $field->addChild('sorting', 'ascending'); |
|
| 160 | + /** |
|
| 161 | + * @param Index $index |
|
| 162 | + * @param \SimpleXMLElement $xml |
|
| 163 | + */ |
|
| 164 | + private static function saveIndex($index, $xml) { |
|
| 165 | + $xml->addChild('name', $index->getName()); |
|
| 166 | + if ($index->isPrimary()) { |
|
| 167 | + $xml->addChild('primary', 'true'); |
|
| 168 | + } |
|
| 169 | + elseif ($index->isUnique()) { |
|
| 170 | + $xml->addChild('unique', 'true'); |
|
| 171 | + } |
|
| 172 | + foreach($index->getColumns() as $column) { |
|
| 173 | + $field = $xml->addChild('field'); |
|
| 174 | + $field->addChild('name', $column); |
|
| 175 | + $field->addChild('sorting', 'ascending'); |
|
| 176 | 176 | |
| 177 | - } |
|
| 178 | - } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - private static function toBool($bool) { |
|
| 181 | - return $bool ? 'true' : 'false'; |
|
| 182 | - } |
|
| 180 | + private static function toBool($bool) { |
|
| 181 | + return $bool ? 'true' : 'false'; |
|
| 182 | + } |
|
| 183 | 183 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $xml->addChild('name', $config->getSystemValue('dbname', 'owncloud')); |
| 44 | 44 | $xml->addChild('create', 'true'); |
| 45 | 45 | $xml->addChild('overwrite', 'false'); |
| 46 | - if($config->getSystemValue('dbtype', 'sqlite') === 'mysql' && $config->getSystemValue('mysql.utf8mb4', false)) { |
|
| 46 | + if ($config->getSystemValue('dbtype', 'sqlite') === 'mysql' && $config->getSystemValue('mysql.utf8mb4', false)) { |
|
| 47 | 47 | $xml->addChild('charset', 'utf8mb4'); |
| 48 | 48 | } else { |
| 49 | 49 | $xml->addChild('charset', 'utf8'); |
@@ -51,9 +51,9 @@ discard block |
||
| 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 | |
@@ -71,13 +71,13 @@ discard block |
||
| 71 | 71 | private static function saveTable($table, $xml) { |
| 72 | 72 | $xml->addChild('name', $table->getName()); |
| 73 | 73 | $declaration = $xml->addChild('declaration'); |
| 74 | - foreach($table->getColumns() as $column) { |
|
| 74 | + foreach ($table->getColumns() as $column) { |
|
| 75 | 75 | self::saveColumn($column, $declaration->addChild('field')); |
| 76 | 76 | } |
| 77 | - foreach($table->getIndexes() as $index) { |
|
| 77 | + foreach ($table->getIndexes() as $index) { |
|
| 78 | 78 | if ($index->getName() == 'PRIMARY') { |
| 79 | 79 | $autoincrement = false; |
| 80 | - foreach($index->getColumns() as $column) { |
|
| 80 | + foreach ($index->getColumns() as $column) { |
|
| 81 | 81 | if ($table->getColumn($column)->getAutoincrement()) { |
| 82 | 82 | $autoincrement = true; |
| 83 | 83 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | private static function saveColumn($column, $xml) { |
| 98 | 98 | $xml->addChild('name', $column->getName()); |
| 99 | - switch($column->getType()) { |
|
| 99 | + switch ($column->getType()) { |
|
| 100 | 100 | case 'SmallInt': |
| 101 | 101 | case 'Integer': |
| 102 | 102 | case 'BigInt': |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | elseif ($index->isUnique()) { |
| 170 | 170 | $xml->addChild('unique', 'true'); |
| 171 | 171 | } |
| 172 | - foreach($index->getColumns() as $column) { |
|
| 172 | + foreach ($index->getColumns() as $column) { |
|
| 173 | 173 | $field = $xml->addChild('field'); |
| 174 | 174 | $field->addChild('name', $column); |
| 175 | 175 | $field->addChild('sorting', 'ascending'); |
@@ -116,8 +116,7 @@ discard block |
||
| 116 | 116 | $length = '4'; |
| 117 | 117 | if ($column->getType() == 'SmallInt') { |
| 118 | 118 | $length = '2'; |
| 119 | - } |
|
| 120 | - elseif ($column->getType() == 'BigInt') { |
|
| 119 | + } elseif ($column->getType() == 'BigInt') { |
|
| 121 | 120 | $length = '8'; |
| 122 | 121 | } |
| 123 | 122 | $xml->addChild('length', $length); |
@@ -165,8 +164,7 @@ discard block |
||
| 165 | 164 | $xml->addChild('name', $index->getName()); |
| 166 | 165 | if ($index->isPrimary()) { |
| 167 | 166 | $xml->addChild('primary', 'true'); |
| 168 | - } |
|
| 169 | - elseif ($index->isUnique()) { |
|
| 167 | + } elseif ($index->isUnique()) { |
|
| 170 | 168 | $xml->addChild('unique', 'true'); |
| 171 | 169 | } |
| 172 | 170 | foreach($index->getColumns() as $column) { |
@@ -32,62 +32,62 @@ |
||
| 32 | 32 | |
| 33 | 33 | class SQLiteMigrator extends Migrator { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 37 | - * @throws \OC\DB\MigrationException |
|
| 38 | - * |
|
| 39 | - * For sqlite we simple make a copy of the entire database, and test the migration on that |
|
| 40 | - */ |
|
| 41 | - public function checkMigrate(\Doctrine\DBAL\Schema\Schema $targetSchema) { |
|
| 42 | - $dbFile = $this->connection->getDatabase(); |
|
| 43 | - $tmpFile = $this->buildTempDatabase(); |
|
| 44 | - copy($dbFile, $tmpFile); |
|
| 35 | + /** |
|
| 36 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 37 | + * @throws \OC\DB\MigrationException |
|
| 38 | + * |
|
| 39 | + * For sqlite we simple make a copy of the entire database, and test the migration on that |
|
| 40 | + */ |
|
| 41 | + public function checkMigrate(\Doctrine\DBAL\Schema\Schema $targetSchema) { |
|
| 42 | + $dbFile = $this->connection->getDatabase(); |
|
| 43 | + $tmpFile = $this->buildTempDatabase(); |
|
| 44 | + copy($dbFile, $tmpFile); |
|
| 45 | 45 | |
| 46 | - $connectionParams = array( |
|
| 47 | - 'path' => $tmpFile, |
|
| 48 | - 'driver' => 'pdo_sqlite', |
|
| 49 | - ); |
|
| 50 | - $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams); |
|
| 51 | - try { |
|
| 52 | - $this->applySchema($targetSchema, $conn); |
|
| 53 | - $conn->close(); |
|
| 54 | - unlink($tmpFile); |
|
| 55 | - } catch (DBALException $e) { |
|
| 56 | - $conn->close(); |
|
| 57 | - unlink($tmpFile); |
|
| 58 | - throw new MigrationException('', $e->getMessage()); |
|
| 59 | - } |
|
| 60 | - } |
|
| 46 | + $connectionParams = array( |
|
| 47 | + 'path' => $tmpFile, |
|
| 48 | + 'driver' => 'pdo_sqlite', |
|
| 49 | + ); |
|
| 50 | + $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams); |
|
| 51 | + try { |
|
| 52 | + $this->applySchema($targetSchema, $conn); |
|
| 53 | + $conn->close(); |
|
| 54 | + unlink($tmpFile); |
|
| 55 | + } catch (DBALException $e) { |
|
| 56 | + $conn->close(); |
|
| 57 | + unlink($tmpFile); |
|
| 58 | + throw new MigrationException('', $e->getMessage()); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - private function buildTempDatabase() { |
|
| 66 | - $dataDir = $this->config->getSystemValue("datadirectory", \OC::$SERVERROOT . '/data'); |
|
| 67 | - $tmpFile = uniqid("oc_"); |
|
| 68 | - return "$dataDir/$tmpFile.db"; |
|
| 69 | - } |
|
| 62 | + /** |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + private function buildTempDatabase() { |
|
| 66 | + $dataDir = $this->config->getSystemValue("datadirectory", \OC::$SERVERROOT . '/data'); |
|
| 67 | + $tmpFile = uniqid("oc_"); |
|
| 68 | + return "$dataDir/$tmpFile.db"; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param Schema $targetSchema |
|
| 73 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 74 | - * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 75 | - */ |
|
| 76 | - protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 77 | - $platform = $connection->getDatabasePlatform(); |
|
| 78 | - $platform->registerDoctrineTypeMapping('tinyint unsigned', 'integer'); |
|
| 79 | - $platform->registerDoctrineTypeMapping('smallint unsigned', 'integer'); |
|
| 80 | - $platform->registerDoctrineTypeMapping('varchar ', 'string'); |
|
| 71 | + /** |
|
| 72 | + * @param Schema $targetSchema |
|
| 73 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 74 | + * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 75 | + */ |
|
| 76 | + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 77 | + $platform = $connection->getDatabasePlatform(); |
|
| 78 | + $platform->registerDoctrineTypeMapping('tinyint unsigned', 'integer'); |
|
| 79 | + $platform->registerDoctrineTypeMapping('smallint unsigned', 'integer'); |
|
| 80 | + $platform->registerDoctrineTypeMapping('varchar ', 'string'); |
|
| 81 | 81 | |
| 82 | - // with sqlite autoincrement columns is of type integer |
|
| 83 | - foreach ($targetSchema->getTables() as $table) { |
|
| 84 | - foreach ($table->getColumns() as $column) { |
|
| 85 | - if ($column->getType() instanceof BigIntType && $column->getAutoincrement()) { |
|
| 86 | - $column->setType(Type::getType('integer')); |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 82 | + // with sqlite autoincrement columns is of type integer |
|
| 83 | + foreach ($targetSchema->getTables() as $table) { |
|
| 84 | + foreach ($table->getColumns() as $column) { |
|
| 85 | + if ($column->getType() instanceof BigIntType && $column->getAutoincrement()) { |
|
| 86 | + $column->setType(Type::getType('integer')); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return parent::getDiff($targetSchema, $connection); |
|
| 92 | - } |
|
| 91 | + return parent::getDiff($targetSchema, $connection); |
|
| 92 | + } |
|
| 93 | 93 | } |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | * @return string |
| 64 | 64 | */ |
| 65 | 65 | private function buildTempDatabase() { |
| 66 | - $dataDir = $this->config->getSystemValue("datadirectory", \OC::$SERVERROOT . '/data'); |
|
| 66 | + $dataDir = $this->config->getSystemValue("datadirectory", \OC::$SERVERROOT.'/data'); |
|
| 67 | 67 | $tmpFile = uniqid("oc_"); |
| 68 | 68 | return "$dataDir/$tmpFile.db"; |
| 69 | 69 | } |
@@ -25,14 +25,14 @@ |
||
| 25 | 25 | namespace OC\DB; |
| 26 | 26 | |
| 27 | 27 | class AdapterPgSql extends Adapter { |
| 28 | - public function lastInsertId($table) { |
|
| 29 | - return $this->conn->fetchColumn('SELECT lastval()'); |
|
| 30 | - } |
|
| 28 | + public function lastInsertId($table) { |
|
| 29 | + return $this->conn->fetchColumn('SELECT lastval()'); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - const UNIX_TIMESTAMP_REPLACEMENT = 'cast(extract(epoch from current_timestamp) as integer)'; |
|
| 33 | - public function fixupStatement($statement) { |
|
| 34 | - $statement = str_replace( '`', '"', $statement ); |
|
| 35 | - $statement = str_ireplace( 'UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement ); |
|
| 36 | - return $statement; |
|
| 37 | - } |
|
| 32 | + const UNIX_TIMESTAMP_REPLACEMENT = 'cast(extract(epoch from current_timestamp) as integer)'; |
|
| 33 | + public function fixupStatement($statement) { |
|
| 34 | + $statement = str_replace( '`', '"', $statement ); |
|
| 35 | + $statement = str_ireplace( 'UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement ); |
|
| 36 | + return $statement; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -31,8 +31,8 @@ |
||
| 31 | 31 | |
| 32 | 32 | const UNIX_TIMESTAMP_REPLACEMENT = 'cast(extract(epoch from current_timestamp) as integer)'; |
| 33 | 33 | public function fixupStatement($statement) { |
| 34 | - $statement = str_replace( '`', '"', $statement ); |
|
| 35 | - $statement = str_ireplace( 'UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement ); |
|
| 34 | + $statement = str_replace('`', '"', $statement); |
|
| 35 | + $statement = str_ireplace('UNIX_TIMESTAMP()', self::UNIX_TIMESTAMP_REPLACEMENT, $statement); |
|
| 36 | 36 | return $statement; |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -36,66 +36,66 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class Platform { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param IConfig $config |
|
| 41 | - */ |
|
| 42 | - function __construct(IConfig $config) { |
|
| 43 | - $this->config = $config; |
|
| 44 | - } |
|
| 39 | + /** |
|
| 40 | + * @param IConfig $config |
|
| 41 | + */ |
|
| 42 | + function __construct(IConfig $config) { |
|
| 43 | + $this->config = $config; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public function getPhpVersion() { |
|
| 50 | - return phpversion(); |
|
| 51 | - } |
|
| 46 | + /** |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public function getPhpVersion() { |
|
| 50 | + return phpversion(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return int |
|
| 55 | - */ |
|
| 56 | - public function getIntSize() { |
|
| 57 | - return PHP_INT_SIZE; |
|
| 58 | - } |
|
| 53 | + /** |
|
| 54 | + * @return int |
|
| 55 | + */ |
|
| 56 | + public function getIntSize() { |
|
| 57 | + return PHP_INT_SIZE; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function getOcVersion() { |
|
| 64 | - $v = \OCP\Util::getVersion(); |
|
| 65 | - return join('.', $v); |
|
| 66 | - } |
|
| 60 | + /** |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function getOcVersion() { |
|
| 64 | + $v = \OCP\Util::getVersion(); |
|
| 65 | + return join('.', $v); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @return string |
|
| 70 | - */ |
|
| 71 | - public function getDatabase() { |
|
| 72 | - $dbType = $this->config->getSystemValue('dbtype', 'sqlite'); |
|
| 73 | - if ($dbType === 'sqlite3') { |
|
| 74 | - $dbType = 'sqlite'; |
|
| 75 | - } |
|
| 68 | + /** |
|
| 69 | + * @return string |
|
| 70 | + */ |
|
| 71 | + public function getDatabase() { |
|
| 72 | + $dbType = $this->config->getSystemValue('dbtype', 'sqlite'); |
|
| 73 | + if ($dbType === 'sqlite3') { |
|
| 74 | + $dbType = 'sqlite'; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - return $dbType; |
|
| 78 | - } |
|
| 77 | + return $dbType; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @return string |
|
| 82 | - */ |
|
| 83 | - public function getOS() { |
|
| 84 | - return php_uname('s'); |
|
| 85 | - } |
|
| 80 | + /** |
|
| 81 | + * @return string |
|
| 82 | + */ |
|
| 83 | + public function getOS() { |
|
| 84 | + return php_uname('s'); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @param $command |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - public function isCommandKnown($command) { |
|
| 92 | - $path = \OC_Helper::findBinaryPath($command); |
|
| 93 | - return ($path !== null); |
|
| 94 | - } |
|
| 87 | + /** |
|
| 88 | + * @param $command |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + public function isCommandKnown($command) { |
|
| 92 | + $path = \OC_Helper::findBinaryPath($command); |
|
| 93 | + return ($path !== null); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function getLibraryVersion($name) { |
|
| 97 | - $repo = new PlatformRepository(); |
|
| 98 | - $lib = $repo->findLibrary($name); |
|
| 99 | - return $lib; |
|
| 100 | - } |
|
| 96 | + public function getLibraryVersion($name) { |
|
| 97 | + $repo = new PlatformRepository(); |
|
| 98 | + $lib = $repo->findLibrary($name); |
|
| 99 | + return $lib; |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -22,31 +22,31 @@ |
||
| 22 | 22 | namespace OC\App\AppStore\Version; |
| 23 | 23 | |
| 24 | 24 | class Version { |
| 25 | - /** @var string */ |
|
| 26 | - private $minVersion; |
|
| 27 | - /** @var string */ |
|
| 28 | - private $maxVersion; |
|
| 25 | + /** @var string */ |
|
| 26 | + private $minVersion; |
|
| 27 | + /** @var string */ |
|
| 28 | + private $maxVersion; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @param string $minVersion |
|
| 32 | - * @param string $maxVersion |
|
| 33 | - */ |
|
| 34 | - public function __construct($minVersion, $maxVersion) { |
|
| 35 | - $this->minVersion = $minVersion; |
|
| 36 | - $this->maxVersion = $maxVersion; |
|
| 37 | - } |
|
| 30 | + /** |
|
| 31 | + * @param string $minVersion |
|
| 32 | + * @param string $maxVersion |
|
| 33 | + */ |
|
| 34 | + public function __construct($minVersion, $maxVersion) { |
|
| 35 | + $this->minVersion = $minVersion; |
|
| 36 | + $this->maxVersion = $maxVersion; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function getMinimumVersion() { |
|
| 43 | - return $this->minVersion; |
|
| 44 | - } |
|
| 39 | + /** |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function getMinimumVersion() { |
|
| 43 | + return $this->minVersion; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public function getMaximumVersion() { |
|
| 50 | - return $this->maxVersion; |
|
| 51 | - } |
|
| 46 | + /** |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public function getMaximumVersion() { |
|
| 50 | + return $this->maxVersion; |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -27,57 +27,57 @@ |
||
| 27 | 27 | * @package OC\App\AppStore |
| 28 | 28 | */ |
| 29 | 29 | class VersionParser { |
| 30 | - /** |
|
| 31 | - * @param string $versionString |
|
| 32 | - * @return bool |
|
| 33 | - */ |
|
| 34 | - private function isValidVersionString($versionString) { |
|
| 35 | - return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
| 36 | - } |
|
| 30 | + /** |
|
| 31 | + * @param string $versionString |
|
| 32 | + * @return bool |
|
| 33 | + */ |
|
| 34 | + private function isValidVersionString($versionString) { |
|
| 35 | + return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Returns the version for a version string |
|
| 40 | - * |
|
| 41 | - * @param string $versionSpec |
|
| 42 | - * @return Version |
|
| 43 | - * @throws \Exception If the version cannot be parsed |
|
| 44 | - */ |
|
| 45 | - public function getVersion($versionSpec) { |
|
| 46 | - // * indicates that the version is compatible with all versions |
|
| 47 | - if($versionSpec === '*') { |
|
| 48 | - return new Version('', ''); |
|
| 49 | - } |
|
| 38 | + /** |
|
| 39 | + * Returns the version for a version string |
|
| 40 | + * |
|
| 41 | + * @param string $versionSpec |
|
| 42 | + * @return Version |
|
| 43 | + * @throws \Exception If the version cannot be parsed |
|
| 44 | + */ |
|
| 45 | + public function getVersion($versionSpec) { |
|
| 46 | + // * indicates that the version is compatible with all versions |
|
| 47 | + if($versionSpec === '*') { |
|
| 48 | + return new Version('', ''); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - // Count the amount of =, if it is one then it's either maximum or minimum |
|
| 52 | - // version. If it is two then it is maximum and minimum. |
|
| 53 | - $versionElements = explode(' ', $versionSpec); |
|
| 54 | - $firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; |
|
| 55 | - $firstVersionNumber = substr($firstVersion, 2); |
|
| 56 | - $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
|
| 57 | - $secondVersionNumber = substr($secondVersion, 2); |
|
| 51 | + // Count the amount of =, if it is one then it's either maximum or minimum |
|
| 52 | + // version. If it is two then it is maximum and minimum. |
|
| 53 | + $versionElements = explode(' ', $versionSpec); |
|
| 54 | + $firstVersion = isset($versionElements[0]) ? $versionElements[0] : ''; |
|
| 55 | + $firstVersionNumber = substr($firstVersion, 2); |
|
| 56 | + $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
|
| 57 | + $secondVersionNumber = substr($secondVersion, 2); |
|
| 58 | 58 | |
| 59 | - switch(count($versionElements)) { |
|
| 60 | - case 1: |
|
| 61 | - if(!$this->isValidVersionString($firstVersionNumber)) { |
|
| 62 | - break; |
|
| 63 | - } |
|
| 64 | - if(substr($firstVersion, 0, 1) === '>') { |
|
| 65 | - return new Version($firstVersionNumber, ''); |
|
| 66 | - } else { |
|
| 67 | - return new Version('', $firstVersionNumber); |
|
| 68 | - } |
|
| 69 | - case 2: |
|
| 70 | - if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
| 71 | - break; |
|
| 72 | - } |
|
| 73 | - return new Version($firstVersionNumber, $secondVersionNumber); |
|
| 74 | - } |
|
| 59 | + switch(count($versionElements)) { |
|
| 60 | + case 1: |
|
| 61 | + if(!$this->isValidVersionString($firstVersionNumber)) { |
|
| 62 | + break; |
|
| 63 | + } |
|
| 64 | + if(substr($firstVersion, 0, 1) === '>') { |
|
| 65 | + return new Version($firstVersionNumber, ''); |
|
| 66 | + } else { |
|
| 67 | + return new Version('', $firstVersionNumber); |
|
| 68 | + } |
|
| 69 | + case 2: |
|
| 70 | + if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
| 71 | + break; |
|
| 72 | + } |
|
| 73 | + return new Version($firstVersionNumber, $secondVersionNumber); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - throw new \Exception( |
|
| 77 | - sprintf( |
|
| 78 | - 'Version cannot be parsed: %s', |
|
| 79 | - $versionSpec |
|
| 80 | - ) |
|
| 81 | - ); |
|
| 82 | - } |
|
| 76 | + throw new \Exception( |
|
| 77 | + sprintf( |
|
| 78 | + 'Version cannot be parsed: %s', |
|
| 79 | + $versionSpec |
|
| 80 | + ) |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @return bool |
| 33 | 33 | */ |
| 34 | 34 | private function isValidVersionString($versionString) { |
| 35 | - return (bool)preg_match('/^[0-9.]+$/', $versionString); |
|
| 35 | + return (bool) preg_match('/^[0-9.]+$/', $versionString); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function getVersion($versionSpec) { |
| 46 | 46 | // * indicates that the version is compatible with all versions |
| 47 | - if($versionSpec === '*') { |
|
| 47 | + if ($versionSpec === '*') { |
|
| 48 | 48 | return new Version('', ''); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,18 +56,18 @@ discard block |
||
| 56 | 56 | $secondVersion = isset($versionElements[1]) ? $versionElements[1] : ''; |
| 57 | 57 | $secondVersionNumber = substr($secondVersion, 2); |
| 58 | 58 | |
| 59 | - switch(count($versionElements)) { |
|
| 59 | + switch (count($versionElements)) { |
|
| 60 | 60 | case 1: |
| 61 | - if(!$this->isValidVersionString($firstVersionNumber)) { |
|
| 61 | + if (!$this->isValidVersionString($firstVersionNumber)) { |
|
| 62 | 62 | break; |
| 63 | 63 | } |
| 64 | - if(substr($firstVersion, 0, 1) === '>') { |
|
| 64 | + if (substr($firstVersion, 0, 1) === '>') { |
|
| 65 | 65 | return new Version($firstVersionNumber, ''); |
| 66 | 66 | } else { |
| 67 | 67 | return new Version('', $firstVersionNumber); |
| 68 | 68 | } |
| 69 | 69 | case 2: |
| 70 | - if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
| 70 | + if (!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) { |
|
| 71 | 71 | break; |
| 72 | 72 | } |
| 73 | 73 | return new Version($firstVersionNumber, $secondVersionNumber); |