@@ -23,20 +23,20 @@ |
||
23 | 23 | |
24 | 24 | class CoreBundle extends Bundle { |
25 | 25 | |
26 | - /** |
|
27 | - * {@inheritDoc} |
|
28 | - */ |
|
29 | - public function getName() { |
|
30 | - return 'Core bundle'; |
|
31 | - } |
|
26 | + /** |
|
27 | + * {@inheritDoc} |
|
28 | + */ |
|
29 | + public function getName() { |
|
30 | + return 'Core bundle'; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritDoc} |
|
35 | - */ |
|
36 | - public function getAppIdentifiers() { |
|
37 | - return [ |
|
38 | - 'bruteforcesettings', |
|
39 | - ]; |
|
40 | - } |
|
33 | + /** |
|
34 | + * {@inheritDoc} |
|
35 | + */ |
|
36 | + public function getAppIdentifiers() { |
|
37 | + return [ |
|
38 | + 'bruteforcesettings', |
|
39 | + ]; |
|
40 | + } |
|
41 | 41 | |
42 | 42 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | * {@inheritDoc} |
28 | 28 | */ |
29 | 29 | public function getName() { |
30 | - return (string)$this->l10n->t('Groupware bundle'); |
|
30 | + return (string) $this->l10n->t('Groupware bundle'); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -25,23 +25,23 @@ |
||
25 | 25 | |
26 | 26 | class GroupwareBundle extends Bundle { |
27 | 27 | |
28 | - /** |
|
29 | - * {@inheritDoc} |
|
30 | - */ |
|
31 | - public function getName() { |
|
32 | - return (string)$this->l10n->t('Groupware bundle'); |
|
33 | - } |
|
28 | + /** |
|
29 | + * {@inheritDoc} |
|
30 | + */ |
|
31 | + public function getName() { |
|
32 | + return (string)$this->l10n->t('Groupware bundle'); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritDoc} |
|
37 | - */ |
|
38 | - public function getAppIdentifiers() { |
|
39 | - return [ |
|
40 | - 'calendar', |
|
41 | - 'contacts', |
|
42 | - 'deck', |
|
43 | - 'mail' |
|
44 | - ]; |
|
45 | - } |
|
35 | + /** |
|
36 | + * {@inheritDoc} |
|
37 | + */ |
|
38 | + public function getAppIdentifiers() { |
|
39 | + return [ |
|
40 | + 'calendar', |
|
41 | + 'contacts', |
|
42 | + 'deck', |
|
43 | + 'mail' |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
@@ -24,36 +24,36 @@ |
||
24 | 24 | use OCP\IL10N; |
25 | 25 | |
26 | 26 | abstract class Bundle { |
27 | - /** @var IL10N */ |
|
28 | - protected $l10n; |
|
27 | + /** @var IL10N */ |
|
28 | + protected $l10n; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param IL10N $l10n |
|
32 | - */ |
|
33 | - public function __construct(IL10N $l10n) { |
|
34 | - $this->l10n = $l10n; |
|
35 | - } |
|
30 | + /** |
|
31 | + * @param IL10N $l10n |
|
32 | + */ |
|
33 | + public function __construct(IL10N $l10n) { |
|
34 | + $this->l10n = $l10n; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Get the identifier of the bundle |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public final function getIdentifier() { |
|
43 | - return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | - } |
|
37 | + /** |
|
38 | + * Get the identifier of the bundle |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public final function getIdentifier() { |
|
43 | + return substr(strrchr(get_class($this), '\\'), 1); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the name of the bundle |
|
48 | - * |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public abstract function getName(); |
|
46 | + /** |
|
47 | + * Get the name of the bundle |
|
48 | + * |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public abstract function getName(); |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get the list of app identifiers in the bundle |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public abstract function getAppIdentifiers(); |
|
53 | + /** |
|
54 | + * Get the list of app identifiers in the bundle |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public abstract function getAppIdentifiers(); |
|
59 | 59 | } |
@@ -34,59 +34,59 @@ |
||
34 | 34 | use Symfony\Component\Console\Output\OutputInterface; |
35 | 35 | |
36 | 36 | class ConvertMysqlToMB4 extends Command { |
37 | - /** @var IConfig */ |
|
38 | - private $config; |
|
37 | + /** @var IConfig */ |
|
38 | + private $config; |
|
39 | 39 | |
40 | - /** @var IDBConnection */ |
|
41 | - private $connection; |
|
40 | + /** @var IDBConnection */ |
|
41 | + private $connection; |
|
42 | 42 | |
43 | - /** @var IURLGenerator */ |
|
44 | - private $urlGenerator; |
|
43 | + /** @var IURLGenerator */ |
|
44 | + private $urlGenerator; |
|
45 | 45 | |
46 | - /** @var ILogger */ |
|
47 | - private $logger; |
|
46 | + /** @var ILogger */ |
|
47 | + private $logger; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param IConfig $config |
|
51 | - * @param IDBConnection $connection |
|
52 | - * @param IURLGenerator $urlGenerator |
|
53 | - * @param ILogger $logger |
|
54 | - */ |
|
55 | - public function __construct(IConfig $config, IDBConnection $connection, IURLGenerator $urlGenerator, ILogger $logger) { |
|
56 | - $this->config = $config; |
|
57 | - $this->connection = $connection; |
|
58 | - $this->urlGenerator = $urlGenerator; |
|
59 | - $this->logger = $logger; |
|
60 | - parent::__construct(); |
|
61 | - } |
|
49 | + /** |
|
50 | + * @param IConfig $config |
|
51 | + * @param IDBConnection $connection |
|
52 | + * @param IURLGenerator $urlGenerator |
|
53 | + * @param ILogger $logger |
|
54 | + */ |
|
55 | + public function __construct(IConfig $config, IDBConnection $connection, IURLGenerator $urlGenerator, ILogger $logger) { |
|
56 | + $this->config = $config; |
|
57 | + $this->connection = $connection; |
|
58 | + $this->urlGenerator = $urlGenerator; |
|
59 | + $this->logger = $logger; |
|
60 | + parent::__construct(); |
|
61 | + } |
|
62 | 62 | |
63 | - protected function configure() { |
|
64 | - $this |
|
65 | - ->setName('db:convert-mysql-charset') |
|
66 | - ->setDescription('Convert charset of MySQL/MariaDB to use utf8mb4'); |
|
67 | - } |
|
63 | + protected function configure() { |
|
64 | + $this |
|
65 | + ->setName('db:convert-mysql-charset') |
|
66 | + ->setDescription('Convert charset of MySQL/MariaDB to use utf8mb4'); |
|
67 | + } |
|
68 | 68 | |
69 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | - if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) { |
|
71 | - $output->writeln("This command is only valid for MySQL/MariaDB databases."); |
|
72 | - return 1; |
|
73 | - } |
|
69 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | + if (!$this->connection->getDatabasePlatform() instanceof MySqlPlatform) { |
|
71 | + $output->writeln("This command is only valid for MySQL/MariaDB databases."); |
|
72 | + return 1; |
|
73 | + } |
|
74 | 74 | |
75 | - $tools = new MySqlTools(); |
|
76 | - if (!$tools->supports4ByteCharset($this->connection)) { |
|
77 | - $url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4'); |
|
78 | - $output->writeln("The database is not properly setup to use the charset utf8mb4."); |
|
79 | - $output->writeln("For more information please read the documentation at $url"); |
|
80 | - return 1; |
|
81 | - } |
|
75 | + $tools = new MySqlTools(); |
|
76 | + if (!$tools->supports4ByteCharset($this->connection)) { |
|
77 | + $url = $this->urlGenerator->linkToDocs('admin-mysql-utf8mb4'); |
|
78 | + $output->writeln("The database is not properly setup to use the charset utf8mb4."); |
|
79 | + $output->writeln("For more information please read the documentation at $url"); |
|
80 | + return 1; |
|
81 | + } |
|
82 | 82 | |
83 | - // enable charset |
|
84 | - $this->config->setSystemValue('mysql.utf8mb4', true); |
|
83 | + // enable charset |
|
84 | + $this->config->setSystemValue('mysql.utf8mb4', true); |
|
85 | 85 | |
86 | - // run conversion |
|
87 | - $coll = new Collation($this->config, $this->logger, $this->connection, false); |
|
88 | - $coll->run(new ConsoleOutput($output)); |
|
86 | + // run conversion |
|
87 | + $coll = new Collation($this->config, $this->logger, $this->connection, false); |
|
88 | + $coll->run(new ConsoleOutput($output)); |
|
89 | 89 | |
90 | - return 0; |
|
91 | - } |
|
90 | + return 0; |
|
91 | + } |
|
92 | 92 | } |
@@ -35,55 +35,55 @@ |
||
35 | 35 | * @since 8.0.0 |
36 | 36 | */ |
37 | 37 | interface IEventLogger { |
38 | - /** |
|
39 | - * Mark the start of an event setting its ID $id and providing event description $description. |
|
40 | - * |
|
41 | - * @param string $id |
|
42 | - * @param string $description |
|
43 | - * @since 8.0.0 |
|
44 | - */ |
|
45 | - public function start($id, $description); |
|
38 | + /** |
|
39 | + * Mark the start of an event setting its ID $id and providing event description $description. |
|
40 | + * |
|
41 | + * @param string $id |
|
42 | + * @param string $description |
|
43 | + * @since 8.0.0 |
|
44 | + */ |
|
45 | + public function start($id, $description); |
|
46 | 46 | |
47 | - /** |
|
48 | - * Mark the end of an event with specific ID $id, marked by start() method. |
|
49 | - * Ending event should store \OCP\Diagnostics\IEvent to |
|
50 | - * be returned with getEvents() method. |
|
51 | - * |
|
52 | - * @param string $id |
|
53 | - * @since 8.0.0 |
|
54 | - */ |
|
55 | - public function end($id); |
|
47 | + /** |
|
48 | + * Mark the end of an event with specific ID $id, marked by start() method. |
|
49 | + * Ending event should store \OCP\Diagnostics\IEvent to |
|
50 | + * be returned with getEvents() method. |
|
51 | + * |
|
52 | + * @param string $id |
|
53 | + * @since 8.0.0 |
|
54 | + */ |
|
55 | + public function end($id); |
|
56 | 56 | |
57 | - /** |
|
58 | - * Mark the start and the end of an event with specific ID $id and description $description, |
|
59 | - * explicitly marking start and end of the event, represented by $start and $end timestamps. |
|
60 | - * Logging event should store \OCP\Diagnostics\IEvent to |
|
61 | - * be returned with getEvents() method. |
|
62 | - * |
|
63 | - * @param string $id |
|
64 | - * @param string $description |
|
65 | - * @param float $start |
|
66 | - * @param float $end |
|
67 | - * @since 8.0.0 |
|
68 | - */ |
|
69 | - public function log($id, $description, $start, $end); |
|
57 | + /** |
|
58 | + * Mark the start and the end of an event with specific ID $id and description $description, |
|
59 | + * explicitly marking start and end of the event, represented by $start and $end timestamps. |
|
60 | + * Logging event should store \OCP\Diagnostics\IEvent to |
|
61 | + * be returned with getEvents() method. |
|
62 | + * |
|
63 | + * @param string $id |
|
64 | + * @param string $description |
|
65 | + * @param float $start |
|
66 | + * @param float $end |
|
67 | + * @since 8.0.0 |
|
68 | + */ |
|
69 | + public function log($id, $description, $start, $end); |
|
70 | 70 | |
71 | - /** |
|
72 | - * This method should return all \OCP\Diagnostics\IEvent objects stored using |
|
73 | - * start()/end() or log() methods |
|
74 | - * |
|
75 | - * @return \OCP\Diagnostics\IEvent[] |
|
76 | - * @since 8.0.0 |
|
77 | - */ |
|
78 | - public function getEvents(); |
|
71 | + /** |
|
72 | + * This method should return all \OCP\Diagnostics\IEvent objects stored using |
|
73 | + * start()/end() or log() methods |
|
74 | + * |
|
75 | + * @return \OCP\Diagnostics\IEvent[] |
|
76 | + * @since 8.0.0 |
|
77 | + */ |
|
78 | + public function getEvents(); |
|
79 | 79 | |
80 | - /** |
|
81 | - * Activate the module for the duration of the request. Deactivated module |
|
82 | - * does not create and store \OCP\Diagnostics\IEvent objects. |
|
83 | - * Only activated module should create and store objects to be |
|
84 | - * returned with getEvents() call. |
|
85 | - * |
|
86 | - * @since 12.0.0 |
|
87 | - */ |
|
88 | - public function activate(); |
|
80 | + /** |
|
81 | + * Activate the module for the duration of the request. Deactivated module |
|
82 | + * does not create and store \OCP\Diagnostics\IEvent objects. |
|
83 | + * Only activated module should create and store objects to be |
|
84 | + * returned with getEvents() call. |
|
85 | + * |
|
86 | + * @since 12.0.0 |
|
87 | + */ |
|
88 | + public function activate(); |
|
89 | 89 | } |
@@ -30,38 +30,38 @@ |
||
30 | 30 | * @since 8.0.0 |
31 | 31 | */ |
32 | 32 | interface IQuery { |
33 | - /** |
|
34 | - * @return string |
|
35 | - * @since 8.0.0 |
|
36 | - */ |
|
37 | - public function getSql(); |
|
33 | + /** |
|
34 | + * @return string |
|
35 | + * @since 8.0.0 |
|
36 | + */ |
|
37 | + public function getSql(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return array |
|
41 | - * @since 8.0.0 |
|
42 | - */ |
|
43 | - public function getParams(); |
|
39 | + /** |
|
40 | + * @return array |
|
41 | + * @since 8.0.0 |
|
42 | + */ |
|
43 | + public function getParams(); |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return float |
|
47 | - * @since 8.0.0 |
|
48 | - */ |
|
49 | - public function getDuration(); |
|
45 | + /** |
|
46 | + * @return float |
|
47 | + * @since 8.0.0 |
|
48 | + */ |
|
49 | + public function getDuration(); |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return float |
|
53 | - * @since 11.0.0 |
|
54 | - */ |
|
55 | - public function getStartTime(); |
|
51 | + /** |
|
52 | + * @return float |
|
53 | + * @since 11.0.0 |
|
54 | + */ |
|
55 | + public function getStartTime(); |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return array |
|
59 | - * @since 11.0.0 |
|
60 | - */ |
|
61 | - public function getStacktrace(); |
|
62 | - /** |
|
63 | - * @return array |
|
64 | - * @since 12.0.0 |
|
65 | - */ |
|
66 | - public function getStart(); |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + * @since 11.0.0 |
|
60 | + */ |
|
61 | + public function getStacktrace(); |
|
62 | + /** |
|
63 | + * @return array |
|
64 | + * @since 12.0.0 |
|
65 | + */ |
|
66 | + public function getStart(); |
|
67 | 67 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | return parent::connect(); |
59 | 59 | } catch (DBALException $e) { |
60 | 60 | // throw a new exception to prevent leaking info from the stacktrace |
61 | - throw new DBALException('Failed to connect to the database: ' . $e->getMessage(), $e->getCode()); |
|
61 | + throw new DBALException('Failed to connect to the database: '.$e->getMessage(), $e->getCode()); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | // 0 is the method where we use `getCallerBacktrace` |
111 | 111 | // 1 is the target method which uses the method we want to log |
112 | 112 | if (isset($traces[1])) { |
113 | - return $traces[1]['file'] . ':' . $traces[1]['line']; |
|
113 | + return $traces[1]['file'].':'.$traces[1]['line']; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | return ''; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | * @param int $offset |
157 | 157 | * @return \Doctrine\DBAL\Driver\Statement The prepared statement. |
158 | 158 | */ |
159 | - public function prepare( $statement, $limit=null, $offset=null ) { |
|
159 | + public function prepare($statement, $limit = null, $offset = null) { |
|
160 | 160 | if ($limit === -1) { |
161 | 161 | $limit = null; |
162 | 162 | } |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.'); |
322 | 322 | } |
323 | 323 | |
324 | - $tableName = $this->tablePrefix . $tableName; |
|
324 | + $tableName = $this->tablePrefix.$tableName; |
|
325 | 325 | $this->lockedTable = $tableName; |
326 | 326 | $this->adapter->lockTable($tableName); |
327 | 327 | } |
@@ -342,11 +342,11 @@ discard block |
||
342 | 342 | * @return string |
343 | 343 | */ |
344 | 344 | public function getError() { |
345 | - $msg = $this->errorCode() . ': '; |
|
345 | + $msg = $this->errorCode().': '; |
|
346 | 346 | $errorInfo = $this->errorInfo(); |
347 | 347 | if (is_array($errorInfo)) { |
348 | - $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; |
|
349 | - $msg .= 'Driver Code = '.$errorInfo[1] . ', '; |
|
348 | + $msg .= 'SQLSTATE = '.$errorInfo[0].', '; |
|
349 | + $msg .= 'Driver Code = '.$errorInfo[1].', '; |
|
350 | 350 | $msg .= 'Driver Message = '.$errorInfo[2]; |
351 | 351 | } |
352 | 352 | return $msg; |
@@ -358,9 +358,9 @@ discard block |
||
358 | 358 | * @param string $table table name without the prefix |
359 | 359 | */ |
360 | 360 | public function dropTable($table) { |
361 | - $table = $this->tablePrefix . trim($table); |
|
361 | + $table = $this->tablePrefix.trim($table); |
|
362 | 362 | $schema = $this->getSchemaManager(); |
363 | - if($schema->tablesExist(array($table))) { |
|
363 | + if ($schema->tablesExist(array($table))) { |
|
364 | 364 | $schema->dropTable($table); |
365 | 365 | } |
366 | 366 | } |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | * @param string $table table name without the prefix |
372 | 372 | * @return bool |
373 | 373 | */ |
374 | - public function tableExists($table){ |
|
375 | - $table = $this->tablePrefix . trim($table); |
|
374 | + public function tableExists($table) { |
|
375 | + $table = $this->tablePrefix.trim($table); |
|
376 | 376 | $schema = $this->getSchemaManager(); |
377 | 377 | return $schema->tablesExist(array($table)); |
378 | 378 | } |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @return string |
384 | 384 | */ |
385 | 385 | protected function replaceTablePrefix($statement) { |
386 | - return str_replace( '*PREFIX*', $this->tablePrefix, $statement ); |
|
386 | + return str_replace('*PREFIX*', $this->tablePrefix, $statement); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -44,412 +44,412 @@ |
||
44 | 44 | use OCP\PreConditionNotMetException; |
45 | 45 | |
46 | 46 | class Connection extends ReconnectWrapper implements IDBConnection { |
47 | - /** |
|
48 | - * @var string $tablePrefix |
|
49 | - */ |
|
50 | - protected $tablePrefix; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var \OC\DB\Adapter $adapter |
|
54 | - */ |
|
55 | - protected $adapter; |
|
56 | - |
|
57 | - protected $lockedTable = null; |
|
58 | - |
|
59 | - public function connect() { |
|
60 | - try { |
|
61 | - return parent::connect(); |
|
62 | - } catch (DBALException $e) { |
|
63 | - // throw a new exception to prevent leaking info from the stacktrace |
|
64 | - throw new DBALException('Failed to connect to the database: ' . $e->getMessage(), $e->getCode()); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Returns a QueryBuilder for the connection. |
|
70 | - * |
|
71 | - * @return \OCP\DB\QueryBuilder\IQueryBuilder |
|
72 | - */ |
|
73 | - public function getQueryBuilder() { |
|
74 | - return new QueryBuilder( |
|
75 | - $this, |
|
76 | - \OC::$server->getSystemConfig(), |
|
77 | - \OC::$server->getLogger() |
|
78 | - ); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Gets the QueryBuilder for the connection. |
|
83 | - * |
|
84 | - * @return \Doctrine\DBAL\Query\QueryBuilder |
|
85 | - * @deprecated please use $this->getQueryBuilder() instead |
|
86 | - */ |
|
87 | - public function createQueryBuilder() { |
|
88 | - $backtrace = $this->getCallerBacktrace(); |
|
89 | - \OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
90 | - return parent::createQueryBuilder(); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Gets the ExpressionBuilder for the connection. |
|
95 | - * |
|
96 | - * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder |
|
97 | - * @deprecated please use $this->getQueryBuilder()->expr() instead |
|
98 | - */ |
|
99 | - public function getExpressionBuilder() { |
|
100 | - $backtrace = $this->getCallerBacktrace(); |
|
101 | - \OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
102 | - return parent::getExpressionBuilder(); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Get the file and line that called the method where `getCallerBacktrace()` was used |
|
107 | - * |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - protected function getCallerBacktrace() { |
|
111 | - $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
|
112 | - |
|
113 | - // 0 is the method where we use `getCallerBacktrace` |
|
114 | - // 1 is the target method which uses the method we want to log |
|
115 | - if (isset($traces[1])) { |
|
116 | - return $traces[1]['file'] . ':' . $traces[1]['line']; |
|
117 | - } |
|
118 | - |
|
119 | - return ''; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public function getPrefix() { |
|
126 | - return $this->tablePrefix; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Initializes a new instance of the Connection class. |
|
131 | - * |
|
132 | - * @param array $params The connection parameters. |
|
133 | - * @param \Doctrine\DBAL\Driver $driver |
|
134 | - * @param \Doctrine\DBAL\Configuration $config |
|
135 | - * @param \Doctrine\Common\EventManager $eventManager |
|
136 | - * @throws \Exception |
|
137 | - */ |
|
138 | - public function __construct(array $params, Driver $driver, Configuration $config = null, |
|
139 | - EventManager $eventManager = null) |
|
140 | - { |
|
141 | - if (!isset($params['adapter'])) { |
|
142 | - throw new \Exception('adapter not set'); |
|
143 | - } |
|
144 | - if (!isset($params['tablePrefix'])) { |
|
145 | - throw new \Exception('tablePrefix not set'); |
|
146 | - } |
|
147 | - parent::__construct($params, $driver, $config, $eventManager); |
|
148 | - $this->adapter = new $params['adapter']($this); |
|
149 | - $this->tablePrefix = $params['tablePrefix']; |
|
150 | - |
|
151 | - parent::setTransactionIsolation(parent::TRANSACTION_READ_COMMITTED); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Prepares an SQL statement. |
|
156 | - * |
|
157 | - * @param string $statement The SQL statement to prepare. |
|
158 | - * @param int $limit |
|
159 | - * @param int $offset |
|
160 | - * @return \Doctrine\DBAL\Driver\Statement The prepared statement. |
|
161 | - */ |
|
162 | - public function prepare( $statement, $limit=null, $offset=null ) { |
|
163 | - if ($limit === -1) { |
|
164 | - $limit = null; |
|
165 | - } |
|
166 | - if (!is_null($limit)) { |
|
167 | - $platform = $this->getDatabasePlatform(); |
|
168 | - $statement = $platform->modifyLimitQuery($statement, $limit, $offset); |
|
169 | - } |
|
170 | - $statement = $this->replaceTablePrefix($statement); |
|
171 | - $statement = $this->adapter->fixupStatement($statement); |
|
172 | - |
|
173 | - return parent::prepare($statement); |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Executes an, optionally parametrized, SQL query. |
|
178 | - * |
|
179 | - * If the query is parametrized, a prepared statement is used. |
|
180 | - * If an SQLLogger is configured, the execution is logged. |
|
181 | - * |
|
182 | - * @param string $query The SQL query to execute. |
|
183 | - * @param array $params The parameters to bind to the query, if any. |
|
184 | - * @param array $types The types the previous parameters are in. |
|
185 | - * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional. |
|
186 | - * |
|
187 | - * @return \Doctrine\DBAL\Driver\Statement The executed statement. |
|
188 | - * |
|
189 | - * @throws \Doctrine\DBAL\DBALException |
|
190 | - */ |
|
191 | - public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null) |
|
192 | - { |
|
193 | - $query = $this->replaceTablePrefix($query); |
|
194 | - $query = $this->adapter->fixupStatement($query); |
|
195 | - return parent::executeQuery($query, $params, $types, $qcp); |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters |
|
200 | - * and returns the number of affected rows. |
|
201 | - * |
|
202 | - * This method supports PDO binding types as well as DBAL mapping types. |
|
203 | - * |
|
204 | - * @param string $query The SQL query. |
|
205 | - * @param array $params The query parameters. |
|
206 | - * @param array $types The parameter types. |
|
207 | - * |
|
208 | - * @return integer The number of affected rows. |
|
209 | - * |
|
210 | - * @throws \Doctrine\DBAL\DBALException |
|
211 | - */ |
|
212 | - public function executeUpdate($query, array $params = array(), array $types = array()) |
|
213 | - { |
|
214 | - $query = $this->replaceTablePrefix($query); |
|
215 | - $query = $this->adapter->fixupStatement($query); |
|
216 | - return parent::executeUpdate($query, $params, $types); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Returns the ID of the last inserted row, or the last value from a sequence object, |
|
221 | - * depending on the underlying driver. |
|
222 | - * |
|
223 | - * Note: This method may not return a meaningful or consistent result across different drivers, |
|
224 | - * because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY |
|
225 | - * columns or sequences. |
|
226 | - * |
|
227 | - * @param string $seqName Name of the sequence object from which the ID should be returned. |
|
228 | - * @return string A string representation of the last inserted ID. |
|
229 | - */ |
|
230 | - public function lastInsertId($seqName = null) { |
|
231 | - if ($seqName) { |
|
232 | - $seqName = $this->replaceTablePrefix($seqName); |
|
233 | - } |
|
234 | - return $this->adapter->lastInsertId($seqName); |
|
235 | - } |
|
236 | - |
|
237 | - // internal use |
|
238 | - public function realLastInsertId($seqName = null) { |
|
239 | - return parent::lastInsertId($seqName); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
244 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
245 | - * catch the exception and return 0. |
|
246 | - * |
|
247 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
248 | - * @param array $input data that should be inserted into the table (column name => value) |
|
249 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
250 | - * If this is null or an empty array, all keys of $input will be compared |
|
251 | - * Please note: text fields (clob) must not be used in the compare array |
|
252 | - * @return int number of inserted rows |
|
253 | - * @throws \Doctrine\DBAL\DBALException |
|
254 | - * @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 |
|
255 | - */ |
|
256 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
257 | - return $this->adapter->insertIfNotExist($table, $input, $compare); |
|
258 | - } |
|
259 | - |
|
260 | - public function insertIgnoreConflict(string $table, array $values) : int { |
|
261 | - return $this->adapter->insertIgnoreConflict($table, $values); |
|
262 | - } |
|
263 | - |
|
264 | - private function getType($value) { |
|
265 | - if (is_bool($value)) { |
|
266 | - return IQueryBuilder::PARAM_BOOL; |
|
267 | - } else if (is_int($value)) { |
|
268 | - return IQueryBuilder::PARAM_INT; |
|
269 | - } else { |
|
270 | - return IQueryBuilder::PARAM_STR; |
|
271 | - } |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Insert or update a row value |
|
276 | - * |
|
277 | - * @param string $table |
|
278 | - * @param array $keys (column name => value) |
|
279 | - * @param array $values (column name => value) |
|
280 | - * @param array $updatePreconditionValues ensure values match preconditions (column name => value) |
|
281 | - * @return int number of new rows |
|
282 | - * @throws \Doctrine\DBAL\DBALException |
|
283 | - * @throws PreConditionNotMetException |
|
284 | - * @suppress SqlInjectionChecker |
|
285 | - */ |
|
286 | - public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) { |
|
287 | - try { |
|
288 | - $insertQb = $this->getQueryBuilder(); |
|
289 | - $insertQb->insert($table) |
|
290 | - ->values( |
|
291 | - array_map(function($value) use ($insertQb) { |
|
292 | - return $insertQb->createNamedParameter($value, $this->getType($value)); |
|
293 | - }, array_merge($keys, $values)) |
|
294 | - ); |
|
295 | - return $insertQb->execute(); |
|
296 | - } catch (ConstraintViolationException $e) { |
|
297 | - // value already exists, try update |
|
298 | - $updateQb = $this->getQueryBuilder(); |
|
299 | - $updateQb->update($table); |
|
300 | - foreach ($values as $name => $value) { |
|
301 | - $updateQb->set($name, $updateQb->createNamedParameter($value, $this->getType($value))); |
|
302 | - } |
|
303 | - $where = $updateQb->expr()->andX(); |
|
304 | - $whereValues = array_merge($keys, $updatePreconditionValues); |
|
305 | - foreach ($whereValues as $name => $value) { |
|
306 | - $where->add($updateQb->expr()->eq( |
|
307 | - $name, |
|
308 | - $updateQb->createNamedParameter($value, $this->getType($value)), |
|
309 | - $this->getType($value) |
|
310 | - )); |
|
311 | - } |
|
312 | - $updateQb->where($where); |
|
313 | - $affected = $updateQb->execute(); |
|
314 | - |
|
315 | - if ($affected === 0 && !empty($updatePreconditionValues)) { |
|
316 | - throw new PreConditionNotMetException(); |
|
317 | - } |
|
318 | - |
|
319 | - return 0; |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Create an exclusive read+write lock on a table |
|
325 | - * |
|
326 | - * @param string $tableName |
|
327 | - * @throws \BadMethodCallException When trying to acquire a second lock |
|
328 | - * @since 9.1.0 |
|
329 | - */ |
|
330 | - public function lockTable($tableName) { |
|
331 | - if ($this->lockedTable !== null) { |
|
332 | - throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.'); |
|
333 | - } |
|
334 | - |
|
335 | - $tableName = $this->tablePrefix . $tableName; |
|
336 | - $this->lockedTable = $tableName; |
|
337 | - $this->adapter->lockTable($tableName); |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Release a previous acquired lock again |
|
342 | - * |
|
343 | - * @since 9.1.0 |
|
344 | - */ |
|
345 | - public function unlockTable() { |
|
346 | - $this->adapter->unlockTable(); |
|
347 | - $this->lockedTable = null; |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * returns the error code and message as a string for logging |
|
352 | - * works with DoctrineException |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - public function getError() { |
|
356 | - $msg = $this->errorCode() . ': '; |
|
357 | - $errorInfo = $this->errorInfo(); |
|
358 | - if (is_array($errorInfo)) { |
|
359 | - $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; |
|
360 | - $msg .= 'Driver Code = '.$errorInfo[1] . ', '; |
|
361 | - $msg .= 'Driver Message = '.$errorInfo[2]; |
|
362 | - } |
|
363 | - return $msg; |
|
364 | - } |
|
365 | - |
|
366 | - /** |
|
367 | - * Drop a table from the database if it exists |
|
368 | - * |
|
369 | - * @param string $table table name without the prefix |
|
370 | - */ |
|
371 | - public function dropTable($table) { |
|
372 | - $table = $this->tablePrefix . trim($table); |
|
373 | - $schema = $this->getSchemaManager(); |
|
374 | - if($schema->tablesExist(array($table))) { |
|
375 | - $schema->dropTable($table); |
|
376 | - } |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Check if a table exists |
|
381 | - * |
|
382 | - * @param string $table table name without the prefix |
|
383 | - * @return bool |
|
384 | - */ |
|
385 | - public function tableExists($table){ |
|
386 | - $table = $this->tablePrefix . trim($table); |
|
387 | - $schema = $this->getSchemaManager(); |
|
388 | - return $schema->tablesExist(array($table)); |
|
389 | - } |
|
390 | - |
|
391 | - // internal use |
|
392 | - /** |
|
393 | - * @param string $statement |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - protected function replaceTablePrefix($statement) { |
|
397 | - return str_replace( '*PREFIX*', $this->tablePrefix, $statement ); |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Check if a transaction is active |
|
402 | - * |
|
403 | - * @return bool |
|
404 | - * @since 8.2.0 |
|
405 | - */ |
|
406 | - public function inTransaction() { |
|
407 | - return $this->getTransactionNestingLevel() > 0; |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Escape a parameter to be used in a LIKE query |
|
412 | - * |
|
413 | - * @param string $param |
|
414 | - * @return string |
|
415 | - */ |
|
416 | - public function escapeLikeParameter($param) { |
|
417 | - return addcslashes($param, '\\_%'); |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * Check whether or not the current database support 4byte wide unicode |
|
422 | - * |
|
423 | - * @return bool |
|
424 | - * @since 11.0.0 |
|
425 | - */ |
|
426 | - public function supports4ByteText() { |
|
427 | - if (!$this->getDatabasePlatform() instanceof MySqlPlatform) { |
|
428 | - return true; |
|
429 | - } |
|
430 | - return $this->getParams()['charset'] === 'utf8mb4'; |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * Create the schema of the connected database |
|
436 | - * |
|
437 | - * @return Schema |
|
438 | - */ |
|
439 | - public function createSchema() { |
|
440 | - $schemaManager = new MDB2SchemaManager($this); |
|
441 | - $migrator = $schemaManager->getMigrator(); |
|
442 | - return $migrator->createSchema(); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Migrate the database to the given schema |
|
447 | - * |
|
448 | - * @param Schema $toSchema |
|
449 | - */ |
|
450 | - public function migrateToSchema(Schema $toSchema) { |
|
451 | - $schemaManager = new MDB2SchemaManager($this); |
|
452 | - $migrator = $schemaManager->getMigrator(); |
|
453 | - $migrator->migrate($toSchema); |
|
454 | - } |
|
47 | + /** |
|
48 | + * @var string $tablePrefix |
|
49 | + */ |
|
50 | + protected $tablePrefix; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var \OC\DB\Adapter $adapter |
|
54 | + */ |
|
55 | + protected $adapter; |
|
56 | + |
|
57 | + protected $lockedTable = null; |
|
58 | + |
|
59 | + public function connect() { |
|
60 | + try { |
|
61 | + return parent::connect(); |
|
62 | + } catch (DBALException $e) { |
|
63 | + // throw a new exception to prevent leaking info from the stacktrace |
|
64 | + throw new DBALException('Failed to connect to the database: ' . $e->getMessage(), $e->getCode()); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Returns a QueryBuilder for the connection. |
|
70 | + * |
|
71 | + * @return \OCP\DB\QueryBuilder\IQueryBuilder |
|
72 | + */ |
|
73 | + public function getQueryBuilder() { |
|
74 | + return new QueryBuilder( |
|
75 | + $this, |
|
76 | + \OC::$server->getSystemConfig(), |
|
77 | + \OC::$server->getLogger() |
|
78 | + ); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Gets the QueryBuilder for the connection. |
|
83 | + * |
|
84 | + * @return \Doctrine\DBAL\Query\QueryBuilder |
|
85 | + * @deprecated please use $this->getQueryBuilder() instead |
|
86 | + */ |
|
87 | + public function createQueryBuilder() { |
|
88 | + $backtrace = $this->getCallerBacktrace(); |
|
89 | + \OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
90 | + return parent::createQueryBuilder(); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Gets the ExpressionBuilder for the connection. |
|
95 | + * |
|
96 | + * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder |
|
97 | + * @deprecated please use $this->getQueryBuilder()->expr() instead |
|
98 | + */ |
|
99 | + public function getExpressionBuilder() { |
|
100 | + $backtrace = $this->getCallerBacktrace(); |
|
101 | + \OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
102 | + return parent::getExpressionBuilder(); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Get the file and line that called the method where `getCallerBacktrace()` was used |
|
107 | + * |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + protected function getCallerBacktrace() { |
|
111 | + $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
|
112 | + |
|
113 | + // 0 is the method where we use `getCallerBacktrace` |
|
114 | + // 1 is the target method which uses the method we want to log |
|
115 | + if (isset($traces[1])) { |
|
116 | + return $traces[1]['file'] . ':' . $traces[1]['line']; |
|
117 | + } |
|
118 | + |
|
119 | + return ''; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public function getPrefix() { |
|
126 | + return $this->tablePrefix; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Initializes a new instance of the Connection class. |
|
131 | + * |
|
132 | + * @param array $params The connection parameters. |
|
133 | + * @param \Doctrine\DBAL\Driver $driver |
|
134 | + * @param \Doctrine\DBAL\Configuration $config |
|
135 | + * @param \Doctrine\Common\EventManager $eventManager |
|
136 | + * @throws \Exception |
|
137 | + */ |
|
138 | + public function __construct(array $params, Driver $driver, Configuration $config = null, |
|
139 | + EventManager $eventManager = null) |
|
140 | + { |
|
141 | + if (!isset($params['adapter'])) { |
|
142 | + throw new \Exception('adapter not set'); |
|
143 | + } |
|
144 | + if (!isset($params['tablePrefix'])) { |
|
145 | + throw new \Exception('tablePrefix not set'); |
|
146 | + } |
|
147 | + parent::__construct($params, $driver, $config, $eventManager); |
|
148 | + $this->adapter = new $params['adapter']($this); |
|
149 | + $this->tablePrefix = $params['tablePrefix']; |
|
150 | + |
|
151 | + parent::setTransactionIsolation(parent::TRANSACTION_READ_COMMITTED); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Prepares an SQL statement. |
|
156 | + * |
|
157 | + * @param string $statement The SQL statement to prepare. |
|
158 | + * @param int $limit |
|
159 | + * @param int $offset |
|
160 | + * @return \Doctrine\DBAL\Driver\Statement The prepared statement. |
|
161 | + */ |
|
162 | + public function prepare( $statement, $limit=null, $offset=null ) { |
|
163 | + if ($limit === -1) { |
|
164 | + $limit = null; |
|
165 | + } |
|
166 | + if (!is_null($limit)) { |
|
167 | + $platform = $this->getDatabasePlatform(); |
|
168 | + $statement = $platform->modifyLimitQuery($statement, $limit, $offset); |
|
169 | + } |
|
170 | + $statement = $this->replaceTablePrefix($statement); |
|
171 | + $statement = $this->adapter->fixupStatement($statement); |
|
172 | + |
|
173 | + return parent::prepare($statement); |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Executes an, optionally parametrized, SQL query. |
|
178 | + * |
|
179 | + * If the query is parametrized, a prepared statement is used. |
|
180 | + * If an SQLLogger is configured, the execution is logged. |
|
181 | + * |
|
182 | + * @param string $query The SQL query to execute. |
|
183 | + * @param array $params The parameters to bind to the query, if any. |
|
184 | + * @param array $types The types the previous parameters are in. |
|
185 | + * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional. |
|
186 | + * |
|
187 | + * @return \Doctrine\DBAL\Driver\Statement The executed statement. |
|
188 | + * |
|
189 | + * @throws \Doctrine\DBAL\DBALException |
|
190 | + */ |
|
191 | + public function executeQuery($query, array $params = array(), $types = array(), QueryCacheProfile $qcp = null) |
|
192 | + { |
|
193 | + $query = $this->replaceTablePrefix($query); |
|
194 | + $query = $this->adapter->fixupStatement($query); |
|
195 | + return parent::executeQuery($query, $params, $types, $qcp); |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters |
|
200 | + * and returns the number of affected rows. |
|
201 | + * |
|
202 | + * This method supports PDO binding types as well as DBAL mapping types. |
|
203 | + * |
|
204 | + * @param string $query The SQL query. |
|
205 | + * @param array $params The query parameters. |
|
206 | + * @param array $types The parameter types. |
|
207 | + * |
|
208 | + * @return integer The number of affected rows. |
|
209 | + * |
|
210 | + * @throws \Doctrine\DBAL\DBALException |
|
211 | + */ |
|
212 | + public function executeUpdate($query, array $params = array(), array $types = array()) |
|
213 | + { |
|
214 | + $query = $this->replaceTablePrefix($query); |
|
215 | + $query = $this->adapter->fixupStatement($query); |
|
216 | + return parent::executeUpdate($query, $params, $types); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Returns the ID of the last inserted row, or the last value from a sequence object, |
|
221 | + * depending on the underlying driver. |
|
222 | + * |
|
223 | + * Note: This method may not return a meaningful or consistent result across different drivers, |
|
224 | + * because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY |
|
225 | + * columns or sequences. |
|
226 | + * |
|
227 | + * @param string $seqName Name of the sequence object from which the ID should be returned. |
|
228 | + * @return string A string representation of the last inserted ID. |
|
229 | + */ |
|
230 | + public function lastInsertId($seqName = null) { |
|
231 | + if ($seqName) { |
|
232 | + $seqName = $this->replaceTablePrefix($seqName); |
|
233 | + } |
|
234 | + return $this->adapter->lastInsertId($seqName); |
|
235 | + } |
|
236 | + |
|
237 | + // internal use |
|
238 | + public function realLastInsertId($seqName = null) { |
|
239 | + return parent::lastInsertId($seqName); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
244 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
245 | + * catch the exception and return 0. |
|
246 | + * |
|
247 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
248 | + * @param array $input data that should be inserted into the table (column name => value) |
|
249 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
250 | + * If this is null or an empty array, all keys of $input will be compared |
|
251 | + * Please note: text fields (clob) must not be used in the compare array |
|
252 | + * @return int number of inserted rows |
|
253 | + * @throws \Doctrine\DBAL\DBALException |
|
254 | + * @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 |
|
255 | + */ |
|
256 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
257 | + return $this->adapter->insertIfNotExist($table, $input, $compare); |
|
258 | + } |
|
259 | + |
|
260 | + public function insertIgnoreConflict(string $table, array $values) : int { |
|
261 | + return $this->adapter->insertIgnoreConflict($table, $values); |
|
262 | + } |
|
263 | + |
|
264 | + private function getType($value) { |
|
265 | + if (is_bool($value)) { |
|
266 | + return IQueryBuilder::PARAM_BOOL; |
|
267 | + } else if (is_int($value)) { |
|
268 | + return IQueryBuilder::PARAM_INT; |
|
269 | + } else { |
|
270 | + return IQueryBuilder::PARAM_STR; |
|
271 | + } |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Insert or update a row value |
|
276 | + * |
|
277 | + * @param string $table |
|
278 | + * @param array $keys (column name => value) |
|
279 | + * @param array $values (column name => value) |
|
280 | + * @param array $updatePreconditionValues ensure values match preconditions (column name => value) |
|
281 | + * @return int number of new rows |
|
282 | + * @throws \Doctrine\DBAL\DBALException |
|
283 | + * @throws PreConditionNotMetException |
|
284 | + * @suppress SqlInjectionChecker |
|
285 | + */ |
|
286 | + public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) { |
|
287 | + try { |
|
288 | + $insertQb = $this->getQueryBuilder(); |
|
289 | + $insertQb->insert($table) |
|
290 | + ->values( |
|
291 | + array_map(function($value) use ($insertQb) { |
|
292 | + return $insertQb->createNamedParameter($value, $this->getType($value)); |
|
293 | + }, array_merge($keys, $values)) |
|
294 | + ); |
|
295 | + return $insertQb->execute(); |
|
296 | + } catch (ConstraintViolationException $e) { |
|
297 | + // value already exists, try update |
|
298 | + $updateQb = $this->getQueryBuilder(); |
|
299 | + $updateQb->update($table); |
|
300 | + foreach ($values as $name => $value) { |
|
301 | + $updateQb->set($name, $updateQb->createNamedParameter($value, $this->getType($value))); |
|
302 | + } |
|
303 | + $where = $updateQb->expr()->andX(); |
|
304 | + $whereValues = array_merge($keys, $updatePreconditionValues); |
|
305 | + foreach ($whereValues as $name => $value) { |
|
306 | + $where->add($updateQb->expr()->eq( |
|
307 | + $name, |
|
308 | + $updateQb->createNamedParameter($value, $this->getType($value)), |
|
309 | + $this->getType($value) |
|
310 | + )); |
|
311 | + } |
|
312 | + $updateQb->where($where); |
|
313 | + $affected = $updateQb->execute(); |
|
314 | + |
|
315 | + if ($affected === 0 && !empty($updatePreconditionValues)) { |
|
316 | + throw new PreConditionNotMetException(); |
|
317 | + } |
|
318 | + |
|
319 | + return 0; |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Create an exclusive read+write lock on a table |
|
325 | + * |
|
326 | + * @param string $tableName |
|
327 | + * @throws \BadMethodCallException When trying to acquire a second lock |
|
328 | + * @since 9.1.0 |
|
329 | + */ |
|
330 | + public function lockTable($tableName) { |
|
331 | + if ($this->lockedTable !== null) { |
|
332 | + throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.'); |
|
333 | + } |
|
334 | + |
|
335 | + $tableName = $this->tablePrefix . $tableName; |
|
336 | + $this->lockedTable = $tableName; |
|
337 | + $this->adapter->lockTable($tableName); |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Release a previous acquired lock again |
|
342 | + * |
|
343 | + * @since 9.1.0 |
|
344 | + */ |
|
345 | + public function unlockTable() { |
|
346 | + $this->adapter->unlockTable(); |
|
347 | + $this->lockedTable = null; |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * returns the error code and message as a string for logging |
|
352 | + * works with DoctrineException |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + public function getError() { |
|
356 | + $msg = $this->errorCode() . ': '; |
|
357 | + $errorInfo = $this->errorInfo(); |
|
358 | + if (is_array($errorInfo)) { |
|
359 | + $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; |
|
360 | + $msg .= 'Driver Code = '.$errorInfo[1] . ', '; |
|
361 | + $msg .= 'Driver Message = '.$errorInfo[2]; |
|
362 | + } |
|
363 | + return $msg; |
|
364 | + } |
|
365 | + |
|
366 | + /** |
|
367 | + * Drop a table from the database if it exists |
|
368 | + * |
|
369 | + * @param string $table table name without the prefix |
|
370 | + */ |
|
371 | + public function dropTable($table) { |
|
372 | + $table = $this->tablePrefix . trim($table); |
|
373 | + $schema = $this->getSchemaManager(); |
|
374 | + if($schema->tablesExist(array($table))) { |
|
375 | + $schema->dropTable($table); |
|
376 | + } |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Check if a table exists |
|
381 | + * |
|
382 | + * @param string $table table name without the prefix |
|
383 | + * @return bool |
|
384 | + */ |
|
385 | + public function tableExists($table){ |
|
386 | + $table = $this->tablePrefix . trim($table); |
|
387 | + $schema = $this->getSchemaManager(); |
|
388 | + return $schema->tablesExist(array($table)); |
|
389 | + } |
|
390 | + |
|
391 | + // internal use |
|
392 | + /** |
|
393 | + * @param string $statement |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + protected function replaceTablePrefix($statement) { |
|
397 | + return str_replace( '*PREFIX*', $this->tablePrefix, $statement ); |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Check if a transaction is active |
|
402 | + * |
|
403 | + * @return bool |
|
404 | + * @since 8.2.0 |
|
405 | + */ |
|
406 | + public function inTransaction() { |
|
407 | + return $this->getTransactionNestingLevel() > 0; |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Escape a parameter to be used in a LIKE query |
|
412 | + * |
|
413 | + * @param string $param |
|
414 | + * @return string |
|
415 | + */ |
|
416 | + public function escapeLikeParameter($param) { |
|
417 | + return addcslashes($param, '\\_%'); |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * Check whether or not the current database support 4byte wide unicode |
|
422 | + * |
|
423 | + * @return bool |
|
424 | + * @since 11.0.0 |
|
425 | + */ |
|
426 | + public function supports4ByteText() { |
|
427 | + if (!$this->getDatabasePlatform() instanceof MySqlPlatform) { |
|
428 | + return true; |
|
429 | + } |
|
430 | + return $this->getParams()['charset'] === 'utf8mb4'; |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * Create the schema of the connected database |
|
436 | + * |
|
437 | + * @return Schema |
|
438 | + */ |
|
439 | + public function createSchema() { |
|
440 | + $schemaManager = new MDB2SchemaManager($this); |
|
441 | + $migrator = $schemaManager->getMigrator(); |
|
442 | + return $migrator->createSchema(); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Migrate the database to the given schema |
|
447 | + * |
|
448 | + * @param Schema $toSchema |
|
449 | + */ |
|
450 | + public function migrateToSchema(Schema $toSchema) { |
|
451 | + $schemaManager = new MDB2SchemaManager($this); |
|
452 | + $migrator = $schemaManager->getMigrator(); |
|
453 | + $migrator->migrate($toSchema); |
|
454 | + } |
|
455 | 455 | } |
@@ -28,56 +28,56 @@ |
||
28 | 28 | use OCP\Diagnostics\IEventLogger; |
29 | 29 | |
30 | 30 | class EventLogger implements IEventLogger { |
31 | - /** |
|
32 | - * @var \OC\Diagnostics\Event[] |
|
33 | - */ |
|
34 | - private $events = []; |
|
31 | + /** |
|
32 | + * @var \OC\Diagnostics\Event[] |
|
33 | + */ |
|
34 | + private $events = []; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var bool - Module needs to be activated by some app |
|
38 | - */ |
|
39 | - private $activated = false; |
|
36 | + /** |
|
37 | + * @var bool - Module needs to be activated by some app |
|
38 | + */ |
|
39 | + private $activated = false; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @inheritdoc |
|
43 | - */ |
|
44 | - public function start($id, $description) { |
|
45 | - if ($this->activated){ |
|
46 | - $this->events[$id] = new Event($id, $description, microtime(true)); |
|
47 | - } |
|
48 | - } |
|
41 | + /** |
|
42 | + * @inheritdoc |
|
43 | + */ |
|
44 | + public function start($id, $description) { |
|
45 | + if ($this->activated){ |
|
46 | + $this->events[$id] = new Event($id, $description, microtime(true)); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @inheritdoc |
|
52 | - */ |
|
53 | - public function end($id) { |
|
54 | - if ($this->activated && isset($this->events[$id])) { |
|
55 | - $timing = $this->events[$id]; |
|
56 | - $timing->end(microtime(true)); |
|
57 | - } |
|
58 | - } |
|
50 | + /** |
|
51 | + * @inheritdoc |
|
52 | + */ |
|
53 | + public function end($id) { |
|
54 | + if ($this->activated && isset($this->events[$id])) { |
|
55 | + $timing = $this->events[$id]; |
|
56 | + $timing->end(microtime(true)); |
|
57 | + } |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @inheritdoc |
|
62 | - */ |
|
63 | - public function log($id, $description, $start, $end) { |
|
64 | - if ($this->activated) { |
|
65 | - $this->events[$id] = new Event($id, $description, $start); |
|
66 | - $this->events[$id]->end($end); |
|
67 | - } |
|
68 | - } |
|
60 | + /** |
|
61 | + * @inheritdoc |
|
62 | + */ |
|
63 | + public function log($id, $description, $start, $end) { |
|
64 | + if ($this->activated) { |
|
65 | + $this->events[$id] = new Event($id, $description, $start); |
|
66 | + $this->events[$id]->end($end); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * @inheritdoc |
|
72 | - */ |
|
73 | - public function getEvents() { |
|
74 | - return $this->events; |
|
75 | - } |
|
70 | + /** |
|
71 | + * @inheritdoc |
|
72 | + */ |
|
73 | + public function getEvents() { |
|
74 | + return $this->events; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * @inheritdoc |
|
79 | - */ |
|
80 | - public function activate() { |
|
81 | - $this->activated = true; |
|
82 | - } |
|
77 | + /** |
|
78 | + * @inheritdoc |
|
79 | + */ |
|
80 | + public function activate() { |
|
81 | + $this->activated = true; |
|
82 | + } |
|
83 | 83 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | * @inheritdoc |
43 | 43 | */ |
44 | 44 | public function start($id, $description) { |
45 | - if ($this->activated){ |
|
45 | + if ($this->activated) { |
|
46 | 46 | $this->events[$id] = new Event($id, $description, microtime(true)); |
47 | 47 | } |
48 | 48 | } |
@@ -26,65 +26,65 @@ |
||
26 | 26 | use OCP\Diagnostics\IQuery; |
27 | 27 | |
28 | 28 | class Query implements IQuery { |
29 | - private $sql; |
|
29 | + private $sql; |
|
30 | 30 | |
31 | - private $params; |
|
31 | + private $params; |
|
32 | 32 | |
33 | - private $start; |
|
33 | + private $start; |
|
34 | 34 | |
35 | - private $end; |
|
35 | + private $end; |
|
36 | 36 | |
37 | - private $stack; |
|
37 | + private $stack; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $sql |
|
41 | - * @param array $params |
|
42 | - * @param int $start |
|
43 | - */ |
|
44 | - public function __construct($sql, $params, $start, array $stack) { |
|
45 | - $this->sql = $sql; |
|
46 | - $this->params = $params; |
|
47 | - $this->start = $start; |
|
48 | - $this->stack = $stack; |
|
49 | - } |
|
39 | + /** |
|
40 | + * @param string $sql |
|
41 | + * @param array $params |
|
42 | + * @param int $start |
|
43 | + */ |
|
44 | + public function __construct($sql, $params, $start, array $stack) { |
|
45 | + $this->sql = $sql; |
|
46 | + $this->params = $params; |
|
47 | + $this->start = $start; |
|
48 | + $this->stack = $stack; |
|
49 | + } |
|
50 | 50 | |
51 | - public function end($time) { |
|
52 | - $this->end = $time; |
|
53 | - } |
|
51 | + public function end($time) { |
|
52 | + $this->end = $time; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getParams() { |
|
59 | - return $this->params; |
|
60 | - } |
|
55 | + /** |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getParams() { |
|
59 | + return $this->params; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getSql() { |
|
66 | - return $this->sql; |
|
67 | - } |
|
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getSql() { |
|
66 | + return $this->sql; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @return float |
|
71 | - */ |
|
72 | - public function getStart() { |
|
73 | - return $this->start; |
|
74 | - } |
|
69 | + /** |
|
70 | + * @return float |
|
71 | + */ |
|
72 | + public function getStart() { |
|
73 | + return $this->start; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @return float |
|
78 | - */ |
|
79 | - public function getDuration() { |
|
80 | - return $this->end - $this->start; |
|
81 | - } |
|
76 | + /** |
|
77 | + * @return float |
|
78 | + */ |
|
79 | + public function getDuration() { |
|
80 | + return $this->end - $this->start; |
|
81 | + } |
|
82 | 82 | |
83 | - public function getStartTime() { |
|
84 | - return $this->start; |
|
85 | - } |
|
83 | + public function getStartTime() { |
|
84 | + return $this->start; |
|
85 | + } |
|
86 | 86 | |
87 | - public function getStacktrace() { |
|
88 | - return $this->stack; |
|
89 | - } |
|
87 | + public function getStacktrace() { |
|
88 | + return $this->stack; |
|
89 | + } |
|
90 | 90 | } |