@@ -54,8 +54,7 @@ |
||
54 | 54 | */ |
55 | 55 | public function getBody() { |
56 | 56 | return $this->stream ? |
57 | - $this->response->getBody()->detach(): |
|
58 | - $this->response->getBody()->getContents(); |
|
57 | + $this->response->getBody()->detach() : $this->response->getBody()->getContents(); |
|
59 | 58 | } |
60 | 59 | |
61 | 60 | /** |
@@ -33,57 +33,57 @@ |
||
33 | 33 | * @package OC\Http |
34 | 34 | */ |
35 | 35 | class Response implements IResponse { |
36 | - /** @var ResponseInterface */ |
|
37 | - private $response; |
|
36 | + /** @var ResponseInterface */ |
|
37 | + private $response; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var bool |
|
41 | - */ |
|
42 | - private $stream; |
|
39 | + /** |
|
40 | + * @var bool |
|
41 | + */ |
|
42 | + private $stream; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param ResponseInterface $response |
|
46 | - * @param bool $stream |
|
47 | - */ |
|
48 | - public function __construct(ResponseInterface $response, $stream = false) { |
|
49 | - $this->response = $response; |
|
50 | - $this->stream = $stream; |
|
51 | - } |
|
44 | + /** |
|
45 | + * @param ResponseInterface $response |
|
46 | + * @param bool $stream |
|
47 | + */ |
|
48 | + public function __construct(ResponseInterface $response, $stream = false) { |
|
49 | + $this->response = $response; |
|
50 | + $this->stream = $stream; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return string|resource |
|
55 | - */ |
|
56 | - public function getBody() { |
|
57 | - return $this->stream ? |
|
58 | - $this->response->getBody()->detach(): |
|
59 | - $this->response->getBody()->getContents(); |
|
60 | - } |
|
53 | + /** |
|
54 | + * @return string|resource |
|
55 | + */ |
|
56 | + public function getBody() { |
|
57 | + return $this->stream ? |
|
58 | + $this->response->getBody()->detach(): |
|
59 | + $this->response->getBody()->getContents(); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return int |
|
64 | - */ |
|
65 | - public function getStatusCode(): int { |
|
66 | - return $this->response->getStatusCode(); |
|
67 | - } |
|
62 | + /** |
|
63 | + * @return int |
|
64 | + */ |
|
65 | + public function getStatusCode(): int { |
|
66 | + return $this->response->getStatusCode(); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param string $key |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function getHeader(string $key): string { |
|
74 | - $headers = $this->response->getHeader($key); |
|
69 | + /** |
|
70 | + * @param string $key |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function getHeader(string $key): string { |
|
74 | + $headers = $this->response->getHeader($key); |
|
75 | 75 | |
76 | - if (count($headers) === 0) { |
|
77 | - return ''; |
|
78 | - } |
|
76 | + if (count($headers) === 0) { |
|
77 | + return ''; |
|
78 | + } |
|
79 | 79 | |
80 | - return $headers[0]; |
|
81 | - } |
|
80 | + return $headers[0]; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - public function getHeaders(): array { |
|
87 | - return $this->response->getHeaders(); |
|
88 | - } |
|
83 | + /** |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + public function getHeaders(): array { |
|
87 | + return $this->response->getHeaders(); |
|
88 | + } |
|
89 | 89 | } |
@@ -81,7 +81,7 @@ |
||
81 | 81 | // FIXME: Required for CI |
82 | 82 | if (!defined('PHPUNIT_RUN')) { |
83 | 83 | $webRoot = \OC::$WEBROOT; |
84 | - if($webRoot === '') { |
|
84 | + if ($webRoot === '') { |
|
85 | 85 | $webRoot = '/'; |
86 | 86 | } |
87 | 87 | setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
@@ -48,58 +48,58 @@ |
||
48 | 48 | * @package OC\Session |
49 | 49 | */ |
50 | 50 | class CryptoWrapper { |
51 | - const COOKIE_NAME = 'oc_sessionPassphrase'; |
|
51 | + const COOKIE_NAME = 'oc_sessionPassphrase'; |
|
52 | 52 | |
53 | - /** @var IConfig */ |
|
54 | - protected $config; |
|
55 | - /** @var ISession */ |
|
56 | - protected $session; |
|
57 | - /** @var ICrypto */ |
|
58 | - protected $crypto; |
|
59 | - /** @var ISecureRandom */ |
|
60 | - protected $random; |
|
61 | - /** @var string */ |
|
62 | - protected $passphrase; |
|
53 | + /** @var IConfig */ |
|
54 | + protected $config; |
|
55 | + /** @var ISession */ |
|
56 | + protected $session; |
|
57 | + /** @var ICrypto */ |
|
58 | + protected $crypto; |
|
59 | + /** @var ISecureRandom */ |
|
60 | + protected $random; |
|
61 | + /** @var string */ |
|
62 | + protected $passphrase; |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param IConfig $config |
|
66 | - * @param ICrypto $crypto |
|
67 | - * @param ISecureRandom $random |
|
68 | - * @param IRequest $request |
|
69 | - */ |
|
70 | - public function __construct(IConfig $config, |
|
71 | - ICrypto $crypto, |
|
72 | - ISecureRandom $random, |
|
73 | - IRequest $request) { |
|
74 | - $this->crypto = $crypto; |
|
75 | - $this->config = $config; |
|
76 | - $this->random = $random; |
|
64 | + /** |
|
65 | + * @param IConfig $config |
|
66 | + * @param ICrypto $crypto |
|
67 | + * @param ISecureRandom $random |
|
68 | + * @param IRequest $request |
|
69 | + */ |
|
70 | + public function __construct(IConfig $config, |
|
71 | + ICrypto $crypto, |
|
72 | + ISecureRandom $random, |
|
73 | + IRequest $request) { |
|
74 | + $this->crypto = $crypto; |
|
75 | + $this->config = $config; |
|
76 | + $this->random = $random; |
|
77 | 77 | |
78 | - if (!is_null($request->getCookie(self::COOKIE_NAME))) { |
|
79 | - $this->passphrase = $request->getCookie(self::COOKIE_NAME); |
|
80 | - } else { |
|
81 | - $this->passphrase = $this->random->generate(128); |
|
82 | - $secureCookie = $request->getServerProtocol() === 'https'; |
|
83 | - // FIXME: Required for CI |
|
84 | - if (!defined('PHPUNIT_RUN')) { |
|
85 | - $webRoot = \OC::$WEBROOT; |
|
86 | - if($webRoot === '') { |
|
87 | - $webRoot = '/'; |
|
88 | - } |
|
89 | - setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
|
90 | - } |
|
91 | - } |
|
92 | - } |
|
78 | + if (!is_null($request->getCookie(self::COOKIE_NAME))) { |
|
79 | + $this->passphrase = $request->getCookie(self::COOKIE_NAME); |
|
80 | + } else { |
|
81 | + $this->passphrase = $this->random->generate(128); |
|
82 | + $secureCookie = $request->getServerProtocol() === 'https'; |
|
83 | + // FIXME: Required for CI |
|
84 | + if (!defined('PHPUNIT_RUN')) { |
|
85 | + $webRoot = \OC::$WEBROOT; |
|
86 | + if($webRoot === '') { |
|
87 | + $webRoot = '/'; |
|
88 | + } |
|
89 | + setcookie(self::COOKIE_NAME, $this->passphrase, 0, $webRoot, '', $secureCookie, true); |
|
90 | + } |
|
91 | + } |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @param ISession $session |
|
96 | - * @return ISession |
|
97 | - */ |
|
98 | - public function wrapSession(ISession $session) { |
|
99 | - if (!($session instanceof CryptoSessionData)) { |
|
100 | - return new CryptoSessionData($session, $this->crypto, $this->passphrase); |
|
101 | - } |
|
94 | + /** |
|
95 | + * @param ISession $session |
|
96 | + * @return ISession |
|
97 | + */ |
|
98 | + public function wrapSession(ISession $session) { |
|
99 | + if (!($session instanceof CryptoSessionData)) { |
|
100 | + return new CryptoSessionData($session, $this->crypto, $this->passphrase); |
|
101 | + } |
|
102 | 102 | |
103 | - return $session; |
|
104 | - } |
|
103 | + return $session; |
|
104 | + } |
|
105 | 105 | } |
@@ -27,148 +27,148 @@ |
||
27 | 27 | |
28 | 28 | class Action implements IAction { |
29 | 29 | |
30 | - /** @var string */ |
|
31 | - protected $label; |
|
32 | - |
|
33 | - /** @var string */ |
|
34 | - protected $labelParsed; |
|
35 | - |
|
36 | - /** @var string */ |
|
37 | - protected $link; |
|
38 | - |
|
39 | - /** @var string */ |
|
40 | - protected $requestType; |
|
41 | - |
|
42 | - /** @var string */ |
|
43 | - protected $icon; |
|
44 | - |
|
45 | - /** @var bool */ |
|
46 | - protected $primary; |
|
47 | - |
|
48 | - /** |
|
49 | - * Constructor |
|
50 | - */ |
|
51 | - public function __construct() { |
|
52 | - $this->label = ''; |
|
53 | - $this->labelParsed = ''; |
|
54 | - $this->link = ''; |
|
55 | - $this->requestType = ''; |
|
56 | - $this->primary = false; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @param string $label |
|
61 | - * @return $this |
|
62 | - * @throws \InvalidArgumentException if the label is invalid |
|
63 | - * @since 8.2.0 |
|
64 | - */ |
|
65 | - public function setLabel($label) { |
|
66 | - if (!is_string($label) || $label === '' || isset($label[32])) { |
|
67 | - throw new \InvalidArgumentException('The given label is invalid'); |
|
68 | - } |
|
69 | - $this->label = $label; |
|
70 | - return $this; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @return string |
|
75 | - * @since 8.2.0 |
|
76 | - */ |
|
77 | - public function getLabel() { |
|
78 | - return $this->label; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @param string $label |
|
83 | - * @return $this |
|
84 | - * @throws \InvalidArgumentException if the label is invalid |
|
85 | - * @since 8.2.0 |
|
86 | - */ |
|
87 | - public function setParsedLabel($label) { |
|
88 | - if (!is_string($label) || $label === '') { |
|
89 | - throw new \InvalidArgumentException('The given parsed label is invalid'); |
|
90 | - } |
|
91 | - $this->labelParsed = $label; |
|
92 | - return $this; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return string |
|
97 | - * @since 8.2.0 |
|
98 | - */ |
|
99 | - public function getParsedLabel() { |
|
100 | - return $this->labelParsed; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param $primary bool |
|
105 | - * @return $this |
|
106 | - * @throws \InvalidArgumentException if $primary is invalid |
|
107 | - * @since 9.0.0 |
|
108 | - */ |
|
109 | - public function setPrimary($primary) { |
|
110 | - if (!is_bool($primary)) { |
|
111 | - throw new \InvalidArgumentException('The given primary option is invalid'); |
|
112 | - } |
|
113 | - |
|
114 | - $this->primary = $primary; |
|
115 | - return $this; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @return bool |
|
120 | - * @since 9.0.0 |
|
121 | - */ |
|
122 | - public function isPrimary() { |
|
123 | - return $this->primary; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $link |
|
128 | - * @param string $requestType |
|
129 | - * @return $this |
|
130 | - * @throws \InvalidArgumentException if the link is invalid |
|
131 | - * @since 8.2.0 |
|
132 | - */ |
|
133 | - public function setLink($link, $requestType) { |
|
134 | - if (!is_string($link) || $link === '' || isset($link[256])) { |
|
135 | - throw new \InvalidArgumentException('The given link is invalid'); |
|
136 | - } |
|
137 | - if (!in_array($requestType, ['GET', 'POST', 'PUT', 'DELETE'], true)) { |
|
138 | - throw new \InvalidArgumentException('The given request type is invalid'); |
|
139 | - } |
|
140 | - $this->link = $link; |
|
141 | - $this->requestType = $requestType; |
|
142 | - return $this; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @return string |
|
147 | - * @since 8.2.0 |
|
148 | - */ |
|
149 | - public function getLink() { |
|
150 | - return $this->link; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @return string |
|
155 | - * @since 8.2.0 |
|
156 | - */ |
|
157 | - public function getRequestType() { |
|
158 | - return $this->requestType; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @return bool |
|
163 | - */ |
|
164 | - public function isValid() { |
|
165 | - return $this->label !== '' && $this->link !== ''; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return bool |
|
170 | - */ |
|
171 | - public function isValidParsed() { |
|
172 | - return $this->labelParsed !== '' && $this->link !== ''; |
|
173 | - } |
|
30 | + /** @var string */ |
|
31 | + protected $label; |
|
32 | + |
|
33 | + /** @var string */ |
|
34 | + protected $labelParsed; |
|
35 | + |
|
36 | + /** @var string */ |
|
37 | + protected $link; |
|
38 | + |
|
39 | + /** @var string */ |
|
40 | + protected $requestType; |
|
41 | + |
|
42 | + /** @var string */ |
|
43 | + protected $icon; |
|
44 | + |
|
45 | + /** @var bool */ |
|
46 | + protected $primary; |
|
47 | + |
|
48 | + /** |
|
49 | + * Constructor |
|
50 | + */ |
|
51 | + public function __construct() { |
|
52 | + $this->label = ''; |
|
53 | + $this->labelParsed = ''; |
|
54 | + $this->link = ''; |
|
55 | + $this->requestType = ''; |
|
56 | + $this->primary = false; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @param string $label |
|
61 | + * @return $this |
|
62 | + * @throws \InvalidArgumentException if the label is invalid |
|
63 | + * @since 8.2.0 |
|
64 | + */ |
|
65 | + public function setLabel($label) { |
|
66 | + if (!is_string($label) || $label === '' || isset($label[32])) { |
|
67 | + throw new \InvalidArgumentException('The given label is invalid'); |
|
68 | + } |
|
69 | + $this->label = $label; |
|
70 | + return $this; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + * @since 8.2.0 |
|
76 | + */ |
|
77 | + public function getLabel() { |
|
78 | + return $this->label; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @param string $label |
|
83 | + * @return $this |
|
84 | + * @throws \InvalidArgumentException if the label is invalid |
|
85 | + * @since 8.2.0 |
|
86 | + */ |
|
87 | + public function setParsedLabel($label) { |
|
88 | + if (!is_string($label) || $label === '') { |
|
89 | + throw new \InvalidArgumentException('The given parsed label is invalid'); |
|
90 | + } |
|
91 | + $this->labelParsed = $label; |
|
92 | + return $this; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + * @since 8.2.0 |
|
98 | + */ |
|
99 | + public function getParsedLabel() { |
|
100 | + return $this->labelParsed; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param $primary bool |
|
105 | + * @return $this |
|
106 | + * @throws \InvalidArgumentException if $primary is invalid |
|
107 | + * @since 9.0.0 |
|
108 | + */ |
|
109 | + public function setPrimary($primary) { |
|
110 | + if (!is_bool($primary)) { |
|
111 | + throw new \InvalidArgumentException('The given primary option is invalid'); |
|
112 | + } |
|
113 | + |
|
114 | + $this->primary = $primary; |
|
115 | + return $this; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @return bool |
|
120 | + * @since 9.0.0 |
|
121 | + */ |
|
122 | + public function isPrimary() { |
|
123 | + return $this->primary; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $link |
|
128 | + * @param string $requestType |
|
129 | + * @return $this |
|
130 | + * @throws \InvalidArgumentException if the link is invalid |
|
131 | + * @since 8.2.0 |
|
132 | + */ |
|
133 | + public function setLink($link, $requestType) { |
|
134 | + if (!is_string($link) || $link === '' || isset($link[256])) { |
|
135 | + throw new \InvalidArgumentException('The given link is invalid'); |
|
136 | + } |
|
137 | + if (!in_array($requestType, ['GET', 'POST', 'PUT', 'DELETE'], true)) { |
|
138 | + throw new \InvalidArgumentException('The given request type is invalid'); |
|
139 | + } |
|
140 | + $this->link = $link; |
|
141 | + $this->requestType = $requestType; |
|
142 | + return $this; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @return string |
|
147 | + * @since 8.2.0 |
|
148 | + */ |
|
149 | + public function getLink() { |
|
150 | + return $this->link; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @return string |
|
155 | + * @since 8.2.0 |
|
156 | + */ |
|
157 | + public function getRequestType() { |
|
158 | + return $this->requestType; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @return bool |
|
163 | + */ |
|
164 | + public function isValid() { |
|
165 | + return $this->label !== '' && $this->link !== ''; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return bool |
|
170 | + */ |
|
171 | + public function isValidParsed() { |
|
172 | + return $this->labelParsed !== '' && $this->link !== ''; |
|
173 | + } |
|
174 | 174 | } |
@@ -146,7 +146,7 @@ |
||
146 | 146 | throw new \InvalidArgumentException('The given notifier information is invalid'); |
147 | 147 | } |
148 | 148 | if (isset($this->notifiersInfo[$notifier['id']])) { |
149 | - throw new \InvalidArgumentException('The given notifier ID ' . $notifier['id'] . ' is already in use'); |
|
149 | + throw new \InvalidArgumentException('The given notifier ID '.$notifier['id'].' is already in use'); |
|
150 | 150 | } |
151 | 151 | $this->notifiersInfo[$notifier['id']] = $notifier['name']; |
152 | 152 | } |
@@ -30,25 +30,25 @@ |
||
30 | 30 | parent::__construct($iterator); |
31 | 31 | |
32 | 32 | $appFolders = \OC::$APPSROOTS; |
33 | - foreach($appFolders as $key => $appFolder) { |
|
33 | + foreach ($appFolders as $key => $appFolder) { |
|
34 | 34 | $appFolders[$key] = rtrim($appFolder['path'], '/'); |
35 | 35 | } |
36 | 36 | |
37 | 37 | $excludedFolders = [ |
38 | - rtrim($root . '/data', '/'), |
|
39 | - rtrim($root . '/themes', '/'), |
|
40 | - rtrim($root . '/config', '/'), |
|
41 | - rtrim($root . '/apps', '/'), |
|
42 | - rtrim($root . '/assets', '/'), |
|
43 | - rtrim($root . '/lost+found', '/'), |
|
38 | + rtrim($root.'/data', '/'), |
|
39 | + rtrim($root.'/themes', '/'), |
|
40 | + rtrim($root.'/config', '/'), |
|
41 | + rtrim($root.'/apps', '/'), |
|
42 | + rtrim($root.'/assets', '/'), |
|
43 | + rtrim($root.'/lost+found', '/'), |
|
44 | 44 | // Ignore folders generated by updater since the updater is replaced |
45 | 45 | // after the integrity check is run. |
46 | 46 | // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
47 | - rtrim($root . '/updater', '/'), |
|
48 | - rtrim($root . '/_oc_upgrade', '/'), |
|
47 | + rtrim($root.'/updater', '/'), |
|
48 | + rtrim($root.'/_oc_upgrade', '/'), |
|
49 | 49 | ]; |
50 | 50 | $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
51 | - if($customDataDir !== '') { |
|
51 | + if ($customDataDir !== '') { |
|
52 | 52 | $excludedFolders[] = rtrim($customDataDir, '/'); |
53 | 53 | } |
54 | 54 |
@@ -25,45 +25,45 @@ |
||
25 | 25 | namespace OC\IntegrityCheck\Iterator; |
26 | 26 | |
27 | 27 | class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator { |
28 | - private $excludedFolders; |
|
28 | + private $excludedFolders; |
|
29 | 29 | |
30 | - public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
31 | - parent::__construct($iterator); |
|
30 | + public function __construct(\RecursiveIterator $iterator, $root = '') { |
|
31 | + parent::__construct($iterator); |
|
32 | 32 | |
33 | - $appFolders = \OC::$APPSROOTS; |
|
34 | - foreach($appFolders as $key => $appFolder) { |
|
35 | - $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
36 | - } |
|
33 | + $appFolders = \OC::$APPSROOTS; |
|
34 | + foreach($appFolders as $key => $appFolder) { |
|
35 | + $appFolders[$key] = rtrim($appFolder['path'], '/'); |
|
36 | + } |
|
37 | 37 | |
38 | - $excludedFolders = [ |
|
39 | - rtrim($root . '/data', '/'), |
|
40 | - rtrim($root . '/themes', '/'), |
|
41 | - rtrim($root . '/config', '/'), |
|
42 | - rtrim($root . '/apps', '/'), |
|
43 | - rtrim($root . '/assets', '/'), |
|
44 | - rtrim($root . '/lost+found', '/'), |
|
45 | - // Ignore folders generated by updater since the updater is replaced |
|
46 | - // after the integrity check is run. |
|
47 | - // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
48 | - rtrim($root . '/updater', '/'), |
|
49 | - rtrim($root . '/_oc_upgrade', '/'), |
|
50 | - ]; |
|
51 | - $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
52 | - if($customDataDir !== '') { |
|
53 | - $excludedFolders[] = rtrim($customDataDir, '/'); |
|
54 | - } |
|
38 | + $excludedFolders = [ |
|
39 | + rtrim($root . '/data', '/'), |
|
40 | + rtrim($root . '/themes', '/'), |
|
41 | + rtrim($root . '/config', '/'), |
|
42 | + rtrim($root . '/apps', '/'), |
|
43 | + rtrim($root . '/assets', '/'), |
|
44 | + rtrim($root . '/lost+found', '/'), |
|
45 | + // Ignore folders generated by updater since the updater is replaced |
|
46 | + // after the integrity check is run. |
|
47 | + // See https://github.com/owncloud/updater/issues/318#issuecomment-212497846 |
|
48 | + rtrim($root . '/updater', '/'), |
|
49 | + rtrim($root . '/_oc_upgrade', '/'), |
|
50 | + ]; |
|
51 | + $customDataDir = \OC::$server->getConfig()->getSystemValue('datadirectory', ''); |
|
52 | + if($customDataDir !== '') { |
|
53 | + $excludedFolders[] = rtrim($customDataDir, '/'); |
|
54 | + } |
|
55 | 55 | |
56 | - $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
57 | - } |
|
56 | + $this->excludedFolders = array_merge($excludedFolders, $appFolders); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - public function accept() { |
|
63 | - return !\in_array( |
|
64 | - $this->current()->getPathName(), |
|
65 | - $this->excludedFolders, |
|
66 | - true |
|
67 | - ); |
|
68 | - } |
|
59 | + /** |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + public function accept() { |
|
63 | + return !\in_array( |
|
64 | + $this->current()->getPathName(), |
|
65 | + $this->excludedFolders, |
|
66 | + true |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | } |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | * @return array An array of Tag objects. |
51 | 51 | */ |
52 | 52 | public function loadTags($owners, $type) { |
53 | - if(!is_array($owners)) { |
|
53 | + if (!is_array($owners)) { |
|
54 | 54 | $owners = array($owners); |
55 | 55 | } |
56 | 56 | |
57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
58 | + . 'WHERE `uid` IN ('.str_repeat('?,', count($owners) - 1).'?) AND `type` = ? ORDER BY `category`'; |
|
59 | 59 | return $this->findEntities($sql, array_merge($owners, array($type))); |
60 | 60 | } |
61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return bool |
67 | 67 | */ |
68 | 68 | public function tagExists($tag) { |
69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `'.$this->getTableName().'` ' |
|
70 | 70 | . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
71 | 71 | try { |
72 | 72 | $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
@@ -33,47 +33,47 @@ |
||
33 | 33 | */ |
34 | 34 | class TagMapper extends Mapper { |
35 | 35 | |
36 | - /** |
|
37 | - * Constructor. |
|
38 | - * |
|
39 | - * @param IDBConnection $db Instance of the Db abstraction layer. |
|
40 | - */ |
|
41 | - public function __construct(IDBConnection $db) { |
|
42 | - parent::__construct($db, 'vcategory', Tag::class); |
|
43 | - } |
|
36 | + /** |
|
37 | + * Constructor. |
|
38 | + * |
|
39 | + * @param IDBConnection $db Instance of the Db abstraction layer. |
|
40 | + */ |
|
41 | + public function __construct(IDBConnection $db) { |
|
42 | + parent::__construct($db, 'vcategory', Tag::class); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Load tags from the database. |
|
47 | - * |
|
48 | - * @param array|string $owners The user(s) whose tags we are going to load. |
|
49 | - * @param string $type The type of item for which we are loading tags. |
|
50 | - * @return array An array of Tag objects. |
|
51 | - */ |
|
52 | - public function loadTags($owners, $type) { |
|
53 | - if(!is_array($owners)) { |
|
54 | - $owners = array($owners); |
|
55 | - } |
|
45 | + /** |
|
46 | + * Load tags from the database. |
|
47 | + * |
|
48 | + * @param array|string $owners The user(s) whose tags we are going to load. |
|
49 | + * @param string $type The type of item for which we are loading tags. |
|
50 | + * @return array An array of Tag objects. |
|
51 | + */ |
|
52 | + public function loadTags($owners, $type) { |
|
53 | + if(!is_array($owners)) { |
|
54 | + $owners = array($owners); |
|
55 | + } |
|
56 | 56 | |
57 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | - . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
59 | - return $this->findEntities($sql, array_merge($owners, array($type))); |
|
60 | - } |
|
57 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
58 | + . 'WHERE `uid` IN (' . str_repeat('?,', count($owners)-1) . '?) AND `type` = ? ORDER BY `category`'; |
|
59 | + return $this->findEntities($sql, array_merge($owners, array($type))); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Check if a given Tag object already exists in the database. |
|
64 | - * |
|
65 | - * @param Tag $tag The tag to look for in the database. |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function tagExists($tag) { |
|
69 | - $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
70 | - . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
71 | - try { |
|
72 | - $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
73 | - } catch (DoesNotExistException $e) { |
|
74 | - return false; |
|
75 | - } |
|
76 | - return true; |
|
77 | - } |
|
62 | + /** |
|
63 | + * Check if a given Tag object already exists in the database. |
|
64 | + * |
|
65 | + * @param Tag $tag The tag to look for in the database. |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function tagExists($tag) { |
|
69 | + $sql = 'SELECT `id`, `uid`, `type`, `category` FROM `' . $this->getTableName() . '` ' |
|
70 | + . 'WHERE `uid` = ? AND `type` = ? AND `category` = ?'; |
|
71 | + try { |
|
72 | + $this->findEntity($sql, array($tag->getOwner(), $tag->getType(), $tag->getName())); |
|
73 | + } catch (DoesNotExistException $e) { |
|
74 | + return false; |
|
75 | + } |
|
76 | + return true; |
|
77 | + } |
|
78 | 78 | } |
79 | 79 |
@@ -37,54 +37,54 @@ |
||
37 | 37 | */ |
38 | 38 | class Tag extends Entity { |
39 | 39 | |
40 | - protected $owner; |
|
41 | - protected $type; |
|
42 | - protected $name; |
|
40 | + protected $owner; |
|
41 | + protected $type; |
|
42 | + protected $name; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Constructor. |
|
46 | - * |
|
47 | - * @param string $owner The tag's owner |
|
48 | - * @param string $type The type of item this tag is used for |
|
49 | - * @param string $name The tag's name |
|
50 | - */ |
|
51 | - public function __construct($owner = null, $type = null, $name = null) { |
|
52 | - $this->setOwner($owner); |
|
53 | - $this->setType($type); |
|
54 | - $this->setName($name); |
|
55 | - } |
|
44 | + /** |
|
45 | + * Constructor. |
|
46 | + * |
|
47 | + * @param string $owner The tag's owner |
|
48 | + * @param string $type The type of item this tag is used for |
|
49 | + * @param string $name The tag's name |
|
50 | + */ |
|
51 | + public function __construct($owner = null, $type = null, $name = null) { |
|
52 | + $this->setOwner($owner); |
|
53 | + $this->setType($type); |
|
54 | + $this->setName($name); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Transform a database columnname to a property |
|
59 | - * |
|
60 | - * @param string $columnName the name of the column |
|
61 | - * @return string the property name |
|
62 | - * @todo migrate existing database columns to the correct names |
|
63 | - * to be able to drop this direct mapping |
|
64 | - */ |
|
65 | - public function columnToProperty($columnName){ |
|
66 | - if ($columnName === 'category') { |
|
67 | - return 'name'; |
|
68 | - } elseif ($columnName === 'uid') { |
|
69 | - return 'owner'; |
|
70 | - } else { |
|
71 | - return parent::columnToProperty($columnName); |
|
72 | - } |
|
73 | - } |
|
57 | + /** |
|
58 | + * Transform a database columnname to a property |
|
59 | + * |
|
60 | + * @param string $columnName the name of the column |
|
61 | + * @return string the property name |
|
62 | + * @todo migrate existing database columns to the correct names |
|
63 | + * to be able to drop this direct mapping |
|
64 | + */ |
|
65 | + public function columnToProperty($columnName){ |
|
66 | + if ($columnName === 'category') { |
|
67 | + return 'name'; |
|
68 | + } elseif ($columnName === 'uid') { |
|
69 | + return 'owner'; |
|
70 | + } else { |
|
71 | + return parent::columnToProperty($columnName); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Transform a property to a database column name |
|
77 | - * |
|
78 | - * @param string $property the name of the property |
|
79 | - * @return string the column name |
|
80 | - */ |
|
81 | - public function propertyToColumn($property){ |
|
82 | - if ($property === 'name') { |
|
83 | - return 'category'; |
|
84 | - } elseif ($property === 'owner') { |
|
85 | - return 'uid'; |
|
86 | - } else { |
|
87 | - return parent::propertyToColumn($property); |
|
88 | - } |
|
89 | - } |
|
75 | + /** |
|
76 | + * Transform a property to a database column name |
|
77 | + * |
|
78 | + * @param string $property the name of the property |
|
79 | + * @return string the column name |
|
80 | + */ |
|
81 | + public function propertyToColumn($property){ |
|
82 | + if ($property === 'name') { |
|
83 | + return 'category'; |
|
84 | + } elseif ($property === 'owner') { |
|
85 | + return 'uid'; |
|
86 | + } else { |
|
87 | + return parent::propertyToColumn($property); |
|
88 | + } |
|
89 | + } |
|
90 | 90 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @todo migrate existing database columns to the correct names |
63 | 63 | * to be able to drop this direct mapping |
64 | 64 | */ |
65 | - public function columnToProperty($columnName){ |
|
65 | + public function columnToProperty($columnName) { |
|
66 | 66 | if ($columnName === 'category') { |
67 | 67 | return 'name'; |
68 | 68 | } elseif ($columnName === 'uid') { |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param string $property the name of the property |
79 | 79 | * @return string the column name |
80 | 80 | */ |
81 | - public function propertyToColumn($property){ |
|
81 | + public function propertyToColumn($property) { |
|
82 | 82 | if ($property === 'name') { |
83 | 83 | return 'category'; |
84 | 84 | } elseif ($property === 'owner') { |
@@ -41,10 +41,10 @@ discard block |
||
41 | 41 | public function search($pattern, $searchProperties = array(), $options = array()) { |
42 | 42 | $this->loadAddressBooks(); |
43 | 43 | $result = array(); |
44 | - foreach($this->addressBooks as $addressBook) { |
|
44 | + foreach ($this->addressBooks as $addressBook) { |
|
45 | 45 | $r = $addressBook->search($pattern, $searchProperties, $options); |
46 | 46 | $contacts = array(); |
47 | - foreach($r as $c){ |
|
47 | + foreach ($r as $c) { |
|
48 | 48 | $c['addressbook-key'] = $addressBook->getKey(); |
49 | 49 | $contacts[] = $c; |
50 | 50 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | public function getAddressBooks() { |
125 | 125 | $this->loadAddressBooks(); |
126 | 126 | $result = array(); |
127 | - foreach($this->addressBooks as $addressBook) { |
|
127 | + foreach ($this->addressBooks as $addressBook) { |
|
128 | 128 | $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
129 | 129 | } |
130 | 130 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | */ |
182 | 182 | protected function loadAddressBooks() |
183 | 183 | { |
184 | - foreach($this->addressBookLoaders as $callable) { |
|
184 | + foreach ($this->addressBookLoaders as $callable) { |
|
185 | 185 | $callable($this); |
186 | 186 | } |
187 | 187 | $this->addressBookLoaders = array(); |
@@ -27,180 +27,180 @@ |
||
27 | 27 | |
28 | 28 | namespace OC { |
29 | 29 | |
30 | - class ContactsManager implements \OCP\Contacts\IManager { |
|
31 | - |
|
32 | - /** |
|
33 | - * This function is used to search and find contacts within the users address books. |
|
34 | - * In case $pattern is empty all contacts will be returned. |
|
35 | - * |
|
36 | - * @param string $pattern which should match within the $searchProperties |
|
37 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
38 | - * @param array $options - for future use. One should always have options! |
|
39 | - * @return array an array of contacts which are arrays of key-value-pairs |
|
40 | - */ |
|
41 | - public function search($pattern, $searchProperties = array(), $options = array()) { |
|
42 | - $this->loadAddressBooks(); |
|
43 | - $result = array(); |
|
44 | - foreach($this->addressBooks as $addressBook) { |
|
45 | - $r = $addressBook->search($pattern, $searchProperties, $options); |
|
46 | - $contacts = array(); |
|
47 | - foreach($r as $c){ |
|
48 | - $c['addressbook-key'] = $addressBook->getKey(); |
|
49 | - $contacts[] = $c; |
|
50 | - } |
|
51 | - $result = array_merge($result, $contacts); |
|
52 | - } |
|
53 | - |
|
54 | - return $result; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * This function can be used to delete the contact identified by the given id |
|
59 | - * |
|
60 | - * @param object $id the unique identifier to a contact |
|
61 | - * @param string $addressBookKey identifier of the address book in which the contact shall be deleted |
|
62 | - * @return bool successful or not |
|
63 | - */ |
|
64 | - public function delete($id, $addressBookKey) { |
|
65 | - $addressBook = $this->getAddressBook($addressBookKey); |
|
66 | - if (!$addressBook) { |
|
67 | - return null; |
|
68 | - } |
|
69 | - |
|
70 | - if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
71 | - return $addressBook->delete($id); |
|
72 | - } |
|
73 | - |
|
74 | - return null; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * This function is used to create a new contact if 'id' is not given or not present. |
|
79 | - * Otherwise the contact will be updated by replacing the entire data set. |
|
80 | - * |
|
81 | - * @param array $properties this array if key-value-pairs defines a contact |
|
82 | - * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated |
|
83 | - * @return array representing the contact just created or updated |
|
84 | - */ |
|
85 | - public function createOrUpdate($properties, $addressBookKey) { |
|
86 | - $addressBook = $this->getAddressBook($addressBookKey); |
|
87 | - if (!$addressBook) { |
|
88 | - return null; |
|
89 | - } |
|
90 | - |
|
91 | - if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
92 | - return $addressBook->createOrUpdate($properties); |
|
93 | - } |
|
94 | - |
|
95 | - return null; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Check if contacts are available (e.g. contacts app enabled) |
|
100 | - * |
|
101 | - * @return bool true if enabled, false if not |
|
102 | - */ |
|
103 | - public function isEnabled() { |
|
104 | - return !empty($this->addressBooks) || !empty($this->addressBookLoaders); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param \OCP\IAddressBook $addressBook |
|
109 | - */ |
|
110 | - public function registerAddressBook(\OCP\IAddressBook $addressBook) { |
|
111 | - $this->addressBooks[$addressBook->getKey()] = $addressBook; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param \OCP\IAddressBook $addressBook |
|
116 | - */ |
|
117 | - public function unregisterAddressBook(\OCP\IAddressBook $addressBook) { |
|
118 | - unset($this->addressBooks[$addressBook->getKey()]); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Return a list of the user's addressbooks display names |
|
123 | - * ! The addressBook displayName are not unique, please use getUserAddressBooks |
|
124 | - * |
|
125 | - * @return array |
|
126 | - * @since 6.0.0 |
|
127 | - * @deprecated 16.0.0 - Use `$this->getUserAddressBooks()` instead |
|
128 | - */ |
|
129 | - public function getAddressBooks() { |
|
130 | - $this->loadAddressBooks(); |
|
131 | - $result = array(); |
|
132 | - foreach($this->addressBooks as $addressBook) { |
|
133 | - $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
|
134 | - } |
|
135 | - |
|
136 | - return $result; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Return a list of the user's addressbooks |
|
141 | - * |
|
142 | - * @return IAddressBook[] |
|
143 | - * @since 16.0.0 |
|
144 | - */ |
|
145 | - public function getUserAddressBooks(): Array { |
|
146 | - $this->loadAddressBooks(); |
|
147 | - return $this->addressBooks; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * removes all registered address book instances |
|
152 | - */ |
|
153 | - public function clear() { |
|
154 | - $this->addressBooks = array(); |
|
155 | - $this->addressBookLoaders = array(); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @var \OCP\IAddressBook[] which holds all registered address books |
|
160 | - */ |
|
161 | - private $addressBooks = array(); |
|
162 | - |
|
163 | - /** |
|
164 | - * @var \Closure[] to call to load/register address books |
|
165 | - */ |
|
166 | - private $addressBookLoaders = array(); |
|
167 | - |
|
168 | - /** |
|
169 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
170 | - * address books are actually requested |
|
171 | - * |
|
172 | - * @param \Closure $callable |
|
173 | - */ |
|
174 | - public function register(\Closure $callable) |
|
175 | - { |
|
176 | - $this->addressBookLoaders[] = $callable; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Get (and load when needed) the address book for $key |
|
181 | - * |
|
182 | - * @param string $addressBookKey |
|
183 | - * @return \OCP\IAddressBook |
|
184 | - */ |
|
185 | - protected function getAddressBook($addressBookKey) |
|
186 | - { |
|
187 | - $this->loadAddressBooks(); |
|
188 | - if (!array_key_exists($addressBookKey, $this->addressBooks)) { |
|
189 | - return null; |
|
190 | - } |
|
191 | - |
|
192 | - return $this->addressBooks[$addressBookKey]; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Load all address books registered with 'register' |
|
197 | - */ |
|
198 | - protected function loadAddressBooks() |
|
199 | - { |
|
200 | - foreach($this->addressBookLoaders as $callable) { |
|
201 | - $callable($this); |
|
202 | - } |
|
203 | - $this->addressBookLoaders = array(); |
|
204 | - } |
|
205 | - } |
|
30 | + class ContactsManager implements \OCP\Contacts\IManager { |
|
31 | + |
|
32 | + /** |
|
33 | + * This function is used to search and find contacts within the users address books. |
|
34 | + * In case $pattern is empty all contacts will be returned. |
|
35 | + * |
|
36 | + * @param string $pattern which should match within the $searchProperties |
|
37 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
38 | + * @param array $options - for future use. One should always have options! |
|
39 | + * @return array an array of contacts which are arrays of key-value-pairs |
|
40 | + */ |
|
41 | + public function search($pattern, $searchProperties = array(), $options = array()) { |
|
42 | + $this->loadAddressBooks(); |
|
43 | + $result = array(); |
|
44 | + foreach($this->addressBooks as $addressBook) { |
|
45 | + $r = $addressBook->search($pattern, $searchProperties, $options); |
|
46 | + $contacts = array(); |
|
47 | + foreach($r as $c){ |
|
48 | + $c['addressbook-key'] = $addressBook->getKey(); |
|
49 | + $contacts[] = $c; |
|
50 | + } |
|
51 | + $result = array_merge($result, $contacts); |
|
52 | + } |
|
53 | + |
|
54 | + return $result; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * This function can be used to delete the contact identified by the given id |
|
59 | + * |
|
60 | + * @param object $id the unique identifier to a contact |
|
61 | + * @param string $addressBookKey identifier of the address book in which the contact shall be deleted |
|
62 | + * @return bool successful or not |
|
63 | + */ |
|
64 | + public function delete($id, $addressBookKey) { |
|
65 | + $addressBook = $this->getAddressBook($addressBookKey); |
|
66 | + if (!$addressBook) { |
|
67 | + return null; |
|
68 | + } |
|
69 | + |
|
70 | + if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_DELETE) { |
|
71 | + return $addressBook->delete($id); |
|
72 | + } |
|
73 | + |
|
74 | + return null; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * This function is used to create a new contact if 'id' is not given or not present. |
|
79 | + * Otherwise the contact will be updated by replacing the entire data set. |
|
80 | + * |
|
81 | + * @param array $properties this array if key-value-pairs defines a contact |
|
82 | + * @param string $addressBookKey identifier of the address book in which the contact shall be created or updated |
|
83 | + * @return array representing the contact just created or updated |
|
84 | + */ |
|
85 | + public function createOrUpdate($properties, $addressBookKey) { |
|
86 | + $addressBook = $this->getAddressBook($addressBookKey); |
|
87 | + if (!$addressBook) { |
|
88 | + return null; |
|
89 | + } |
|
90 | + |
|
91 | + if ($addressBook->getPermissions() & \OCP\Constants::PERMISSION_CREATE) { |
|
92 | + return $addressBook->createOrUpdate($properties); |
|
93 | + } |
|
94 | + |
|
95 | + return null; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Check if contacts are available (e.g. contacts app enabled) |
|
100 | + * |
|
101 | + * @return bool true if enabled, false if not |
|
102 | + */ |
|
103 | + public function isEnabled() { |
|
104 | + return !empty($this->addressBooks) || !empty($this->addressBookLoaders); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param \OCP\IAddressBook $addressBook |
|
109 | + */ |
|
110 | + public function registerAddressBook(\OCP\IAddressBook $addressBook) { |
|
111 | + $this->addressBooks[$addressBook->getKey()] = $addressBook; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param \OCP\IAddressBook $addressBook |
|
116 | + */ |
|
117 | + public function unregisterAddressBook(\OCP\IAddressBook $addressBook) { |
|
118 | + unset($this->addressBooks[$addressBook->getKey()]); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Return a list of the user's addressbooks display names |
|
123 | + * ! The addressBook displayName are not unique, please use getUserAddressBooks |
|
124 | + * |
|
125 | + * @return array |
|
126 | + * @since 6.0.0 |
|
127 | + * @deprecated 16.0.0 - Use `$this->getUserAddressBooks()` instead |
|
128 | + */ |
|
129 | + public function getAddressBooks() { |
|
130 | + $this->loadAddressBooks(); |
|
131 | + $result = array(); |
|
132 | + foreach($this->addressBooks as $addressBook) { |
|
133 | + $result[$addressBook->getKey()] = $addressBook->getDisplayName(); |
|
134 | + } |
|
135 | + |
|
136 | + return $result; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Return a list of the user's addressbooks |
|
141 | + * |
|
142 | + * @return IAddressBook[] |
|
143 | + * @since 16.0.0 |
|
144 | + */ |
|
145 | + public function getUserAddressBooks(): Array { |
|
146 | + $this->loadAddressBooks(); |
|
147 | + return $this->addressBooks; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * removes all registered address book instances |
|
152 | + */ |
|
153 | + public function clear() { |
|
154 | + $this->addressBooks = array(); |
|
155 | + $this->addressBookLoaders = array(); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @var \OCP\IAddressBook[] which holds all registered address books |
|
160 | + */ |
|
161 | + private $addressBooks = array(); |
|
162 | + |
|
163 | + /** |
|
164 | + * @var \Closure[] to call to load/register address books |
|
165 | + */ |
|
166 | + private $addressBookLoaders = array(); |
|
167 | + |
|
168 | + /** |
|
169 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
170 | + * address books are actually requested |
|
171 | + * |
|
172 | + * @param \Closure $callable |
|
173 | + */ |
|
174 | + public function register(\Closure $callable) |
|
175 | + { |
|
176 | + $this->addressBookLoaders[] = $callable; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Get (and load when needed) the address book for $key |
|
181 | + * |
|
182 | + * @param string $addressBookKey |
|
183 | + * @return \OCP\IAddressBook |
|
184 | + */ |
|
185 | + protected function getAddressBook($addressBookKey) |
|
186 | + { |
|
187 | + $this->loadAddressBooks(); |
|
188 | + if (!array_key_exists($addressBookKey, $this->addressBooks)) { |
|
189 | + return null; |
|
190 | + } |
|
191 | + |
|
192 | + return $this->addressBooks[$addressBookKey]; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Load all address books registered with 'register' |
|
197 | + */ |
|
198 | + protected function loadAddressBooks() |
|
199 | + { |
|
200 | + foreach($this->addressBookLoaders as $callable) { |
|
201 | + $callable($this); |
|
202 | + } |
|
203 | + $this->addressBookLoaders = array(); |
|
204 | + } |
|
205 | + } |
|
206 | 206 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | if ($command instanceof ICommand) { |
56 | 56 | // ensure the command can be serialized |
57 | 57 | $serialized = serialize($command); |
58 | - if(strlen($serialized) > 4000) { |
|
58 | + if (strlen($serialized) > 4000) { |
|
59 | 59 | throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
60 | 60 | } |
61 | 61 | $unserialized = unserialize($serialized); |
@@ -26,48 +26,48 @@ |
||
26 | 26 | use OCP\Command\ICommand; |
27 | 27 | |
28 | 28 | class QueueBus implements IBus { |
29 | - /** |
|
30 | - * @var ICommand[]|callable[] |
|
31 | - */ |
|
32 | - private $queue = []; |
|
29 | + /** |
|
30 | + * @var ICommand[]|callable[] |
|
31 | + */ |
|
32 | + private $queue = []; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Schedule a command to be fired |
|
36 | - * |
|
37 | - * @param \OCP\Command\ICommand | callable $command |
|
38 | - */ |
|
39 | - public function push($command) { |
|
40 | - $this->queue[] = $command; |
|
41 | - } |
|
34 | + /** |
|
35 | + * Schedule a command to be fired |
|
36 | + * |
|
37 | + * @param \OCP\Command\ICommand | callable $command |
|
38 | + */ |
|
39 | + public function push($command) { |
|
40 | + $this->queue[] = $command; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Require all commands using a trait to be run synchronous |
|
45 | - * |
|
46 | - * @param string $trait |
|
47 | - */ |
|
48 | - public function requireSync($trait) { |
|
49 | - } |
|
43 | + /** |
|
44 | + * Require all commands using a trait to be run synchronous |
|
45 | + * |
|
46 | + * @param string $trait |
|
47 | + */ |
|
48 | + public function requireSync($trait) { |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param \OCP\Command\ICommand | callable $command |
|
53 | - */ |
|
54 | - private function runCommand($command) { |
|
55 | - if ($command instanceof ICommand) { |
|
56 | - // ensure the command can be serialized |
|
57 | - $serialized = serialize($command); |
|
58 | - if(strlen($serialized) > 4000) { |
|
59 | - throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
|
60 | - } |
|
61 | - $unserialized = unserialize($serialized); |
|
62 | - $unserialized->handle(); |
|
63 | - } else { |
|
64 | - $command(); |
|
65 | - } |
|
66 | - } |
|
51 | + /** |
|
52 | + * @param \OCP\Command\ICommand | callable $command |
|
53 | + */ |
|
54 | + private function runCommand($command) { |
|
55 | + if ($command instanceof ICommand) { |
|
56 | + // ensure the command can be serialized |
|
57 | + $serialized = serialize($command); |
|
58 | + if(strlen($serialized) > 4000) { |
|
59 | + throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
|
60 | + } |
|
61 | + $unserialized = unserialize($serialized); |
|
62 | + $unserialized->handle(); |
|
63 | + } else { |
|
64 | + $command(); |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - public function run() { |
|
69 | - while ($command = array_shift($this->queue)) { |
|
70 | - $this->runCommand($command); |
|
71 | - } |
|
72 | - } |
|
68 | + public function run() { |
|
69 | + while ($command = array_shift($this->queue)) { |
|
70 | + $this->runCommand($command); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | } |