@@ -33,53 +33,53 @@ |
||
33 | 33 | namespace OC\Files\Storage; |
34 | 34 | |
35 | 35 | class CommonTest extends \OC\Files\Storage\Common { |
36 | - /** |
|
37 | - * underlying local storage used for missing functions |
|
38 | - * @var \OC\Files\Storage\Local |
|
39 | - */ |
|
40 | - private $storage; |
|
36 | + /** |
|
37 | + * underlying local storage used for missing functions |
|
38 | + * @var \OC\Files\Storage\Local |
|
39 | + */ |
|
40 | + private $storage; |
|
41 | 41 | |
42 | - public function __construct($params) { |
|
43 | - $this->storage = new \OC\Files\Storage\Local($params); |
|
44 | - } |
|
42 | + public function __construct($params) { |
|
43 | + $this->storage = new \OC\Files\Storage\Local($params); |
|
44 | + } |
|
45 | 45 | |
46 | - public function getId() { |
|
47 | - return 'test::'.$this->storage->getId(); |
|
48 | - } |
|
49 | - public function mkdir($path) { |
|
50 | - return $this->storage->mkdir($path); |
|
51 | - } |
|
52 | - public function rmdir($path) { |
|
53 | - return $this->storage->rmdir($path); |
|
54 | - } |
|
55 | - public function opendir($path) { |
|
56 | - return $this->storage->opendir($path); |
|
57 | - } |
|
58 | - public function stat($path) { |
|
59 | - return $this->storage->stat($path); |
|
60 | - } |
|
61 | - public function filetype($path) { |
|
62 | - return @$this->storage->filetype($path); |
|
63 | - } |
|
64 | - public function isReadable($path) { |
|
65 | - return $this->storage->isReadable($path); |
|
66 | - } |
|
67 | - public function isUpdatable($path) { |
|
68 | - return $this->storage->isUpdatable($path); |
|
69 | - } |
|
70 | - public function file_exists($path) { |
|
71 | - return $this->storage->file_exists($path); |
|
72 | - } |
|
73 | - public function unlink($path) { |
|
74 | - return $this->storage->unlink($path); |
|
75 | - } |
|
76 | - public function fopen($path, $mode) { |
|
77 | - return $this->storage->fopen($path, $mode); |
|
78 | - } |
|
79 | - public function free_space($path) { |
|
80 | - return $this->storage->free_space($path); |
|
81 | - } |
|
82 | - public function touch($path, $mtime = null) { |
|
83 | - return $this->storage->touch($path, $mtime); |
|
84 | - } |
|
46 | + public function getId() { |
|
47 | + return 'test::'.$this->storage->getId(); |
|
48 | + } |
|
49 | + public function mkdir($path) { |
|
50 | + return $this->storage->mkdir($path); |
|
51 | + } |
|
52 | + public function rmdir($path) { |
|
53 | + return $this->storage->rmdir($path); |
|
54 | + } |
|
55 | + public function opendir($path) { |
|
56 | + return $this->storage->opendir($path); |
|
57 | + } |
|
58 | + public function stat($path) { |
|
59 | + return $this->storage->stat($path); |
|
60 | + } |
|
61 | + public function filetype($path) { |
|
62 | + return @$this->storage->filetype($path); |
|
63 | + } |
|
64 | + public function isReadable($path) { |
|
65 | + return $this->storage->isReadable($path); |
|
66 | + } |
|
67 | + public function isUpdatable($path) { |
|
68 | + return $this->storage->isUpdatable($path); |
|
69 | + } |
|
70 | + public function file_exists($path) { |
|
71 | + return $this->storage->file_exists($path); |
|
72 | + } |
|
73 | + public function unlink($path) { |
|
74 | + return $this->storage->unlink($path); |
|
75 | + } |
|
76 | + public function fopen($path, $mode) { |
|
77 | + return $this->storage->fopen($path, $mode); |
|
78 | + } |
|
79 | + public function free_space($path) { |
|
80 | + return $this->storage->free_space($path); |
|
81 | + } |
|
82 | + public function touch($path, $mtime = null) { |
|
83 | + return $this->storage->touch($path, $mtime); |
|
84 | + } |
|
85 | 85 | } |
@@ -29,20 +29,20 @@ |
||
29 | 29 | * local storage backend in temporary folder for testing purpose |
30 | 30 | */ |
31 | 31 | class Temporary extends Local { |
32 | - public function __construct($arguments = null) { |
|
33 | - parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); |
|
34 | - } |
|
32 | + public function __construct($arguments = null) { |
|
33 | + parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); |
|
34 | + } |
|
35 | 35 | |
36 | - public function cleanUp() { |
|
37 | - \OC_Helper::rmdirr($this->datadir); |
|
38 | - } |
|
36 | + public function cleanUp() { |
|
37 | + \OC_Helper::rmdirr($this->datadir); |
|
38 | + } |
|
39 | 39 | |
40 | - public function __destruct() { |
|
41 | - parent::__destruct(); |
|
42 | - $this->cleanUp(); |
|
43 | - } |
|
40 | + public function __destruct() { |
|
41 | + parent::__destruct(); |
|
42 | + $this->cleanUp(); |
|
43 | + } |
|
44 | 44 | |
45 | - public function getDataDir() { |
|
46 | - return $this->datadir; |
|
47 | - } |
|
45 | + public function getDataDir() { |
|
46 | + return $this->datadir; |
|
47 | + } |
|
48 | 48 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | public function __construct($arguments) { |
51 | 51 | $this->user = $arguments['user']; |
52 | 52 | $datadir = $this->user->getHome(); |
53 | - $this->id = 'home::' . $this->user->getUID(); |
|
53 | + $this->id = 'home::'.$this->user->getUID(); |
|
54 | 54 | |
55 | 55 | parent::__construct(['datadir' => $datadir]); |
56 | 56 | } |
@@ -33,80 +33,80 @@ |
||
33 | 33 | * Specialized version of Local storage for home directory usage |
34 | 34 | */ |
35 | 35 | class Home extends Local implements \OCP\Files\IHomeStorage { |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $id; |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $id; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var \OC\User\User $user |
|
43 | - */ |
|
44 | - protected $user; |
|
41 | + /** |
|
42 | + * @var \OC\User\User $user |
|
43 | + */ |
|
44 | + protected $user; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Construct a Home storage instance |
|
48 | - * |
|
49 | - * @param array $arguments array with "user" containing the |
|
50 | - * storage owner |
|
51 | - */ |
|
52 | - public function __construct($arguments) { |
|
53 | - $this->user = $arguments['user']; |
|
54 | - $datadir = $this->user->getHome(); |
|
55 | - $this->id = 'home::' . $this->user->getUID(); |
|
46 | + /** |
|
47 | + * Construct a Home storage instance |
|
48 | + * |
|
49 | + * @param array $arguments array with "user" containing the |
|
50 | + * storage owner |
|
51 | + */ |
|
52 | + public function __construct($arguments) { |
|
53 | + $this->user = $arguments['user']; |
|
54 | + $datadir = $this->user->getHome(); |
|
55 | + $this->id = 'home::' . $this->user->getUID(); |
|
56 | 56 | |
57 | - parent::__construct(['datadir' => $datadir]); |
|
58 | - } |
|
57 | + parent::__construct(['datadir' => $datadir]); |
|
58 | + } |
|
59 | 59 | |
60 | - public function getId() { |
|
61 | - return $this->id; |
|
62 | - } |
|
60 | + public function getId() { |
|
61 | + return $this->id; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return \OC\Files\Cache\HomeCache |
|
66 | - */ |
|
67 | - public function getCache($path = '', $storage = null) { |
|
68 | - if (!$storage) { |
|
69 | - $storage = $this; |
|
70 | - } |
|
71 | - if (!isset($this->cache)) { |
|
72 | - $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
73 | - } |
|
74 | - return $this->cache; |
|
75 | - } |
|
64 | + /** |
|
65 | + * @return \OC\Files\Cache\HomeCache |
|
66 | + */ |
|
67 | + public function getCache($path = '', $storage = null) { |
|
68 | + if (!$storage) { |
|
69 | + $storage = $this; |
|
70 | + } |
|
71 | + if (!isset($this->cache)) { |
|
72 | + $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
73 | + } |
|
74 | + return $this->cache; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * get a propagator instance for the cache |
|
79 | - * |
|
80 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
81 | - * @return \OC\Files\Cache\Propagator |
|
82 | - */ |
|
83 | - public function getPropagator($storage = null) { |
|
84 | - if (!$storage) { |
|
85 | - $storage = $this; |
|
86 | - } |
|
87 | - if (!isset($this->propagator)) { |
|
88 | - $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
89 | - } |
|
90 | - return $this->propagator; |
|
91 | - } |
|
77 | + /** |
|
78 | + * get a propagator instance for the cache |
|
79 | + * |
|
80 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
81 | + * @return \OC\Files\Cache\Propagator |
|
82 | + */ |
|
83 | + public function getPropagator($storage = null) { |
|
84 | + if (!$storage) { |
|
85 | + $storage = $this; |
|
86 | + } |
|
87 | + if (!isset($this->propagator)) { |
|
88 | + $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
89 | + } |
|
90 | + return $this->propagator; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * Returns the owner of this home storage |
|
96 | - * |
|
97 | - * @return \OC\User\User owner of this home storage |
|
98 | - */ |
|
99 | - public function getUser() { |
|
100 | - return $this->user; |
|
101 | - } |
|
94 | + /** |
|
95 | + * Returns the owner of this home storage |
|
96 | + * |
|
97 | + * @return \OC\User\User owner of this home storage |
|
98 | + */ |
|
99 | + public function getUser() { |
|
100 | + return $this->user; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * get the owner of a path |
|
105 | - * |
|
106 | - * @param string $path The path to get the owner |
|
107 | - * @return string uid or false |
|
108 | - */ |
|
109 | - public function getOwner($path) { |
|
110 | - return $this->user->getUID(); |
|
111 | - } |
|
103 | + /** |
|
104 | + * get the owner of a path |
|
105 | + * |
|
106 | + * @param string $path The path to get the owner |
|
107 | + * @return string uid or false |
|
108 | + */ |
|
109 | + public function getOwner($path) { |
|
110 | + return $this->user->getUID(); |
|
111 | + } |
|
112 | 112 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param array $params |
34 | 34 | */ |
35 | 35 | public function __construct($params) { |
36 | - if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
36 | + if (!isset($params['user']) || !$params['user'] instanceof User) { |
|
37 | 37 | throw new \Exception('missing user object in parameters'); |
38 | 38 | } |
39 | 39 | $this->user = $params['user']; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | } |
42 | 42 | |
43 | 43 | public function getId() { |
44 | - return 'object::user:' . $this->user->getUID(); |
|
44 | + return 'object::user:'.$this->user->getUID(); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -28,40 +28,40 @@ |
||
28 | 28 | use OC\User\User; |
29 | 29 | |
30 | 30 | class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage { |
31 | - /** |
|
32 | - * The home user storage requires a user object to create a unique storage id |
|
33 | - * @param array $params |
|
34 | - */ |
|
35 | - public function __construct($params) { |
|
36 | - if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
37 | - throw new \Exception('missing user object in parameters'); |
|
38 | - } |
|
39 | - $this->user = $params['user']; |
|
40 | - parent::__construct($params); |
|
41 | - } |
|
31 | + /** |
|
32 | + * The home user storage requires a user object to create a unique storage id |
|
33 | + * @param array $params |
|
34 | + */ |
|
35 | + public function __construct($params) { |
|
36 | + if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
37 | + throw new \Exception('missing user object in parameters'); |
|
38 | + } |
|
39 | + $this->user = $params['user']; |
|
40 | + parent::__construct($params); |
|
41 | + } |
|
42 | 42 | |
43 | - public function getId() { |
|
44 | - return 'object::user:' . $this->user->getUID(); |
|
45 | - } |
|
43 | + public function getId() { |
|
44 | + return 'object::user:' . $this->user->getUID(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * get the owner of a path |
|
49 | - * |
|
50 | - * @param string $path The path to get the owner |
|
51 | - * @return false|string uid |
|
52 | - */ |
|
53 | - public function getOwner($path) { |
|
54 | - if (is_object($this->user)) { |
|
55 | - return $this->user->getUID(); |
|
56 | - } |
|
57 | - return false; |
|
58 | - } |
|
47 | + /** |
|
48 | + * get the owner of a path |
|
49 | + * |
|
50 | + * @param string $path The path to get the owner |
|
51 | + * @return false|string uid |
|
52 | + */ |
|
53 | + public function getOwner($path) { |
|
54 | + if (is_object($this->user)) { |
|
55 | + return $this->user->getUID(); |
|
56 | + } |
|
57 | + return false; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @param string $path, optional |
|
62 | - * @return \OC\User\User |
|
63 | - */ |
|
64 | - public function getUser($path = null) { |
|
65 | - return $this->user; |
|
66 | - } |
|
60 | + /** |
|
61 | + * @param string $path, optional |
|
62 | + * @return \OC\User\User |
|
63 | + */ |
|
64 | + public function getUser($path = null) { |
|
65 | + return $this->user; |
|
66 | + } |
|
67 | 67 | } |
@@ -24,17 +24,17 @@ |
||
24 | 24 | namespace OC\DB; |
25 | 25 | |
26 | 26 | class MigrationException extends \Exception { |
27 | - private $table; |
|
27 | + private $table; |
|
28 | 28 | |
29 | - public function __construct($table, $message) { |
|
30 | - $this->table = $table; |
|
31 | - parent::__construct($message); |
|
32 | - } |
|
29 | + public function __construct($table, $message) { |
|
30 | + $this->table = $table; |
|
31 | + parent::__construct($message); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function getTable() { |
|
38 | - return $this->table; |
|
39 | - } |
|
34 | + /** |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function getTable() { |
|
38 | + return $this->table; |
|
39 | + } |
|
40 | 40 | } |
@@ -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 | } |
@@ -64,14 +64,14 @@ |
||
64 | 64 | if (empty($compare)) { |
65 | 65 | $compare = array_keys($input); |
66 | 66 | } |
67 | - $fieldList = '`' . implode('`,`', array_keys($input)) . '`'; |
|
67 | + $fieldList = '`'.implode('`,`', array_keys($input)).'`'; |
|
68 | 68 | $query = "INSERT INTO `$table` ($fieldList) SELECT " |
69 | 69 | . str_repeat('?,', count($input) - 1).'? ' |
70 | 70 | . " WHERE NOT EXISTS (SELECT 1 FROM `$table` WHERE "; |
71 | 71 | |
72 | 72 | $inserts = array_values($input); |
73 | 73 | foreach ($compare as $key) { |
74 | - $query .= '`' . $key . '`'; |
|
74 | + $query .= '`'.$key.'`'; |
|
75 | 75 | if (is_null($input[$key])) { |
76 | 76 | $query .= ' IS NULL AND '; |
77 | 77 | } else { |
@@ -29,70 +29,70 @@ |
||
29 | 29 | use Doctrine\DBAL\Exception\UniqueConstraintViolationException; |
30 | 30 | |
31 | 31 | class AdapterSqlite extends Adapter { |
32 | - /** |
|
33 | - * @param string $tableName |
|
34 | - */ |
|
35 | - public function lockTable($tableName) { |
|
36 | - $this->conn->executeUpdate('BEGIN EXCLUSIVE TRANSACTION'); |
|
37 | - } |
|
32 | + /** |
|
33 | + * @param string $tableName |
|
34 | + */ |
|
35 | + public function lockTable($tableName) { |
|
36 | + $this->conn->executeUpdate('BEGIN EXCLUSIVE TRANSACTION'); |
|
37 | + } |
|
38 | 38 | |
39 | - public function unlockTable() { |
|
40 | - $this->conn->executeUpdate('COMMIT TRANSACTION'); |
|
41 | - } |
|
39 | + public function unlockTable() { |
|
40 | + $this->conn->executeUpdate('COMMIT TRANSACTION'); |
|
41 | + } |
|
42 | 42 | |
43 | - public function fixupStatement($statement) { |
|
44 | - $statement = preg_replace('/`(\w+)` ILIKE \?/', 'LOWER($1) LIKE LOWER(?)', $statement); |
|
45 | - $statement = str_replace('`', '"', $statement); |
|
46 | - $statement = str_ireplace('NOW()', 'datetime(\'now\')', $statement); |
|
47 | - $statement = str_ireplace('GREATEST(', 'MAX(', $statement); |
|
48 | - $statement = str_ireplace('UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $statement); |
|
49 | - return $statement; |
|
50 | - } |
|
43 | + public function fixupStatement($statement) { |
|
44 | + $statement = preg_replace('/`(\w+)` ILIKE \?/', 'LOWER($1) LIKE LOWER(?)', $statement); |
|
45 | + $statement = str_replace('`', '"', $statement); |
|
46 | + $statement = str_ireplace('NOW()', 'datetime(\'now\')', $statement); |
|
47 | + $statement = str_ireplace('GREATEST(', 'MAX(', $statement); |
|
48 | + $statement = str_ireplace('UNIX_TIMESTAMP()', 'strftime(\'%s\',\'now\')', $statement); |
|
49 | + return $statement; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
54 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
55 | - * catch the exception and return 0. |
|
56 | - * |
|
57 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
58 | - * @param array $input data that should be inserted into the table (column name => value) |
|
59 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
60 | - * If this is null or an empty array, all keys of $input will be compared |
|
61 | - * Please note: text fields (clob) must not be used in the compare array |
|
62 | - * @return int number of inserted rows |
|
63 | - * @throws \Doctrine\DBAL\Exception |
|
64 | - * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
65 | - */ |
|
66 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
67 | - if (empty($compare)) { |
|
68 | - $compare = array_keys($input); |
|
69 | - } |
|
70 | - $fieldList = '`' . implode('`,`', array_keys($input)) . '`'; |
|
71 | - $query = "INSERT INTO `$table` ($fieldList) SELECT " |
|
72 | - . str_repeat('?,', count($input) - 1).'? ' |
|
73 | - . " WHERE NOT EXISTS (SELECT 1 FROM `$table` WHERE "; |
|
52 | + /** |
|
53 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
54 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
55 | + * catch the exception and return 0. |
|
56 | + * |
|
57 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
58 | + * @param array $input data that should be inserted into the table (column name => value) |
|
59 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
60 | + * If this is null or an empty array, all keys of $input will be compared |
|
61 | + * Please note: text fields (clob) must not be used in the compare array |
|
62 | + * @return int number of inserted rows |
|
63 | + * @throws \Doctrine\DBAL\Exception |
|
64 | + * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
65 | + */ |
|
66 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
67 | + if (empty($compare)) { |
|
68 | + $compare = array_keys($input); |
|
69 | + } |
|
70 | + $fieldList = '`' . implode('`,`', array_keys($input)) . '`'; |
|
71 | + $query = "INSERT INTO `$table` ($fieldList) SELECT " |
|
72 | + . str_repeat('?,', count($input) - 1).'? ' |
|
73 | + . " WHERE NOT EXISTS (SELECT 1 FROM `$table` WHERE "; |
|
74 | 74 | |
75 | - $inserts = array_values($input); |
|
76 | - foreach ($compare as $key) { |
|
77 | - $query .= '`' . $key . '`'; |
|
78 | - if (is_null($input[$key])) { |
|
79 | - $query .= ' IS NULL AND '; |
|
80 | - } else { |
|
81 | - $inserts[] = $input[$key]; |
|
82 | - $query .= ' = ? AND '; |
|
83 | - } |
|
84 | - } |
|
85 | - $query = substr($query, 0, -5); |
|
86 | - $query .= ')'; |
|
75 | + $inserts = array_values($input); |
|
76 | + foreach ($compare as $key) { |
|
77 | + $query .= '`' . $key . '`'; |
|
78 | + if (is_null($input[$key])) { |
|
79 | + $query .= ' IS NULL AND '; |
|
80 | + } else { |
|
81 | + $inserts[] = $input[$key]; |
|
82 | + $query .= ' = ? AND '; |
|
83 | + } |
|
84 | + } |
|
85 | + $query = substr($query, 0, -5); |
|
86 | + $query .= ')'; |
|
87 | 87 | |
88 | - try { |
|
89 | - return $this->conn->executeUpdate($query, $inserts); |
|
90 | - } catch (UniqueConstraintViolationException $e) { |
|
91 | - // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
92 | - // it's fine to ignore this then |
|
93 | - // |
|
94 | - // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
95 | - return 0; |
|
96 | - } |
|
97 | - } |
|
88 | + try { |
|
89 | + return $this->conn->executeUpdate($query, $inserts); |
|
90 | + } catch (UniqueConstraintViolationException $e) { |
|
91 | + // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
92 | + // it's fine to ignore this then |
|
93 | + // |
|
94 | + // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
95 | + return 0; |
|
96 | + } |
|
97 | + } |
|
98 | 98 | } |
@@ -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 ' |
|
96 | + $query = 'INSERT INTO `'.$table.'` (`' |
|
97 | + . implode('`,`', array_keys($input)).'`) SELECT ' |
|
98 | 98 | . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
99 | - . 'FROM `' . $table . '` WHERE '; |
|
99 | + . 'FROM `'.$table.'` WHERE '; |
|
100 | 100 | |
101 | 101 | $inserts = array_values($input); |
102 | 102 | foreach ($compare as $key) { |
103 | - $query .= '`' . $key . '`'; |
|
103 | + $query .= '`'.$key.'`'; |
|
104 | 104 | if (is_null($input[$key])) { |
105 | 105 | $query .= ' IS NULL AND '; |
106 | 106 | } else { |
@@ -36,115 +36,115 @@ |
||
36 | 36 | * handled by the database abstraction layer. |
37 | 37 | */ |
38 | 38 | class Adapter { |
39 | - /** |
|
40 | - * @var \OC\DB\Connection $conn |
|
41 | - */ |
|
42 | - protected $conn; |
|
39 | + /** |
|
40 | + * @var \OC\DB\Connection $conn |
|
41 | + */ |
|
42 | + protected $conn; |
|
43 | 43 | |
44 | - public function __construct($conn) { |
|
45 | - $this->conn = $conn; |
|
46 | - } |
|
44 | + public function __construct($conn) { |
|
45 | + $this->conn = $conn; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $table name |
|
50 | - * |
|
51 | - * @return int id of last insert statement |
|
52 | - * @throws Exception |
|
53 | - */ |
|
54 | - public function lastInsertId($table) { |
|
55 | - return (int) $this->conn->realLastInsertId($table); |
|
56 | - } |
|
48 | + /** |
|
49 | + * @param string $table name |
|
50 | + * |
|
51 | + * @return int id of last insert statement |
|
52 | + * @throws Exception |
|
53 | + */ |
|
54 | + public function lastInsertId($table) { |
|
55 | + return (int) $this->conn->realLastInsertId($table); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param string $statement that needs to be changed so the db can handle it |
|
60 | - * @return string changed statement |
|
61 | - */ |
|
62 | - public function fixupStatement($statement) { |
|
63 | - return $statement; |
|
64 | - } |
|
58 | + /** |
|
59 | + * @param string $statement that needs to be changed so the db can handle it |
|
60 | + * @return string changed statement |
|
61 | + */ |
|
62 | + public function fixupStatement($statement) { |
|
63 | + return $statement; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Create an exclusive read+write lock on a table |
|
68 | - * |
|
69 | - * @param string $tableName |
|
70 | - * @throws Exception |
|
71 | - * @since 9.1.0 |
|
72 | - */ |
|
73 | - public function lockTable($tableName) { |
|
74 | - $this->conn->beginTransaction(); |
|
75 | - $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
76 | - } |
|
66 | + /** |
|
67 | + * Create an exclusive read+write lock on a table |
|
68 | + * |
|
69 | + * @param string $tableName |
|
70 | + * @throws Exception |
|
71 | + * @since 9.1.0 |
|
72 | + */ |
|
73 | + public function lockTable($tableName) { |
|
74 | + $this->conn->beginTransaction(); |
|
75 | + $this->conn->executeUpdate('LOCK TABLE `' .$tableName . '` IN EXCLUSIVE MODE'); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Release a previous acquired lock again |
|
80 | - * |
|
81 | - * @throws Exception |
|
82 | - * @since 9.1.0 |
|
83 | - */ |
|
84 | - public function unlockTable() { |
|
85 | - $this->conn->commit(); |
|
86 | - } |
|
78 | + /** |
|
79 | + * Release a previous acquired lock again |
|
80 | + * |
|
81 | + * @throws Exception |
|
82 | + * @since 9.1.0 |
|
83 | + */ |
|
84 | + public function unlockTable() { |
|
85 | + $this->conn->commit(); |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
90 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
91 | - * catch the exception and return 0. |
|
92 | - * |
|
93 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
94 | - * @param array $input data that should be inserted into the table (column name => value) |
|
95 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
96 | - * If this is null or an empty array, all keys of $input will be compared |
|
97 | - * Please note: text fields (clob) must not be used in the compare array |
|
98 | - * @return int number of inserted rows |
|
99 | - * @throws Exception |
|
100 | - * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
101 | - */ |
|
102 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
103 | - if (empty($compare)) { |
|
104 | - $compare = array_keys($input); |
|
105 | - } |
|
106 | - $query = 'INSERT INTO `' .$table . '` (`' |
|
107 | - . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
108 | - . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
|
109 | - . 'FROM `' . $table . '` WHERE '; |
|
88 | + /** |
|
89 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
90 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
91 | + * catch the exception and return 0. |
|
92 | + * |
|
93 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
94 | + * @param array $input data that should be inserted into the table (column name => value) |
|
95 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
96 | + * If this is null or an empty array, all keys of $input will be compared |
|
97 | + * Please note: text fields (clob) must not be used in the compare array |
|
98 | + * @return int number of inserted rows |
|
99 | + * @throws Exception |
|
100 | + * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
101 | + */ |
|
102 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
103 | + if (empty($compare)) { |
|
104 | + $compare = array_keys($input); |
|
105 | + } |
|
106 | + $query = 'INSERT INTO `' .$table . '` (`' |
|
107 | + . implode('`,`', array_keys($input)) . '`) SELECT ' |
|
108 | + . str_repeat('?,', count($input) - 1).'? ' // Is there a prettier alternative? |
|
109 | + . 'FROM `' . $table . '` WHERE '; |
|
110 | 110 | |
111 | - $inserts = array_values($input); |
|
112 | - foreach ($compare as $key) { |
|
113 | - $query .= '`' . $key . '`'; |
|
114 | - if (is_null($input[$key])) { |
|
115 | - $query .= ' IS NULL AND '; |
|
116 | - } else { |
|
117 | - $inserts[] = $input[$key]; |
|
118 | - $query .= ' = ? AND '; |
|
119 | - } |
|
120 | - } |
|
121 | - $query = substr($query, 0, -5); |
|
122 | - $query .= ' HAVING COUNT(*) = 0'; |
|
111 | + $inserts = array_values($input); |
|
112 | + foreach ($compare as $key) { |
|
113 | + $query .= '`' . $key . '`'; |
|
114 | + if (is_null($input[$key])) { |
|
115 | + $query .= ' IS NULL AND '; |
|
116 | + } else { |
|
117 | + $inserts[] = $input[$key]; |
|
118 | + $query .= ' = ? AND '; |
|
119 | + } |
|
120 | + } |
|
121 | + $query = substr($query, 0, -5); |
|
122 | + $query .= ' HAVING COUNT(*) = 0'; |
|
123 | 123 | |
124 | - try { |
|
125 | - return $this->conn->executeUpdate($query, $inserts); |
|
126 | - } catch (UniqueConstraintViolationException $e) { |
|
127 | - // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
128 | - // it's fine to ignore this then |
|
129 | - // |
|
130 | - // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
131 | - return 0; |
|
132 | - } |
|
133 | - } |
|
124 | + try { |
|
125 | + return $this->conn->executeUpdate($query, $inserts); |
|
126 | + } catch (UniqueConstraintViolationException $e) { |
|
127 | + // if this is thrown then a concurrent insert happened between the insert and the sub-select in the insert, that should have avoided it |
|
128 | + // it's fine to ignore this then |
|
129 | + // |
|
130 | + // more discussions about this can be found at https://github.com/nextcloud/server/pull/12315 |
|
131 | + return 0; |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * @throws \OCP\DB\Exception |
|
137 | - */ |
|
138 | - public function insertIgnoreConflict(string $table, array $values) : int { |
|
139 | - try { |
|
140 | - $builder = $this->conn->getQueryBuilder(); |
|
141 | - $builder->insert($table); |
|
142 | - foreach ($values as $key => $value) { |
|
143 | - $builder->setValue($key, $builder->createNamedParameter($value)); |
|
144 | - } |
|
145 | - return $builder->execute(); |
|
146 | - } catch (UniqueConstraintViolationException $e) { |
|
147 | - return 0; |
|
148 | - } |
|
149 | - } |
|
135 | + /** |
|
136 | + * @throws \OCP\DB\Exception |
|
137 | + */ |
|
138 | + public function insertIgnoreConflict(string $table, array $values) : int { |
|
139 | + try { |
|
140 | + $builder = $this->conn->getQueryBuilder(); |
|
141 | + $builder->insert($table); |
|
142 | + foreach ($values as $key => $value) { |
|
143 | + $builder->setValue($key, $builder->createNamedParameter($value)); |
|
144 | + } |
|
145 | + return $builder->execute(); |
|
146 | + } catch (UniqueConstraintViolationException $e) { |
|
147 | + return 0; |
|
148 | + } |
|
149 | + } |
|
150 | 150 | } |
@@ -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($table, array $data, array $types = []) { |
|
51 | - if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
52 | - $table = $this->quoteIdentifier($table); |
|
53 | - } |
|
54 | - $data = $this->quoteKeys($data); |
|
55 | - return parent::insert($table, $data, $types); |
|
56 | - } |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + */ |
|
50 | + public function insert($table, array $data, array $types = []) { |
|
51 | + if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
52 | + $table = $this->quoteIdentifier($table); |
|
53 | + } |
|
54 | + $data = $this->quoteKeys($data); |
|
55 | + return parent::insert($table, $data, $types); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - */ |
|
61 | - public function update($table, array $data, array $criteria, array $types = []) { |
|
62 | - if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
63 | - $table = $this->quoteIdentifier($table); |
|
64 | - } |
|
65 | - $data = $this->quoteKeys($data); |
|
66 | - $criteria = $this->quoteKeys($criteria); |
|
67 | - return parent::update($table, $data, $criteria, $types); |
|
68 | - } |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + */ |
|
61 | + public function update($table, array $data, array $criteria, array $types = []) { |
|
62 | + if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
63 | + $table = $this->quoteIdentifier($table); |
|
64 | + } |
|
65 | + $data = $this->quoteKeys($data); |
|
66 | + $criteria = $this->quoteKeys($criteria); |
|
67 | + return parent::update($table, $data, $criteria, $types); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * {@inheritDoc} |
|
72 | - */ |
|
73 | - public function delete($table, array $criteria, array $types = []) { |
|
74 | - if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
75 | - $table = $this->quoteIdentifier($table); |
|
76 | - } |
|
77 | - $criteria = $this->quoteKeys($criteria); |
|
78 | - return parent::delete($table, $criteria); |
|
79 | - } |
|
70 | + /** |
|
71 | + * {@inheritDoc} |
|
72 | + */ |
|
73 | + public function delete($table, array $criteria, array $types = []) { |
|
74 | + if ($table[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
75 | + $table = $this->quoteIdentifier($table); |
|
76 | + } |
|
77 | + $criteria = $this->quoteKeys($criteria); |
|
78 | + return parent::delete($table, $criteria); |
|
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 | } |