@@ -31,33 +31,33 @@ |
||
31 | 31 | |
32 | 32 | class EMailProvider implements IProvider { |
33 | 33 | |
34 | - /** @var IActionFactory */ |
|
35 | - private $actionFactory; |
|
36 | - |
|
37 | - /** @var IURLGenerator */ |
|
38 | - private $urlGenerator; |
|
39 | - |
|
40 | - /** |
|
41 | - * @param IActionFactory $actionFactory |
|
42 | - * @param IURLGenerator $urlGenerator |
|
43 | - */ |
|
44 | - public function __construct(IActionFactory $actionFactory, IURLGenerator $urlGenerator) { |
|
45 | - $this->actionFactory = $actionFactory; |
|
46 | - $this->urlGenerator = $urlGenerator; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @param IEntry $entry |
|
51 | - */ |
|
52 | - public function process(IEntry $entry) { |
|
53 | - $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); |
|
54 | - foreach ($entry->getEMailAddresses() as $address) { |
|
55 | - if (empty($address)) { |
|
56 | - // Skip |
|
57 | - continue; |
|
58 | - } |
|
59 | - $action = $this->actionFactory->newEMailAction($iconUrl, $address, $address); |
|
60 | - $entry->addAction($action); |
|
61 | - } |
|
62 | - } |
|
34 | + /** @var IActionFactory */ |
|
35 | + private $actionFactory; |
|
36 | + |
|
37 | + /** @var IURLGenerator */ |
|
38 | + private $urlGenerator; |
|
39 | + |
|
40 | + /** |
|
41 | + * @param IActionFactory $actionFactory |
|
42 | + * @param IURLGenerator $urlGenerator |
|
43 | + */ |
|
44 | + public function __construct(IActionFactory $actionFactory, IURLGenerator $urlGenerator) { |
|
45 | + $this->actionFactory = $actionFactory; |
|
46 | + $this->urlGenerator = $urlGenerator; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @param IEntry $entry |
|
51 | + */ |
|
52 | + public function process(IEntry $entry) { |
|
53 | + $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); |
|
54 | + foreach ($entry->getEMailAddresses() as $address) { |
|
55 | + if (empty($address)) { |
|
56 | + // Skip |
|
57 | + continue; |
|
58 | + } |
|
59 | + $action = $this->actionFactory->newEMailAction($iconUrl, $address, $address); |
|
60 | + $entry->addAction($action); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @package OC\AppFramework\Middleware\Security\Exceptions |
33 | 33 | */ |
34 | 34 | class StrictCookieMissingException extends SecurityException { |
35 | - public function __construct() { |
|
36 | - parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | - } |
|
35 | + public function __construct() { |
|
36 | + parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | + } |
|
38 | 38 | } |
@@ -29,40 +29,40 @@ |
||
29 | 29 | |
30 | 30 | class FedAuth extends AbstractBasic { |
31 | 31 | |
32 | - /** @var DbHandler */ |
|
33 | - private $db; |
|
32 | + /** @var DbHandler */ |
|
33 | + private $db; |
|
34 | 34 | |
35 | - /** |
|
36 | - * FedAuth constructor. |
|
37 | - * |
|
38 | - * @param DbHandler $db |
|
39 | - */ |
|
40 | - public function __construct(DbHandler $db) { |
|
41 | - $this->db = $db; |
|
42 | - $this->principalPrefix = 'principals/system/'; |
|
35 | + /** |
|
36 | + * FedAuth constructor. |
|
37 | + * |
|
38 | + * @param DbHandler $db |
|
39 | + */ |
|
40 | + public function __construct(DbHandler $db) { |
|
41 | + $this->db = $db; |
|
42 | + $this->principalPrefix = 'principals/system/'; |
|
43 | 43 | |
44 | - // setup realm |
|
45 | - $defaults = new \OCP\Defaults(); |
|
46 | - $this->realm = $defaults->getName(); |
|
47 | - } |
|
44 | + // setup realm |
|
45 | + $defaults = new \OCP\Defaults(); |
|
46 | + $this->realm = $defaults->getName(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Validates a username and password |
|
51 | - * |
|
52 | - * This method should return true or false depending on if login |
|
53 | - * succeeded. |
|
54 | - * |
|
55 | - * @param string $username |
|
56 | - * @param string $password |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - protected function validateUserPass($username, $password) { |
|
60 | - return $this->db->auth($username, $password); |
|
61 | - } |
|
49 | + /** |
|
50 | + * Validates a username and password |
|
51 | + * |
|
52 | + * This method should return true or false depending on if login |
|
53 | + * succeeded. |
|
54 | + * |
|
55 | + * @param string $username |
|
56 | + * @param string $password |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + protected function validateUserPass($username, $password) { |
|
60 | + return $this->db->auth($username, $password); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @inheritdoc |
|
65 | - */ |
|
66 | - public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
67 | - } |
|
63 | + /** |
|
64 | + * @inheritdoc |
|
65 | + */ |
|
66 | + public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
67 | + } |
|
68 | 68 | } |
@@ -61,8 +61,7 @@ |
||
61 | 61 | $fn = $this->l10n->getPluralFormFunction(); |
62 | 62 | $id = $fn($this->count); |
63 | 63 | $text = $translations[$this->text][$id]; |
64 | - } |
|
65 | - else{ |
|
64 | + } else{ |
|
66 | 65 | $text = $translations[$this->text]; |
67 | 66 | } |
68 | 67 | } |
@@ -29,59 +29,59 @@ |
||
29 | 29 | namespace OC\L10N; |
30 | 30 | |
31 | 31 | class L10NString implements \JsonSerializable { |
32 | - /** @var \OC\L10N\L10N */ |
|
33 | - protected $l10n; |
|
32 | + /** @var \OC\L10N\L10N */ |
|
33 | + protected $l10n; |
|
34 | 34 | |
35 | - /** @var string */ |
|
36 | - protected $text; |
|
35 | + /** @var string */ |
|
36 | + protected $text; |
|
37 | 37 | |
38 | - /** @var array */ |
|
39 | - protected $parameters; |
|
38 | + /** @var array */ |
|
39 | + protected $parameters; |
|
40 | 40 | |
41 | - /** @var integer */ |
|
42 | - protected $count; |
|
41 | + /** @var integer */ |
|
42 | + protected $count; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param \OC\L10N\L10N $l10n |
|
46 | - * @param string|string[] $text |
|
47 | - * @param array $parameters |
|
48 | - * @param int $count |
|
49 | - */ |
|
50 | - public function __construct(\OC\L10N\L10N $l10n, $text, $parameters, $count = 1) { |
|
51 | - $this->l10n = $l10n; |
|
52 | - $this->text = $text; |
|
53 | - $this->parameters = $parameters; |
|
54 | - $this->count = $count; |
|
55 | - } |
|
44 | + /** |
|
45 | + * @param \OC\L10N\L10N $l10n |
|
46 | + * @param string|string[] $text |
|
47 | + * @param array $parameters |
|
48 | + * @param int $count |
|
49 | + */ |
|
50 | + public function __construct(\OC\L10N\L10N $l10n, $text, $parameters, $count = 1) { |
|
51 | + $this->l10n = $l10n; |
|
52 | + $this->text = $text; |
|
53 | + $this->parameters = $parameters; |
|
54 | + $this->count = $count; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function __toString() { |
|
61 | - $translations = $this->l10n->getTranslations(); |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function __toString() { |
|
61 | + $translations = $this->l10n->getTranslations(); |
|
62 | 62 | |
63 | - $text = $this->text; |
|
64 | - if(array_key_exists($this->text, $translations)) { |
|
65 | - if(is_array($translations[$this->text])) { |
|
66 | - $fn = $this->l10n->getPluralFormFunction(); |
|
67 | - $id = $fn($this->count); |
|
68 | - $text = $translations[$this->text][$id]; |
|
69 | - } |
|
70 | - else{ |
|
71 | - $text = $translations[$this->text]; |
|
72 | - } |
|
73 | - } |
|
63 | + $text = $this->text; |
|
64 | + if(array_key_exists($this->text, $translations)) { |
|
65 | + if(is_array($translations[$this->text])) { |
|
66 | + $fn = $this->l10n->getPluralFormFunction(); |
|
67 | + $id = $fn($this->count); |
|
68 | + $text = $translations[$this->text][$id]; |
|
69 | + } |
|
70 | + else{ |
|
71 | + $text = $translations[$this->text]; |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - // Replace %n first (won't interfere with vsprintf) |
|
76 | - $text = str_replace('%n', (string)$this->count, $text); |
|
77 | - return vsprintf($text, $this->parameters); |
|
78 | - } |
|
75 | + // Replace %n first (won't interfere with vsprintf) |
|
76 | + $text = str_replace('%n', (string)$this->count, $text); |
|
77 | + return vsprintf($text, $this->parameters); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function jsonSerialize() { |
|
85 | - return $this->__toString(); |
|
86 | - } |
|
81 | + /** |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function jsonSerialize() { |
|
85 | + return $this->__toString(); |
|
86 | + } |
|
87 | 87 | } |
@@ -56,19 +56,19 @@ |
||
56 | 56 | $translations = $this->l10n->getTranslations(); |
57 | 57 | |
58 | 58 | $text = $this->text; |
59 | - if(array_key_exists($this->text, $translations)) { |
|
60 | - if(is_array($translations[$this->text])) { |
|
59 | + if (array_key_exists($this->text, $translations)) { |
|
60 | + if (is_array($translations[$this->text])) { |
|
61 | 61 | $fn = $this->l10n->getPluralFormFunction(); |
62 | 62 | $id = $fn($this->count); |
63 | 63 | $text = $translations[$this->text][$id]; |
64 | 64 | } |
65 | - else{ |
|
65 | + else { |
|
66 | 66 | $text = $translations[$this->text]; |
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
70 | 70 | // Replace %n first (won't interfere with vsprintf) |
71 | - $text = str_replace('%n', (string)$this->count, $text); |
|
71 | + $text = str_replace('%n', (string) $this->count, $text); |
|
72 | 72 | return vsprintf($text, $this->parameters); |
73 | 73 | } |
74 | 74 |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | public function castColumn($column, $type) { |
148 | 148 | if ($type === IQueryBuilder::PARAM_STR) { |
149 | 149 | $column = $this->helper->quoteColumnName($column); |
150 | - return new QueryFunction('to_char(' . $column . ')'); |
|
150 | + return new QueryFunction('to_char('.$column.')'); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | return parent::castColumn($column, $type); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * @inheritdoc |
158 | 158 | */ |
159 | 159 | public function like($x, $y, $type = null) { |
160 | - return parent::like($x, $y, $type) . " ESCAPE '\\'"; |
|
160 | + return parent::like($x, $y, $type)." ESCAPE '\\'"; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -166,6 +166,6 @@ discard block |
||
166 | 166 | public function iLike($x, $y, $type = null) { |
167 | 167 | $x = $this->helper->quoteColumnName($x); |
168 | 168 | $y = $this->helper->quoteColumnName($y); |
169 | - return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')'); |
|
169 | + return new QueryFunction('REGEXP_LIKE('.$x.', \'^\' || REPLACE(REPLACE('.$y.', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')'); |
|
170 | 170 | } |
171 | 171 | } |
@@ -33,161 +33,161 @@ |
||
33 | 33 | |
34 | 34 | class OCIExpressionBuilder extends ExpressionBuilder { |
35 | 35 | |
36 | - /** |
|
37 | - * @param mixed $column |
|
38 | - * @param mixed|null $type |
|
39 | - * @return array|IQueryFunction|string |
|
40 | - */ |
|
41 | - protected function prepareColumn($column, $type) { |
|
42 | - if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) { |
|
43 | - $column = $this->castColumn($column, $type); |
|
44 | - } else { |
|
45 | - $column = $this->helper->quoteColumnNames($column); |
|
46 | - } |
|
47 | - return $column; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @inheritdoc |
|
52 | - */ |
|
53 | - public function comparison($x, $operator, $y, $type = null) { |
|
54 | - $x = $this->prepareColumn($x, $type); |
|
55 | - $y = $this->prepareColumn($y, $type); |
|
56 | - |
|
57 | - return $this->expressionBuilder->comparison($x, $operator, $y); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @inheritdoc |
|
62 | - */ |
|
63 | - public function eq($x, $y, $type = null) { |
|
64 | - $x = $this->prepareColumn($x, $type); |
|
65 | - $y = $this->prepareColumn($y, $type); |
|
66 | - |
|
67 | - return $this->expressionBuilder->eq($x, $y); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @inheritdoc |
|
72 | - */ |
|
73 | - public function neq($x, $y, $type = null) { |
|
74 | - $x = $this->prepareColumn($x, $type); |
|
75 | - $y = $this->prepareColumn($y, $type); |
|
76 | - |
|
77 | - return $this->expressionBuilder->neq($x, $y); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @inheritdoc |
|
82 | - */ |
|
83 | - public function lt($x, $y, $type = null) { |
|
84 | - $x = $this->prepareColumn($x, $type); |
|
85 | - $y = $this->prepareColumn($y, $type); |
|
86 | - |
|
87 | - return $this->expressionBuilder->lt($x, $y); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @inheritdoc |
|
92 | - */ |
|
93 | - public function lte($x, $y, $type = null) { |
|
94 | - $x = $this->prepareColumn($x, $type); |
|
95 | - $y = $this->prepareColumn($y, $type); |
|
96 | - |
|
97 | - return $this->expressionBuilder->lte($x, $y); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @inheritdoc |
|
102 | - */ |
|
103 | - public function gt($x, $y, $type = null) { |
|
104 | - $x = $this->prepareColumn($x, $type); |
|
105 | - $y = $this->prepareColumn($y, $type); |
|
106 | - |
|
107 | - return $this->expressionBuilder->gt($x, $y); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @inheritdoc |
|
112 | - */ |
|
113 | - public function gte($x, $y, $type = null) { |
|
114 | - $x = $this->prepareColumn($x, $type); |
|
115 | - $y = $this->prepareColumn($y, $type); |
|
116 | - |
|
117 | - return $this->expressionBuilder->gte($x, $y); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @inheritdoc |
|
122 | - */ |
|
123 | - public function in($x, $y, $type = null) { |
|
124 | - $x = $this->prepareColumn($x, $type); |
|
125 | - $y = $this->prepareColumn($y, $type); |
|
126 | - |
|
127 | - return $this->expressionBuilder->in($x, $y); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @inheritdoc |
|
132 | - */ |
|
133 | - public function notIn($x, $y, $type = null) { |
|
134 | - $x = $this->prepareColumn($x, $type); |
|
135 | - $y = $this->prepareColumn($y, $type); |
|
136 | - |
|
137 | - return $this->expressionBuilder->notIn($x, $y); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Creates a $x = '' statement, because Oracle needs a different check |
|
142 | - * |
|
143 | - * @param string $x The field in string format to be inspected by the comparison. |
|
144 | - * @return string |
|
145 | - * @since 13.0.0 |
|
146 | - */ |
|
147 | - public function emptyString($x) { |
|
148 | - return $this->isNull($x); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Creates a `$x <> ''` statement, because Oracle needs a different check |
|
153 | - * |
|
154 | - * @param string $x The field in string format to be inspected by the comparison. |
|
155 | - * @return string |
|
156 | - * @since 13.0.0 |
|
157 | - */ |
|
158 | - public function nonEmptyString($x) { |
|
159 | - return $this->isNotNull($x); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Returns a IQueryFunction that casts the column to the given type |
|
164 | - * |
|
165 | - * @param string $column |
|
166 | - * @param mixed $type One of IQueryBuilder::PARAM_* |
|
167 | - * @return IQueryFunction |
|
168 | - */ |
|
169 | - public function castColumn($column, $type) { |
|
170 | - if ($type === IQueryBuilder::PARAM_STR) { |
|
171 | - $column = $this->helper->quoteColumnName($column); |
|
172 | - return new QueryFunction('to_char(' . $column . ')'); |
|
173 | - } |
|
174 | - |
|
175 | - return parent::castColumn($column, $type); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @inheritdoc |
|
180 | - */ |
|
181 | - public function like($x, $y, $type = null) { |
|
182 | - return parent::like($x, $y, $type) . " ESCAPE '\\'"; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @inheritdoc |
|
187 | - */ |
|
188 | - public function iLike($x, $y, $type = null) { |
|
189 | - $x = $this->helper->quoteColumnName($x); |
|
190 | - $y = $this->helper->quoteColumnName($y); |
|
191 | - return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')'); |
|
192 | - } |
|
36 | + /** |
|
37 | + * @param mixed $column |
|
38 | + * @param mixed|null $type |
|
39 | + * @return array|IQueryFunction|string |
|
40 | + */ |
|
41 | + protected function prepareColumn($column, $type) { |
|
42 | + if ($type === IQueryBuilder::PARAM_STR && !is_array($column) && !($column instanceof IParameter) && !($column instanceof ILiteral)) { |
|
43 | + $column = $this->castColumn($column, $type); |
|
44 | + } else { |
|
45 | + $column = $this->helper->quoteColumnNames($column); |
|
46 | + } |
|
47 | + return $column; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @inheritdoc |
|
52 | + */ |
|
53 | + public function comparison($x, $operator, $y, $type = null) { |
|
54 | + $x = $this->prepareColumn($x, $type); |
|
55 | + $y = $this->prepareColumn($y, $type); |
|
56 | + |
|
57 | + return $this->expressionBuilder->comparison($x, $operator, $y); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @inheritdoc |
|
62 | + */ |
|
63 | + public function eq($x, $y, $type = null) { |
|
64 | + $x = $this->prepareColumn($x, $type); |
|
65 | + $y = $this->prepareColumn($y, $type); |
|
66 | + |
|
67 | + return $this->expressionBuilder->eq($x, $y); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @inheritdoc |
|
72 | + */ |
|
73 | + public function neq($x, $y, $type = null) { |
|
74 | + $x = $this->prepareColumn($x, $type); |
|
75 | + $y = $this->prepareColumn($y, $type); |
|
76 | + |
|
77 | + return $this->expressionBuilder->neq($x, $y); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @inheritdoc |
|
82 | + */ |
|
83 | + public function lt($x, $y, $type = null) { |
|
84 | + $x = $this->prepareColumn($x, $type); |
|
85 | + $y = $this->prepareColumn($y, $type); |
|
86 | + |
|
87 | + return $this->expressionBuilder->lt($x, $y); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @inheritdoc |
|
92 | + */ |
|
93 | + public function lte($x, $y, $type = null) { |
|
94 | + $x = $this->prepareColumn($x, $type); |
|
95 | + $y = $this->prepareColumn($y, $type); |
|
96 | + |
|
97 | + return $this->expressionBuilder->lte($x, $y); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @inheritdoc |
|
102 | + */ |
|
103 | + public function gt($x, $y, $type = null) { |
|
104 | + $x = $this->prepareColumn($x, $type); |
|
105 | + $y = $this->prepareColumn($y, $type); |
|
106 | + |
|
107 | + return $this->expressionBuilder->gt($x, $y); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @inheritdoc |
|
112 | + */ |
|
113 | + public function gte($x, $y, $type = null) { |
|
114 | + $x = $this->prepareColumn($x, $type); |
|
115 | + $y = $this->prepareColumn($y, $type); |
|
116 | + |
|
117 | + return $this->expressionBuilder->gte($x, $y); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @inheritdoc |
|
122 | + */ |
|
123 | + public function in($x, $y, $type = null) { |
|
124 | + $x = $this->prepareColumn($x, $type); |
|
125 | + $y = $this->prepareColumn($y, $type); |
|
126 | + |
|
127 | + return $this->expressionBuilder->in($x, $y); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @inheritdoc |
|
132 | + */ |
|
133 | + public function notIn($x, $y, $type = null) { |
|
134 | + $x = $this->prepareColumn($x, $type); |
|
135 | + $y = $this->prepareColumn($y, $type); |
|
136 | + |
|
137 | + return $this->expressionBuilder->notIn($x, $y); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Creates a $x = '' statement, because Oracle needs a different check |
|
142 | + * |
|
143 | + * @param string $x The field in string format to be inspected by the comparison. |
|
144 | + * @return string |
|
145 | + * @since 13.0.0 |
|
146 | + */ |
|
147 | + public function emptyString($x) { |
|
148 | + return $this->isNull($x); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Creates a `$x <> ''` statement, because Oracle needs a different check |
|
153 | + * |
|
154 | + * @param string $x The field in string format to be inspected by the comparison. |
|
155 | + * @return string |
|
156 | + * @since 13.0.0 |
|
157 | + */ |
|
158 | + public function nonEmptyString($x) { |
|
159 | + return $this->isNotNull($x); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Returns a IQueryFunction that casts the column to the given type |
|
164 | + * |
|
165 | + * @param string $column |
|
166 | + * @param mixed $type One of IQueryBuilder::PARAM_* |
|
167 | + * @return IQueryFunction |
|
168 | + */ |
|
169 | + public function castColumn($column, $type) { |
|
170 | + if ($type === IQueryBuilder::PARAM_STR) { |
|
171 | + $column = $this->helper->quoteColumnName($column); |
|
172 | + return new QueryFunction('to_char(' . $column . ')'); |
|
173 | + } |
|
174 | + |
|
175 | + return parent::castColumn($column, $type); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @inheritdoc |
|
180 | + */ |
|
181 | + public function like($x, $y, $type = null) { |
|
182 | + return parent::like($x, $y, $type) . " ESCAPE '\\'"; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @inheritdoc |
|
187 | + */ |
|
188 | + public function iLike($x, $y, $type = null) { |
|
189 | + $x = $this->helper->quoteColumnName($x); |
|
190 | + $y = $this->helper->quoteColumnName($y); |
|
191 | + return new QueryFunction('REGEXP_LIKE(' . $x . ', \'^\' || REPLACE(REPLACE(' . $y . ', \'%\', \'.*\'), \'_\', \'.\') || \'$\', \'i\')'); |
|
192 | + } |
|
193 | 193 | } |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | |
234 | 234 | $schemaManager = new \OC\DB\MDB2SchemaManager($toDB); |
235 | 235 | $apps = $input->getOption('all-apps') ? \OC_App::getAllApps() : \OC_App::getEnabledApps(); |
236 | - foreach($apps as $app) { |
|
236 | + foreach ($apps as $app) { |
|
237 | 237 | if (file_exists(\OC_App::getAppPath($app).'/appinfo/database.xml')) { |
238 | 238 | $schemaManager->createDbFromStructure(\OC_App::getAppPath($app).'/appinfo/database.xml'); |
239 | 239 | } else { |
@@ -269,13 +269,13 @@ discard block |
||
269 | 269 | if (!empty($toTables)) { |
270 | 270 | $output->writeln('<info>Clearing schema in new database</info>'); |
271 | 271 | } |
272 | - foreach($toTables as $table) { |
|
272 | + foreach ($toTables as $table) { |
|
273 | 273 | $db->getSchemaManager()->dropTable($table); |
274 | 274 | } |
275 | 275 | } |
276 | 276 | |
277 | 277 | protected function getTables(Connection $db) { |
278 | - $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
278 | + $filterExpression = '/^'.preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')).'/'; |
|
279 | 279 | $db->getConfiguration()-> |
280 | 280 | setFilterSchemaAssetsExpression($filterExpression); |
281 | 281 | return $db->getSchemaManager()->listTableNames(); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * @suppress SqlInjectionChecker |
291 | 291 | */ |
292 | 292 | protected function copyTable(Connection $fromDB, Connection $toDB, Table $table, InputInterface $input, OutputInterface $output) { |
293 | - if ($table->getName() === $toDB->getPrefix() . 'migrations') { |
|
293 | + if ($table->getName() === $toDB->getPrefix().'migrations') { |
|
294 | 294 | $output->writeln('<comment>Skipping migrations table because it was already filled by running the migrations</comment>'); |
295 | 295 | return; |
296 | 296 | } |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | $count = $result->fetchColumn(); |
306 | 306 | $result->closeCursor(); |
307 | 307 | |
308 | - $numChunks = ceil($count/$chunkSize); |
|
308 | + $numChunks = ceil($count / $chunkSize); |
|
309 | 309 | if ($numChunks > 1) { |
310 | - $output->writeln('chunked query, ' . $numChunks . ' chunks'); |
|
310 | + $output->writeln('chunked query, '.$numChunks.' chunks'); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | $progress = new ProgressBar($output, $count); |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | |
395 | 395 | try { |
396 | 396 | // copy table rows |
397 | - foreach($tables as $table) { |
|
397 | + foreach ($tables as $table) { |
|
398 | 398 | $output->writeln($table); |
399 | 399 | $this->copyTable($fromDB, $toDB, $schema->getTable($table), $input, $output); |
400 | 400 | } |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | } |
405 | 405 | // save new database config |
406 | 406 | $this->saveDBInfo($input); |
407 | - } catch(\Exception $e) { |
|
407 | + } catch (\Exception $e) { |
|
408 | 408 | $this->config->setSystemValue('maintenance', false); |
409 | 409 | throw $e; |
410 | 410 | } |
@@ -51,409 +51,409 @@ |
||
51 | 51 | use Symfony\Component\Console\Question\Question; |
52 | 52 | |
53 | 53 | class ConvertType extends Command implements CompletionAwareInterface { |
54 | - /** |
|
55 | - * @var \OCP\IConfig |
|
56 | - */ |
|
57 | - protected $config; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var \OC\DB\ConnectionFactory |
|
61 | - */ |
|
62 | - protected $connectionFactory; |
|
63 | - |
|
64 | - /** @var array */ |
|
65 | - protected $columnTypes; |
|
66 | - |
|
67 | - /** |
|
68 | - * @param \OCP\IConfig $config |
|
69 | - * @param \OC\DB\ConnectionFactory $connectionFactory |
|
70 | - */ |
|
71 | - public function __construct(IConfig $config, ConnectionFactory $connectionFactory) { |
|
72 | - $this->config = $config; |
|
73 | - $this->connectionFactory = $connectionFactory; |
|
74 | - parent::__construct(); |
|
75 | - } |
|
76 | - |
|
77 | - protected function configure() { |
|
78 | - $this |
|
79 | - ->setName('db:convert-type') |
|
80 | - ->setDescription('Convert the Nextcloud database to the newly configured one') |
|
81 | - ->addArgument( |
|
82 | - 'type', |
|
83 | - InputArgument::REQUIRED, |
|
84 | - 'the type of the database to convert to' |
|
85 | - ) |
|
86 | - ->addArgument( |
|
87 | - 'username', |
|
88 | - InputArgument::REQUIRED, |
|
89 | - 'the username of the database to convert to' |
|
90 | - ) |
|
91 | - ->addArgument( |
|
92 | - 'hostname', |
|
93 | - InputArgument::REQUIRED, |
|
94 | - 'the hostname of the database to convert to' |
|
95 | - ) |
|
96 | - ->addArgument( |
|
97 | - 'database', |
|
98 | - InputArgument::REQUIRED, |
|
99 | - 'the name of the database to convert to' |
|
100 | - ) |
|
101 | - ->addOption( |
|
102 | - 'port', |
|
103 | - null, |
|
104 | - InputOption::VALUE_REQUIRED, |
|
105 | - 'the port of the database to convert to' |
|
106 | - ) |
|
107 | - ->addOption( |
|
108 | - 'password', |
|
109 | - null, |
|
110 | - InputOption::VALUE_REQUIRED, |
|
111 | - 'the password of the database to convert to. Will be asked when not specified. Can also be passed via stdin.' |
|
112 | - ) |
|
113 | - ->addOption( |
|
114 | - 'clear-schema', |
|
115 | - null, |
|
116 | - InputOption::VALUE_NONE, |
|
117 | - 'remove all tables from the destination database' |
|
118 | - ) |
|
119 | - ->addOption( |
|
120 | - 'all-apps', |
|
121 | - null, |
|
122 | - InputOption::VALUE_NONE, |
|
123 | - 'whether to create schema for all apps instead of only installed apps' |
|
124 | - ) |
|
125 | - ->addOption( |
|
126 | - 'chunk-size', |
|
127 | - null, |
|
128 | - InputOption::VALUE_REQUIRED, |
|
129 | - 'the maximum number of database rows to handle in a single query, bigger tables will be handled in chunks of this size. Lower this if the process runs out of memory during conversion.', |
|
130 | - 1000 |
|
131 | - ) |
|
132 | - ; |
|
133 | - } |
|
134 | - |
|
135 | - protected function validateInput(InputInterface $input, OutputInterface $output) { |
|
136 | - $type = $this->connectionFactory->normalizeType($input->getArgument('type')); |
|
137 | - if ($type === 'sqlite3') { |
|
138 | - throw new \InvalidArgumentException( |
|
139 | - 'Converting to SQLite (sqlite3) is currently not supported.' |
|
140 | - ); |
|
141 | - } |
|
142 | - if ($type === $this->config->getSystemValue('dbtype', '')) { |
|
143 | - throw new \InvalidArgumentException(sprintf( |
|
144 | - 'Can not convert from %1$s to %1$s.', |
|
145 | - $type |
|
146 | - )); |
|
147 | - } |
|
148 | - if ($type === 'oci' && $input->getOption('clear-schema')) { |
|
149 | - // Doctrine unconditionally tries (at least in version 2.3) |
|
150 | - // to drop sequence triggers when dropping a table, even though |
|
151 | - // such triggers may not exist. This results in errors like |
|
152 | - // "ORA-04080: trigger 'OC_STORAGES_AI_PK' does not exist". |
|
153 | - throw new \InvalidArgumentException( |
|
154 | - 'The --clear-schema option is not supported when converting to Oracle (oci).' |
|
155 | - ); |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - protected function readPassword(InputInterface $input, OutputInterface $output) { |
|
160 | - // Explicitly specified password |
|
161 | - if ($input->getOption('password')) { |
|
162 | - return; |
|
163 | - } |
|
164 | - |
|
165 | - // Read from stdin. stream_set_blocking is used to prevent blocking |
|
166 | - // when nothing is passed via stdin. |
|
167 | - stream_set_blocking(STDIN, 0); |
|
168 | - $password = file_get_contents('php://stdin'); |
|
169 | - stream_set_blocking(STDIN, 1); |
|
170 | - if (trim($password) !== '') { |
|
171 | - $input->setOption('password', $password); |
|
172 | - return; |
|
173 | - } |
|
174 | - |
|
175 | - // Read password by interacting |
|
176 | - if ($input->isInteractive()) { |
|
177 | - /** @var QuestionHelper $helper */ |
|
178 | - $helper = $this->getHelper('question'); |
|
179 | - $question = new Question('What is the database password?'); |
|
180 | - $question->setHidden(true); |
|
181 | - $question->setHiddenFallback(false); |
|
182 | - $password = $helper->ask($input, $output, $question); |
|
183 | - $input->setOption('password', $password); |
|
184 | - return; |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
189 | - $this->validateInput($input, $output); |
|
190 | - $this->readPassword($input, $output); |
|
191 | - |
|
192 | - $fromDB = \OC::$server->getDatabaseConnection(); |
|
193 | - $toDB = $this->getToDBConnection($input, $output); |
|
194 | - |
|
195 | - if ($input->getOption('clear-schema')) { |
|
196 | - $this->clearSchema($toDB, $input, $output); |
|
197 | - } |
|
198 | - |
|
199 | - $this->createSchema($fromDB, $toDB, $input, $output); |
|
200 | - |
|
201 | - $toTables = $this->getTables($toDB); |
|
202 | - $fromTables = $this->getTables($fromDB); |
|
203 | - |
|
204 | - // warn/fail if there are more tables in 'from' database |
|
205 | - $extraFromTables = array_diff($fromTables, $toTables); |
|
206 | - if (!empty($extraFromTables)) { |
|
207 | - $output->writeln('<comment>The following tables will not be converted:</comment>'); |
|
208 | - $output->writeln($extraFromTables); |
|
209 | - if (!$input->getOption('all-apps')) { |
|
210 | - $output->writeln('<comment>Please note that tables belonging to available but currently not installed apps</comment>'); |
|
211 | - $output->writeln('<comment>can be included by specifying the --all-apps option.</comment>'); |
|
212 | - } |
|
213 | - |
|
214 | - /** @var QuestionHelper $helper */ |
|
215 | - $helper = $this->getHelper('question'); |
|
216 | - $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false); |
|
217 | - |
|
218 | - if (!$helper->ask($input, $output, $question)) { |
|
219 | - return; |
|
220 | - } |
|
221 | - } |
|
222 | - $intersectingTables = array_intersect($toTables, $fromTables); |
|
223 | - $this->convertDB($fromDB, $toDB, $intersectingTables, $input, $output); |
|
224 | - } |
|
225 | - |
|
226 | - protected function createSchema(Connection $fromDB, Connection $toDB, InputInterface $input, OutputInterface $output) { |
|
227 | - $output->writeln('<info>Creating schema in new database</info>'); |
|
228 | - |
|
229 | - $fromMS = new MigrationService('core', $fromDB); |
|
230 | - $currentMigration = $fromMS->getMigration('current'); |
|
231 | - if ($currentMigration !== '0') { |
|
232 | - $toMS = new MigrationService('core', $toDB); |
|
233 | - $toMS->migrate($currentMigration); |
|
234 | - } |
|
235 | - |
|
236 | - $schemaManager = new \OC\DB\MDB2SchemaManager($toDB); |
|
237 | - $apps = $input->getOption('all-apps') ? \OC_App::getAllApps() : \OC_App::getEnabledApps(); |
|
238 | - foreach($apps as $app) { |
|
239 | - if (file_exists(\OC_App::getAppPath($app).'/appinfo/database.xml')) { |
|
240 | - $schemaManager->createDbFromStructure(\OC_App::getAppPath($app).'/appinfo/database.xml'); |
|
241 | - } else { |
|
242 | - // Make sure autoloading works... |
|
243 | - \OC_App::loadApp($app); |
|
244 | - $fromMS = new MigrationService($app, $fromDB); |
|
245 | - $currentMigration = $fromMS->getMigration('current'); |
|
246 | - if ($currentMigration !== '0') { |
|
247 | - $toMS = new MigrationService($app, $toDB); |
|
248 | - $toMS->migrate($currentMigration, true); |
|
249 | - } |
|
250 | - } |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - protected function getToDBConnection(InputInterface $input, OutputInterface $output) { |
|
255 | - $type = $input->getArgument('type'); |
|
256 | - $connectionParams = $this->connectionFactory->createConnectionParams(); |
|
257 | - $connectionParams = array_merge($connectionParams, [ |
|
258 | - 'host' => $input->getArgument('hostname'), |
|
259 | - 'user' => $input->getArgument('username'), |
|
260 | - 'password' => $input->getOption('password'), |
|
261 | - 'dbname' => $input->getArgument('database'), |
|
262 | - ]); |
|
263 | - if ($input->getOption('port')) { |
|
264 | - $connectionParams['port'] = $input->getOption('port'); |
|
265 | - } |
|
266 | - return $this->connectionFactory->getConnection($type, $connectionParams); |
|
267 | - } |
|
268 | - |
|
269 | - protected function clearSchema(Connection $db, InputInterface $input, OutputInterface $output) { |
|
270 | - $toTables = $this->getTables($db); |
|
271 | - if (!empty($toTables)) { |
|
272 | - $output->writeln('<info>Clearing schema in new database</info>'); |
|
273 | - } |
|
274 | - foreach($toTables as $table) { |
|
275 | - $db->getSchemaManager()->dropTable($table); |
|
276 | - } |
|
277 | - } |
|
278 | - |
|
279 | - protected function getTables(Connection $db) { |
|
280 | - $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
281 | - $db->getConfiguration()-> |
|
282 | - setFilterSchemaAssetsExpression($filterExpression); |
|
283 | - return $db->getSchemaManager()->listTableNames(); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @param Connection $fromDB |
|
288 | - * @param Connection $toDB |
|
289 | - * @param Table $table |
|
290 | - * @param InputInterface $input |
|
291 | - * @param OutputInterface $output |
|
292 | - * @suppress SqlInjectionChecker |
|
293 | - */ |
|
294 | - protected function copyTable(Connection $fromDB, Connection $toDB, Table $table, InputInterface $input, OutputInterface $output) { |
|
295 | - if ($table->getName() === $toDB->getPrefix() . 'migrations') { |
|
296 | - $output->writeln('<comment>Skipping migrations table because it was already filled by running the migrations</comment>'); |
|
297 | - return; |
|
298 | - } |
|
299 | - |
|
300 | - $chunkSize = $input->getOption('chunk-size'); |
|
301 | - |
|
302 | - $query = $fromDB->getQueryBuilder(); |
|
303 | - $query->automaticTablePrefix(false); |
|
304 | - $query->select($query->func()->count('*', 'num_entries')) |
|
305 | - ->from($table->getName()); |
|
306 | - $result = $query->execute(); |
|
307 | - $count = $result->fetchColumn(); |
|
308 | - $result->closeCursor(); |
|
309 | - |
|
310 | - $numChunks = ceil($count/$chunkSize); |
|
311 | - if ($numChunks > 1) { |
|
312 | - $output->writeln('chunked query, ' . $numChunks . ' chunks'); |
|
313 | - } |
|
314 | - |
|
315 | - $progress = new ProgressBar($output, $count); |
|
316 | - $progress->start(); |
|
317 | - $redraw = $count > $chunkSize ? 100 : ($count > 100 ? 5 : 1); |
|
318 | - $progress->setRedrawFrequency($redraw); |
|
319 | - |
|
320 | - $query = $fromDB->getQueryBuilder(); |
|
321 | - $query->automaticTablePrefix(false); |
|
322 | - $query->select('*') |
|
323 | - ->from($table->getName()) |
|
324 | - ->setMaxResults($chunkSize); |
|
325 | - |
|
326 | - try { |
|
327 | - $orderColumns = $table->getPrimaryKeyColumns(); |
|
328 | - } catch (DBALException $e) { |
|
329 | - $orderColumns = []; |
|
330 | - foreach ($table->getColumns() as $column) { |
|
331 | - $orderColumns[] = $column->getName(); |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - foreach ($orderColumns as $column) { |
|
336 | - $query->addOrderBy($column); |
|
337 | - } |
|
338 | - |
|
339 | - $insertQuery = $toDB->getQueryBuilder(); |
|
340 | - $insertQuery->automaticTablePrefix(false); |
|
341 | - $insertQuery->insert($table->getName()); |
|
342 | - $parametersCreated = false; |
|
343 | - |
|
344 | - for ($chunk = 0; $chunk < $numChunks; $chunk++) { |
|
345 | - $query->setFirstResult($chunk * $chunkSize); |
|
346 | - |
|
347 | - $result = $query->execute(); |
|
348 | - |
|
349 | - while ($row = $result->fetch()) { |
|
350 | - $progress->advance(); |
|
351 | - if (!$parametersCreated) { |
|
352 | - foreach ($row as $key => $value) { |
|
353 | - $insertQuery->setValue($key, $insertQuery->createParameter($key)); |
|
354 | - } |
|
355 | - $parametersCreated = true; |
|
356 | - } |
|
357 | - |
|
358 | - foreach ($row as $key => $value) { |
|
359 | - $type = $this->getColumnType($table, $key); |
|
360 | - if ($type !== false) { |
|
361 | - $insertQuery->setParameter($key, $value, $type); |
|
362 | - } else { |
|
363 | - $insertQuery->setParameter($key, $value); |
|
364 | - } |
|
365 | - } |
|
366 | - $insertQuery->execute(); |
|
367 | - } |
|
368 | - $result->closeCursor(); |
|
369 | - } |
|
370 | - $progress->finish(); |
|
371 | - } |
|
372 | - |
|
373 | - protected function getColumnType(Table $table, $columnName) { |
|
374 | - $tableName = $table->getName(); |
|
375 | - if (isset($this->columnTypes[$tableName][$columnName])) { |
|
376 | - return $this->columnTypes[$tableName][$columnName]; |
|
377 | - } |
|
378 | - |
|
379 | - $type = $table->getColumn($columnName)->getType()->getName(); |
|
380 | - |
|
381 | - switch ($type) { |
|
382 | - case Type::BLOB: |
|
383 | - case Type::TEXT: |
|
384 | - $this->columnTypes[$tableName][$columnName] = IQueryBuilder::PARAM_LOB; |
|
385 | - break; |
|
386 | - default: |
|
387 | - $this->columnTypes[$tableName][$columnName] = false; |
|
388 | - } |
|
389 | - |
|
390 | - return $this->columnTypes[$tableName][$columnName]; |
|
391 | - } |
|
392 | - |
|
393 | - protected function convertDB(Connection $fromDB, Connection $toDB, array $tables, InputInterface $input, OutputInterface $output) { |
|
394 | - $this->config->setSystemValue('maintenance', true); |
|
395 | - $schema = $fromDB->createSchema(); |
|
396 | - |
|
397 | - try { |
|
398 | - // copy table rows |
|
399 | - foreach($tables as $table) { |
|
400 | - $output->writeln($table); |
|
401 | - $this->copyTable($fromDB, $toDB, $schema->getTable($table), $input, $output); |
|
402 | - } |
|
403 | - if ($input->getArgument('type') === 'pgsql') { |
|
404 | - $tools = new \OC\DB\PgSqlTools($this->config); |
|
405 | - $tools->resynchronizeDatabaseSequences($toDB); |
|
406 | - } |
|
407 | - // save new database config |
|
408 | - $this->saveDBInfo($input); |
|
409 | - } catch(\Exception $e) { |
|
410 | - $this->config->setSystemValue('maintenance', false); |
|
411 | - throw $e; |
|
412 | - } |
|
413 | - $this->config->setSystemValue('maintenance', false); |
|
414 | - } |
|
415 | - |
|
416 | - protected function saveDBInfo(InputInterface $input) { |
|
417 | - $type = $input->getArgument('type'); |
|
418 | - $username = $input->getArgument('username'); |
|
419 | - $dbHost = $input->getArgument('hostname'); |
|
420 | - $dbName = $input->getArgument('database'); |
|
421 | - $password = $input->getOption('password'); |
|
422 | - if ($input->getOption('port')) { |
|
423 | - $dbHost .= ':'.$input->getOption('port'); |
|
424 | - } |
|
425 | - |
|
426 | - $this->config->setSystemValues([ |
|
427 | - 'dbtype' => $type, |
|
428 | - 'dbname' => $dbName, |
|
429 | - 'dbhost' => $dbHost, |
|
430 | - 'dbuser' => $username, |
|
431 | - 'dbpassword' => $password, |
|
432 | - ]); |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * Return possible values for the named option |
|
437 | - * |
|
438 | - * @param string $optionName |
|
439 | - * @param CompletionContext $context |
|
440 | - * @return string[] |
|
441 | - */ |
|
442 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
443 | - return []; |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Return possible values for the named argument |
|
448 | - * |
|
449 | - * @param string $argumentName |
|
450 | - * @param CompletionContext $context |
|
451 | - * @return string[] |
|
452 | - */ |
|
453 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
454 | - if ($argumentName === 'type') { |
|
455 | - return ['mysql', 'oci', 'pgsql']; |
|
456 | - } |
|
457 | - return []; |
|
458 | - } |
|
54 | + /** |
|
55 | + * @var \OCP\IConfig |
|
56 | + */ |
|
57 | + protected $config; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var \OC\DB\ConnectionFactory |
|
61 | + */ |
|
62 | + protected $connectionFactory; |
|
63 | + |
|
64 | + /** @var array */ |
|
65 | + protected $columnTypes; |
|
66 | + |
|
67 | + /** |
|
68 | + * @param \OCP\IConfig $config |
|
69 | + * @param \OC\DB\ConnectionFactory $connectionFactory |
|
70 | + */ |
|
71 | + public function __construct(IConfig $config, ConnectionFactory $connectionFactory) { |
|
72 | + $this->config = $config; |
|
73 | + $this->connectionFactory = $connectionFactory; |
|
74 | + parent::__construct(); |
|
75 | + } |
|
76 | + |
|
77 | + protected function configure() { |
|
78 | + $this |
|
79 | + ->setName('db:convert-type') |
|
80 | + ->setDescription('Convert the Nextcloud database to the newly configured one') |
|
81 | + ->addArgument( |
|
82 | + 'type', |
|
83 | + InputArgument::REQUIRED, |
|
84 | + 'the type of the database to convert to' |
|
85 | + ) |
|
86 | + ->addArgument( |
|
87 | + 'username', |
|
88 | + InputArgument::REQUIRED, |
|
89 | + 'the username of the database to convert to' |
|
90 | + ) |
|
91 | + ->addArgument( |
|
92 | + 'hostname', |
|
93 | + InputArgument::REQUIRED, |
|
94 | + 'the hostname of the database to convert to' |
|
95 | + ) |
|
96 | + ->addArgument( |
|
97 | + 'database', |
|
98 | + InputArgument::REQUIRED, |
|
99 | + 'the name of the database to convert to' |
|
100 | + ) |
|
101 | + ->addOption( |
|
102 | + 'port', |
|
103 | + null, |
|
104 | + InputOption::VALUE_REQUIRED, |
|
105 | + 'the port of the database to convert to' |
|
106 | + ) |
|
107 | + ->addOption( |
|
108 | + 'password', |
|
109 | + null, |
|
110 | + InputOption::VALUE_REQUIRED, |
|
111 | + 'the password of the database to convert to. Will be asked when not specified. Can also be passed via stdin.' |
|
112 | + ) |
|
113 | + ->addOption( |
|
114 | + 'clear-schema', |
|
115 | + null, |
|
116 | + InputOption::VALUE_NONE, |
|
117 | + 'remove all tables from the destination database' |
|
118 | + ) |
|
119 | + ->addOption( |
|
120 | + 'all-apps', |
|
121 | + null, |
|
122 | + InputOption::VALUE_NONE, |
|
123 | + 'whether to create schema for all apps instead of only installed apps' |
|
124 | + ) |
|
125 | + ->addOption( |
|
126 | + 'chunk-size', |
|
127 | + null, |
|
128 | + InputOption::VALUE_REQUIRED, |
|
129 | + 'the maximum number of database rows to handle in a single query, bigger tables will be handled in chunks of this size. Lower this if the process runs out of memory during conversion.', |
|
130 | + 1000 |
|
131 | + ) |
|
132 | + ; |
|
133 | + } |
|
134 | + |
|
135 | + protected function validateInput(InputInterface $input, OutputInterface $output) { |
|
136 | + $type = $this->connectionFactory->normalizeType($input->getArgument('type')); |
|
137 | + if ($type === 'sqlite3') { |
|
138 | + throw new \InvalidArgumentException( |
|
139 | + 'Converting to SQLite (sqlite3) is currently not supported.' |
|
140 | + ); |
|
141 | + } |
|
142 | + if ($type === $this->config->getSystemValue('dbtype', '')) { |
|
143 | + throw new \InvalidArgumentException(sprintf( |
|
144 | + 'Can not convert from %1$s to %1$s.', |
|
145 | + $type |
|
146 | + )); |
|
147 | + } |
|
148 | + if ($type === 'oci' && $input->getOption('clear-schema')) { |
|
149 | + // Doctrine unconditionally tries (at least in version 2.3) |
|
150 | + // to drop sequence triggers when dropping a table, even though |
|
151 | + // such triggers may not exist. This results in errors like |
|
152 | + // "ORA-04080: trigger 'OC_STORAGES_AI_PK' does not exist". |
|
153 | + throw new \InvalidArgumentException( |
|
154 | + 'The --clear-schema option is not supported when converting to Oracle (oci).' |
|
155 | + ); |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + protected function readPassword(InputInterface $input, OutputInterface $output) { |
|
160 | + // Explicitly specified password |
|
161 | + if ($input->getOption('password')) { |
|
162 | + return; |
|
163 | + } |
|
164 | + |
|
165 | + // Read from stdin. stream_set_blocking is used to prevent blocking |
|
166 | + // when nothing is passed via stdin. |
|
167 | + stream_set_blocking(STDIN, 0); |
|
168 | + $password = file_get_contents('php://stdin'); |
|
169 | + stream_set_blocking(STDIN, 1); |
|
170 | + if (trim($password) !== '') { |
|
171 | + $input->setOption('password', $password); |
|
172 | + return; |
|
173 | + } |
|
174 | + |
|
175 | + // Read password by interacting |
|
176 | + if ($input->isInteractive()) { |
|
177 | + /** @var QuestionHelper $helper */ |
|
178 | + $helper = $this->getHelper('question'); |
|
179 | + $question = new Question('What is the database password?'); |
|
180 | + $question->setHidden(true); |
|
181 | + $question->setHiddenFallback(false); |
|
182 | + $password = $helper->ask($input, $output, $question); |
|
183 | + $input->setOption('password', $password); |
|
184 | + return; |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
189 | + $this->validateInput($input, $output); |
|
190 | + $this->readPassword($input, $output); |
|
191 | + |
|
192 | + $fromDB = \OC::$server->getDatabaseConnection(); |
|
193 | + $toDB = $this->getToDBConnection($input, $output); |
|
194 | + |
|
195 | + if ($input->getOption('clear-schema')) { |
|
196 | + $this->clearSchema($toDB, $input, $output); |
|
197 | + } |
|
198 | + |
|
199 | + $this->createSchema($fromDB, $toDB, $input, $output); |
|
200 | + |
|
201 | + $toTables = $this->getTables($toDB); |
|
202 | + $fromTables = $this->getTables($fromDB); |
|
203 | + |
|
204 | + // warn/fail if there are more tables in 'from' database |
|
205 | + $extraFromTables = array_diff($fromTables, $toTables); |
|
206 | + if (!empty($extraFromTables)) { |
|
207 | + $output->writeln('<comment>The following tables will not be converted:</comment>'); |
|
208 | + $output->writeln($extraFromTables); |
|
209 | + if (!$input->getOption('all-apps')) { |
|
210 | + $output->writeln('<comment>Please note that tables belonging to available but currently not installed apps</comment>'); |
|
211 | + $output->writeln('<comment>can be included by specifying the --all-apps option.</comment>'); |
|
212 | + } |
|
213 | + |
|
214 | + /** @var QuestionHelper $helper */ |
|
215 | + $helper = $this->getHelper('question'); |
|
216 | + $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false); |
|
217 | + |
|
218 | + if (!$helper->ask($input, $output, $question)) { |
|
219 | + return; |
|
220 | + } |
|
221 | + } |
|
222 | + $intersectingTables = array_intersect($toTables, $fromTables); |
|
223 | + $this->convertDB($fromDB, $toDB, $intersectingTables, $input, $output); |
|
224 | + } |
|
225 | + |
|
226 | + protected function createSchema(Connection $fromDB, Connection $toDB, InputInterface $input, OutputInterface $output) { |
|
227 | + $output->writeln('<info>Creating schema in new database</info>'); |
|
228 | + |
|
229 | + $fromMS = new MigrationService('core', $fromDB); |
|
230 | + $currentMigration = $fromMS->getMigration('current'); |
|
231 | + if ($currentMigration !== '0') { |
|
232 | + $toMS = new MigrationService('core', $toDB); |
|
233 | + $toMS->migrate($currentMigration); |
|
234 | + } |
|
235 | + |
|
236 | + $schemaManager = new \OC\DB\MDB2SchemaManager($toDB); |
|
237 | + $apps = $input->getOption('all-apps') ? \OC_App::getAllApps() : \OC_App::getEnabledApps(); |
|
238 | + foreach($apps as $app) { |
|
239 | + if (file_exists(\OC_App::getAppPath($app).'/appinfo/database.xml')) { |
|
240 | + $schemaManager->createDbFromStructure(\OC_App::getAppPath($app).'/appinfo/database.xml'); |
|
241 | + } else { |
|
242 | + // Make sure autoloading works... |
|
243 | + \OC_App::loadApp($app); |
|
244 | + $fromMS = new MigrationService($app, $fromDB); |
|
245 | + $currentMigration = $fromMS->getMigration('current'); |
|
246 | + if ($currentMigration !== '0') { |
|
247 | + $toMS = new MigrationService($app, $toDB); |
|
248 | + $toMS->migrate($currentMigration, true); |
|
249 | + } |
|
250 | + } |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + protected function getToDBConnection(InputInterface $input, OutputInterface $output) { |
|
255 | + $type = $input->getArgument('type'); |
|
256 | + $connectionParams = $this->connectionFactory->createConnectionParams(); |
|
257 | + $connectionParams = array_merge($connectionParams, [ |
|
258 | + 'host' => $input->getArgument('hostname'), |
|
259 | + 'user' => $input->getArgument('username'), |
|
260 | + 'password' => $input->getOption('password'), |
|
261 | + 'dbname' => $input->getArgument('database'), |
|
262 | + ]); |
|
263 | + if ($input->getOption('port')) { |
|
264 | + $connectionParams['port'] = $input->getOption('port'); |
|
265 | + } |
|
266 | + return $this->connectionFactory->getConnection($type, $connectionParams); |
|
267 | + } |
|
268 | + |
|
269 | + protected function clearSchema(Connection $db, InputInterface $input, OutputInterface $output) { |
|
270 | + $toTables = $this->getTables($db); |
|
271 | + if (!empty($toTables)) { |
|
272 | + $output->writeln('<info>Clearing schema in new database</info>'); |
|
273 | + } |
|
274 | + foreach($toTables as $table) { |
|
275 | + $db->getSchemaManager()->dropTable($table); |
|
276 | + } |
|
277 | + } |
|
278 | + |
|
279 | + protected function getTables(Connection $db) { |
|
280 | + $filterExpression = '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
281 | + $db->getConfiguration()-> |
|
282 | + setFilterSchemaAssetsExpression($filterExpression); |
|
283 | + return $db->getSchemaManager()->listTableNames(); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @param Connection $fromDB |
|
288 | + * @param Connection $toDB |
|
289 | + * @param Table $table |
|
290 | + * @param InputInterface $input |
|
291 | + * @param OutputInterface $output |
|
292 | + * @suppress SqlInjectionChecker |
|
293 | + */ |
|
294 | + protected function copyTable(Connection $fromDB, Connection $toDB, Table $table, InputInterface $input, OutputInterface $output) { |
|
295 | + if ($table->getName() === $toDB->getPrefix() . 'migrations') { |
|
296 | + $output->writeln('<comment>Skipping migrations table because it was already filled by running the migrations</comment>'); |
|
297 | + return; |
|
298 | + } |
|
299 | + |
|
300 | + $chunkSize = $input->getOption('chunk-size'); |
|
301 | + |
|
302 | + $query = $fromDB->getQueryBuilder(); |
|
303 | + $query->automaticTablePrefix(false); |
|
304 | + $query->select($query->func()->count('*', 'num_entries')) |
|
305 | + ->from($table->getName()); |
|
306 | + $result = $query->execute(); |
|
307 | + $count = $result->fetchColumn(); |
|
308 | + $result->closeCursor(); |
|
309 | + |
|
310 | + $numChunks = ceil($count/$chunkSize); |
|
311 | + if ($numChunks > 1) { |
|
312 | + $output->writeln('chunked query, ' . $numChunks . ' chunks'); |
|
313 | + } |
|
314 | + |
|
315 | + $progress = new ProgressBar($output, $count); |
|
316 | + $progress->start(); |
|
317 | + $redraw = $count > $chunkSize ? 100 : ($count > 100 ? 5 : 1); |
|
318 | + $progress->setRedrawFrequency($redraw); |
|
319 | + |
|
320 | + $query = $fromDB->getQueryBuilder(); |
|
321 | + $query->automaticTablePrefix(false); |
|
322 | + $query->select('*') |
|
323 | + ->from($table->getName()) |
|
324 | + ->setMaxResults($chunkSize); |
|
325 | + |
|
326 | + try { |
|
327 | + $orderColumns = $table->getPrimaryKeyColumns(); |
|
328 | + } catch (DBALException $e) { |
|
329 | + $orderColumns = []; |
|
330 | + foreach ($table->getColumns() as $column) { |
|
331 | + $orderColumns[] = $column->getName(); |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + foreach ($orderColumns as $column) { |
|
336 | + $query->addOrderBy($column); |
|
337 | + } |
|
338 | + |
|
339 | + $insertQuery = $toDB->getQueryBuilder(); |
|
340 | + $insertQuery->automaticTablePrefix(false); |
|
341 | + $insertQuery->insert($table->getName()); |
|
342 | + $parametersCreated = false; |
|
343 | + |
|
344 | + for ($chunk = 0; $chunk < $numChunks; $chunk++) { |
|
345 | + $query->setFirstResult($chunk * $chunkSize); |
|
346 | + |
|
347 | + $result = $query->execute(); |
|
348 | + |
|
349 | + while ($row = $result->fetch()) { |
|
350 | + $progress->advance(); |
|
351 | + if (!$parametersCreated) { |
|
352 | + foreach ($row as $key => $value) { |
|
353 | + $insertQuery->setValue($key, $insertQuery->createParameter($key)); |
|
354 | + } |
|
355 | + $parametersCreated = true; |
|
356 | + } |
|
357 | + |
|
358 | + foreach ($row as $key => $value) { |
|
359 | + $type = $this->getColumnType($table, $key); |
|
360 | + if ($type !== false) { |
|
361 | + $insertQuery->setParameter($key, $value, $type); |
|
362 | + } else { |
|
363 | + $insertQuery->setParameter($key, $value); |
|
364 | + } |
|
365 | + } |
|
366 | + $insertQuery->execute(); |
|
367 | + } |
|
368 | + $result->closeCursor(); |
|
369 | + } |
|
370 | + $progress->finish(); |
|
371 | + } |
|
372 | + |
|
373 | + protected function getColumnType(Table $table, $columnName) { |
|
374 | + $tableName = $table->getName(); |
|
375 | + if (isset($this->columnTypes[$tableName][$columnName])) { |
|
376 | + return $this->columnTypes[$tableName][$columnName]; |
|
377 | + } |
|
378 | + |
|
379 | + $type = $table->getColumn($columnName)->getType()->getName(); |
|
380 | + |
|
381 | + switch ($type) { |
|
382 | + case Type::BLOB: |
|
383 | + case Type::TEXT: |
|
384 | + $this->columnTypes[$tableName][$columnName] = IQueryBuilder::PARAM_LOB; |
|
385 | + break; |
|
386 | + default: |
|
387 | + $this->columnTypes[$tableName][$columnName] = false; |
|
388 | + } |
|
389 | + |
|
390 | + return $this->columnTypes[$tableName][$columnName]; |
|
391 | + } |
|
392 | + |
|
393 | + protected function convertDB(Connection $fromDB, Connection $toDB, array $tables, InputInterface $input, OutputInterface $output) { |
|
394 | + $this->config->setSystemValue('maintenance', true); |
|
395 | + $schema = $fromDB->createSchema(); |
|
396 | + |
|
397 | + try { |
|
398 | + // copy table rows |
|
399 | + foreach($tables as $table) { |
|
400 | + $output->writeln($table); |
|
401 | + $this->copyTable($fromDB, $toDB, $schema->getTable($table), $input, $output); |
|
402 | + } |
|
403 | + if ($input->getArgument('type') === 'pgsql') { |
|
404 | + $tools = new \OC\DB\PgSqlTools($this->config); |
|
405 | + $tools->resynchronizeDatabaseSequences($toDB); |
|
406 | + } |
|
407 | + // save new database config |
|
408 | + $this->saveDBInfo($input); |
|
409 | + } catch(\Exception $e) { |
|
410 | + $this->config->setSystemValue('maintenance', false); |
|
411 | + throw $e; |
|
412 | + } |
|
413 | + $this->config->setSystemValue('maintenance', false); |
|
414 | + } |
|
415 | + |
|
416 | + protected function saveDBInfo(InputInterface $input) { |
|
417 | + $type = $input->getArgument('type'); |
|
418 | + $username = $input->getArgument('username'); |
|
419 | + $dbHost = $input->getArgument('hostname'); |
|
420 | + $dbName = $input->getArgument('database'); |
|
421 | + $password = $input->getOption('password'); |
|
422 | + if ($input->getOption('port')) { |
|
423 | + $dbHost .= ':'.$input->getOption('port'); |
|
424 | + } |
|
425 | + |
|
426 | + $this->config->setSystemValues([ |
|
427 | + 'dbtype' => $type, |
|
428 | + 'dbname' => $dbName, |
|
429 | + 'dbhost' => $dbHost, |
|
430 | + 'dbuser' => $username, |
|
431 | + 'dbpassword' => $password, |
|
432 | + ]); |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * Return possible values for the named option |
|
437 | + * |
|
438 | + * @param string $optionName |
|
439 | + * @param CompletionContext $context |
|
440 | + * @return string[] |
|
441 | + */ |
|
442 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
443 | + return []; |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Return possible values for the named argument |
|
448 | + * |
|
449 | + * @param string $argumentName |
|
450 | + * @param CompletionContext $context |
|
451 | + * @return string[] |
|
452 | + */ |
|
453 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
454 | + if ($argumentName === 'type') { |
|
455 | + return ['mysql', 'oci', 'pgsql']; |
|
456 | + } |
|
457 | + return []; |
|
458 | + } |
|
459 | 459 | } |
@@ -27,7 +27,7 @@ |
||
27 | 27 | * {@inheritDoc} |
28 | 28 | */ |
29 | 29 | public function getName() { |
30 | - return (string)$this->l10n->t('Education Edition'); |
|
30 | + return (string) $this->l10n->t('Education Edition'); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -23,28 +23,28 @@ |
||
23 | 23 | |
24 | 24 | class EducationBundle extends Bundle { |
25 | 25 | |
26 | - /** |
|
27 | - * {@inheritDoc} |
|
28 | - */ |
|
29 | - public function getName() { |
|
30 | - return (string)$this->l10n->t('Education Edition'); |
|
31 | - } |
|
26 | + /** |
|
27 | + * {@inheritDoc} |
|
28 | + */ |
|
29 | + public function getName() { |
|
30 | + return (string)$this->l10n->t('Education Edition'); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritDoc} |
|
35 | - */ |
|
36 | - public function getAppIdentifiers() { |
|
37 | - return [ |
|
38 | - 'zenodo', |
|
39 | - 'dashboard', |
|
40 | - 'circles', |
|
41 | - 'groupfolders', |
|
42 | - 'announcementcenter', |
|
43 | - 'admin_notifications', |
|
44 | - 'quota_warning', |
|
45 | - 'orcid', |
|
46 | - 'user_saml', |
|
47 | - ]; |
|
48 | - } |
|
33 | + /** |
|
34 | + * {@inheritDoc} |
|
35 | + */ |
|
36 | + public function getAppIdentifiers() { |
|
37 | + return [ |
|
38 | + 'zenodo', |
|
39 | + 'dashboard', |
|
40 | + 'circles', |
|
41 | + 'groupfolders', |
|
42 | + 'announcementcenter', |
|
43 | + 'admin_notifications', |
|
44 | + 'quota_warning', |
|
45 | + 'orcid', |
|
46 | + 'user_saml', |
|
47 | + ]; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | /** |
52 | 52 | * Controllers |
53 | 53 | */ |
54 | - $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { |
|
54 | + $container->registerService('ShareController', function(SimpleContainer $c) use ($server) { |
|
55 | 55 | $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
56 | 56 | return new ShareController( |
57 | 57 | $c->query('AppName'), |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $server->query(Defaults::class) |
72 | 72 | ); |
73 | 73 | }); |
74 | - $container->registerService('ExternalSharesController', function (SimpleContainer $c) { |
|
74 | + $container->registerService('ExternalSharesController', function(SimpleContainer $c) { |
|
75 | 75 | return new ExternalSharesController( |
76 | 76 | $c->query('AppName'), |
77 | 77 | $c->query('Request'), |
@@ -83,13 +83,13 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * Core class wrappers |
85 | 85 | */ |
86 | - $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) { |
|
86 | + $container->registerService('HttpClientService', function(SimpleContainer $c) use ($server) { |
|
87 | 87 | return $server->getHTTPClientService(); |
88 | 88 | }); |
89 | - $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) { |
|
89 | + $container->registerService(ICloudIdManager::class, function(SimpleContainer $c) use ($server) { |
|
90 | 90 | return $server->getCloudIdManager(); |
91 | 91 | }); |
92 | - $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { |
|
92 | + $container->registerService('ExternalManager', function(SimpleContainer $c) use ($server) { |
|
93 | 93 | $user = $server->getUserSession()->getUser(); |
94 | 94 | $uid = $user ? $user->getUID() : null; |
95 | 95 | return new \OCA\Files_Sharing\External\Manager( |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | /** |
108 | 108 | * Middleware |
109 | 109 | */ |
110 | - $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) { |
|
110 | + $container->registerService('SharingCheckMiddleware', function(SimpleContainer $c) use ($server) { |
|
111 | 111 | return new SharingCheckMiddleware( |
112 | 112 | $c->query('AppName'), |
113 | 113 | $server->getConfig(), |
@@ -118,14 +118,14 @@ discard block |
||
118 | 118 | ); |
119 | 119 | }); |
120 | 120 | |
121 | - $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) { |
|
121 | + $container->registerService('OCSShareAPIMiddleware', function(SimpleContainer $c) use ($server) { |
|
122 | 122 | return new OCSShareAPIMiddleware( |
123 | 123 | $server->getShareManager(), |
124 | 124 | $server->getL10N($c->query('AppName')) |
125 | 125 | ); |
126 | 126 | }); |
127 | 127 | |
128 | - $container->registerService(ShareInfoMiddleware::class, function () use ($server) { |
|
128 | + $container->registerService(ShareInfoMiddleware::class, function() use ($server) { |
|
129 | 129 | return new ShareInfoMiddleware( |
130 | 130 | $server->getShareManager() |
131 | 131 | ); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $container->registerMiddleWare('OCSShareAPIMiddleware'); |
137 | 137 | $container->registerMiddleWare(ShareInfoMiddleware::class); |
138 | 138 | |
139 | - $container->registerService('MountProvider', function (IContainer $c) { |
|
139 | + $container->registerService('MountProvider', function(IContainer $c) { |
|
140 | 140 | /** @var \OCP\IServerContainer $server */ |
141 | 141 | $server = $c->query('ServerContainer'); |
142 | 142 | return new MountProvider( |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | ); |
147 | 147 | }); |
148 | 148 | |
149 | - $container->registerService('ExternalMountProvider', function (IContainer $c) { |
|
149 | + $container->registerService('ExternalMountProvider', function(IContainer $c) { |
|
150 | 150 | /** @var \OCP\IServerContainer $server */ |
151 | 151 | $server = $c->query('ServerContainer'); |
152 | 152 | return new \OCA\Files_Sharing\External\MountProvider( |
@@ -46,138 +46,138 @@ |
||
46 | 46 | use OCA\Files_Sharing\External\Manager; |
47 | 47 | |
48 | 48 | class Application extends App { |
49 | - public function __construct(array $urlParams = array()) { |
|
50 | - parent::__construct('files_sharing', $urlParams); |
|
49 | + public function __construct(array $urlParams = array()) { |
|
50 | + parent::__construct('files_sharing', $urlParams); |
|
51 | 51 | |
52 | - $container = $this->getContainer(); |
|
53 | - /** @var IServerContainer $server */ |
|
54 | - $server = $container->getServer(); |
|
52 | + $container = $this->getContainer(); |
|
53 | + /** @var IServerContainer $server */ |
|
54 | + $server = $container->getServer(); |
|
55 | 55 | |
56 | - /** |
|
57 | - * Controllers |
|
58 | - */ |
|
59 | - $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { |
|
60 | - $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
61 | - return new ShareController( |
|
62 | - $c->query('AppName'), |
|
63 | - $c->query('Request'), |
|
64 | - $server->getConfig(), |
|
65 | - $server->getURLGenerator(), |
|
66 | - $server->getUserManager(), |
|
67 | - $server->getLogger(), |
|
68 | - $server->getActivityManager(), |
|
69 | - $server->getShareManager(), |
|
70 | - $server->getSession(), |
|
71 | - $server->getPreviewManager(), |
|
72 | - $server->getRootFolder(), |
|
73 | - $federatedSharingApp->getFederatedShareProvider(), |
|
74 | - $server->getEventDispatcher(), |
|
75 | - $server->getL10N($c->query('AppName')), |
|
76 | - $server->query(Defaults::class) |
|
77 | - ); |
|
78 | - }); |
|
79 | - $container->registerService('ExternalSharesController', function (SimpleContainer $c) { |
|
80 | - return new ExternalSharesController( |
|
81 | - $c->query('AppName'), |
|
82 | - $c->query('Request'), |
|
83 | - $c->query('ExternalManager'), |
|
84 | - $c->query('HttpClientService') |
|
85 | - ); |
|
86 | - }); |
|
56 | + /** |
|
57 | + * Controllers |
|
58 | + */ |
|
59 | + $container->registerService('ShareController', function (SimpleContainer $c) use ($server) { |
|
60 | + $federatedSharingApp = new \OCA\FederatedFileSharing\AppInfo\Application(); |
|
61 | + return new ShareController( |
|
62 | + $c->query('AppName'), |
|
63 | + $c->query('Request'), |
|
64 | + $server->getConfig(), |
|
65 | + $server->getURLGenerator(), |
|
66 | + $server->getUserManager(), |
|
67 | + $server->getLogger(), |
|
68 | + $server->getActivityManager(), |
|
69 | + $server->getShareManager(), |
|
70 | + $server->getSession(), |
|
71 | + $server->getPreviewManager(), |
|
72 | + $server->getRootFolder(), |
|
73 | + $federatedSharingApp->getFederatedShareProvider(), |
|
74 | + $server->getEventDispatcher(), |
|
75 | + $server->getL10N($c->query('AppName')), |
|
76 | + $server->query(Defaults::class) |
|
77 | + ); |
|
78 | + }); |
|
79 | + $container->registerService('ExternalSharesController', function (SimpleContainer $c) { |
|
80 | + return new ExternalSharesController( |
|
81 | + $c->query('AppName'), |
|
82 | + $c->query('Request'), |
|
83 | + $c->query('ExternalManager'), |
|
84 | + $c->query('HttpClientService') |
|
85 | + ); |
|
86 | + }); |
|
87 | 87 | |
88 | - /** |
|
89 | - * Core class wrappers |
|
90 | - */ |
|
91 | - $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) { |
|
92 | - return $server->getHTTPClientService(); |
|
93 | - }); |
|
94 | - $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) { |
|
95 | - return $server->getCloudIdManager(); |
|
96 | - }); |
|
97 | - $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { |
|
98 | - $user = $server->getUserSession()->getUser(); |
|
99 | - $uid = $user ? $user->getUID() : null; |
|
100 | - return new \OCA\Files_Sharing\External\Manager( |
|
101 | - $server->getDatabaseConnection(), |
|
102 | - \OC\Files\Filesystem::getMountManager(), |
|
103 | - \OC\Files\Filesystem::getLoader(), |
|
104 | - $server->getHTTPClientService(), |
|
105 | - $server->getNotificationManager(), |
|
106 | - $server->query(\OCP\OCS\IDiscoveryService::class), |
|
107 | - $server->getCloudFederationProviderManager(), |
|
108 | - $server->getCloudFederationFactory(), |
|
109 | - $server->getGroupManager(), |
|
110 | - $server->getUserManager(), |
|
111 | - $uid |
|
112 | - ); |
|
113 | - }); |
|
114 | - $container->registerAlias(Manager::class, 'ExternalManager'); |
|
88 | + /** |
|
89 | + * Core class wrappers |
|
90 | + */ |
|
91 | + $container->registerService('HttpClientService', function (SimpleContainer $c) use ($server) { |
|
92 | + return $server->getHTTPClientService(); |
|
93 | + }); |
|
94 | + $container->registerService(ICloudIdManager::class, function (SimpleContainer $c) use ($server) { |
|
95 | + return $server->getCloudIdManager(); |
|
96 | + }); |
|
97 | + $container->registerService('ExternalManager', function (SimpleContainer $c) use ($server) { |
|
98 | + $user = $server->getUserSession()->getUser(); |
|
99 | + $uid = $user ? $user->getUID() : null; |
|
100 | + return new \OCA\Files_Sharing\External\Manager( |
|
101 | + $server->getDatabaseConnection(), |
|
102 | + \OC\Files\Filesystem::getMountManager(), |
|
103 | + \OC\Files\Filesystem::getLoader(), |
|
104 | + $server->getHTTPClientService(), |
|
105 | + $server->getNotificationManager(), |
|
106 | + $server->query(\OCP\OCS\IDiscoveryService::class), |
|
107 | + $server->getCloudFederationProviderManager(), |
|
108 | + $server->getCloudFederationFactory(), |
|
109 | + $server->getGroupManager(), |
|
110 | + $server->getUserManager(), |
|
111 | + $uid |
|
112 | + ); |
|
113 | + }); |
|
114 | + $container->registerAlias(Manager::class, 'ExternalManager'); |
|
115 | 115 | |
116 | - /** |
|
117 | - * Middleware |
|
118 | - */ |
|
119 | - $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) { |
|
120 | - return new SharingCheckMiddleware( |
|
121 | - $c->query('AppName'), |
|
122 | - $server->getConfig(), |
|
123 | - $server->getAppManager(), |
|
124 | - $server->query(IControllerMethodReflector::class), |
|
125 | - $server->getShareManager(), |
|
126 | - $server->getRequest() |
|
127 | - ); |
|
128 | - }); |
|
116 | + /** |
|
117 | + * Middleware |
|
118 | + */ |
|
119 | + $container->registerService('SharingCheckMiddleware', function (SimpleContainer $c) use ($server) { |
|
120 | + return new SharingCheckMiddleware( |
|
121 | + $c->query('AppName'), |
|
122 | + $server->getConfig(), |
|
123 | + $server->getAppManager(), |
|
124 | + $server->query(IControllerMethodReflector::class), |
|
125 | + $server->getShareManager(), |
|
126 | + $server->getRequest() |
|
127 | + ); |
|
128 | + }); |
|
129 | 129 | |
130 | - $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) { |
|
131 | - return new OCSShareAPIMiddleware( |
|
132 | - $server->getShareManager(), |
|
133 | - $server->getL10N($c->query('AppName')) |
|
134 | - ); |
|
135 | - }); |
|
130 | + $container->registerService('OCSShareAPIMiddleware', function (SimpleContainer $c) use ($server) { |
|
131 | + return new OCSShareAPIMiddleware( |
|
132 | + $server->getShareManager(), |
|
133 | + $server->getL10N($c->query('AppName')) |
|
134 | + ); |
|
135 | + }); |
|
136 | 136 | |
137 | - $container->registerService(ShareInfoMiddleware::class, function () use ($server) { |
|
138 | - return new ShareInfoMiddleware( |
|
139 | - $server->getShareManager() |
|
140 | - ); |
|
141 | - }); |
|
137 | + $container->registerService(ShareInfoMiddleware::class, function () use ($server) { |
|
138 | + return new ShareInfoMiddleware( |
|
139 | + $server->getShareManager() |
|
140 | + ); |
|
141 | + }); |
|
142 | 142 | |
143 | - // Execute middlewares |
|
144 | - $container->registerMiddleWare('SharingCheckMiddleware'); |
|
145 | - $container->registerMiddleWare('OCSShareAPIMiddleware'); |
|
146 | - $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
143 | + // Execute middlewares |
|
144 | + $container->registerMiddleWare('SharingCheckMiddleware'); |
|
145 | + $container->registerMiddleWare('OCSShareAPIMiddleware'); |
|
146 | + $container->registerMiddleWare(ShareInfoMiddleware::class); |
|
147 | 147 | |
148 | - $container->registerService('MountProvider', function (IContainer $c) { |
|
149 | - /** @var \OCP\IServerContainer $server */ |
|
150 | - $server = $c->query('ServerContainer'); |
|
151 | - return new MountProvider( |
|
152 | - $server->getConfig(), |
|
153 | - $server->getShareManager(), |
|
154 | - $server->getLogger() |
|
155 | - ); |
|
156 | - }); |
|
148 | + $container->registerService('MountProvider', function (IContainer $c) { |
|
149 | + /** @var \OCP\IServerContainer $server */ |
|
150 | + $server = $c->query('ServerContainer'); |
|
151 | + return new MountProvider( |
|
152 | + $server->getConfig(), |
|
153 | + $server->getShareManager(), |
|
154 | + $server->getLogger() |
|
155 | + ); |
|
156 | + }); |
|
157 | 157 | |
158 | - $container->registerService('ExternalMountProvider', function (IContainer $c) { |
|
159 | - /** @var \OCP\IServerContainer $server */ |
|
160 | - $server = $c->query('ServerContainer'); |
|
161 | - return new \OCA\Files_Sharing\External\MountProvider( |
|
162 | - $server->getDatabaseConnection(), |
|
163 | - function() use ($c) { |
|
164 | - return $c->query('ExternalManager'); |
|
165 | - }, |
|
166 | - $server->getCloudIdManager() |
|
167 | - ); |
|
168 | - }); |
|
158 | + $container->registerService('ExternalMountProvider', function (IContainer $c) { |
|
159 | + /** @var \OCP\IServerContainer $server */ |
|
160 | + $server = $c->query('ServerContainer'); |
|
161 | + return new \OCA\Files_Sharing\External\MountProvider( |
|
162 | + $server->getDatabaseConnection(), |
|
163 | + function() use ($c) { |
|
164 | + return $c->query('ExternalManager'); |
|
165 | + }, |
|
166 | + $server->getCloudIdManager() |
|
167 | + ); |
|
168 | + }); |
|
169 | 169 | |
170 | - /* |
|
170 | + /* |
|
171 | 171 | * Register capabilities |
172 | 172 | */ |
173 | - $container->registerCapability(Capabilities::class); |
|
174 | - } |
|
173 | + $container->registerCapability(Capabilities::class); |
|
174 | + } |
|
175 | 175 | |
176 | - public function registerMountProviders() { |
|
177 | - /** @var \OCP\IServerContainer $server */ |
|
178 | - $server = $this->getContainer()->query('ServerContainer'); |
|
179 | - $mountProviderCollection = $server->getMountProviderCollection(); |
|
180 | - $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider')); |
|
181 | - $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
182 | - } |
|
176 | + public function registerMountProviders() { |
|
177 | + /** @var \OCP\IServerContainer $server */ |
|
178 | + $server = $this->getContainer()->query('ServerContainer'); |
|
179 | + $mountProviderCollection = $server->getMountProviderCollection(); |
|
180 | + $mountProviderCollection->registerProvider($this->getContainer()->query('MountProvider')); |
|
181 | + $mountProviderCollection->registerProvider($this->getContainer()->query('ExternalMountProvider')); |
|
182 | + } |
|
183 | 183 | } |
@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | // @codeCoverageIgnoreStart |
3 | 3 | if(!isset($_)) {//standalone page is not supported anymore - redirect to / |
4 | - require_once '../../lib/base.php'; |
|
4 | + require_once '../../lib/base.php'; |
|
5 | 5 | |
6 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
7 | - header('Location: ' . $urlGenerator->getAbsoluteURL('/')); |
|
8 | - exit; |
|
6 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
7 | + header('Location: ' . $urlGenerator->getAbsoluteURL('/')); |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | // @codeCoverageIgnoreEnd |
11 | 11 | ?> |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | // @codeCoverageIgnoreStart |
3 | -if(!isset($_)) {//standalone page is not supported anymore - redirect to / |
|
3 | +if (!isset($_)) {//standalone page is not supported anymore - redirect to / |
|
4 | 4 | require_once '../../lib/base.php'; |
5 | 5 | |
6 | 6 | $urlGenerator = \OC::$server->getURLGenerator(); |
7 | - header('Location: ' . $urlGenerator->getAbsoluteURL('/')); |
|
7 | + header('Location: '.$urlGenerator->getAbsoluteURL('/')); |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | // @codeCoverageIgnoreEnd |
11 | 11 | ?> |
12 | 12 | <ul> |
13 | 13 | <li class='error'> |
14 | - <?php p($l->t( 'Access forbidden' )); ?><br> |
|
15 | - <p class='hint'><?php if(isset($_['message'])) p($_['message'])?></p> |
|
14 | + <?php p($l->t('Access forbidden')); ?><br> |
|
15 | + <p class='hint'><?php if (isset($_['message'])) p($_['message'])?></p> |
|
16 | 16 | </li> |
17 | 17 | </ul> |