@@ -32,33 +32,33 @@ |
||
32 | 32 | |
33 | 33 | class UpdateTheme extends UpdateJS { |
34 | 34 | |
35 | - /** @var IMimeTypeDetector */ |
|
36 | - protected $mimetypeDetector; |
|
35 | + /** @var IMimeTypeDetector */ |
|
36 | + protected $mimetypeDetector; |
|
37 | 37 | |
38 | - /** @var ICacheFactory */ |
|
39 | - protected $cacheFactory; |
|
38 | + /** @var ICacheFactory */ |
|
39 | + protected $cacheFactory; |
|
40 | 40 | |
41 | - public function __construct( |
|
42 | - IMimeTypeDetector $mimetypeDetector, |
|
43 | - ICacheFactory $cacheFactory |
|
44 | - ) { |
|
45 | - parent::__construct($mimetypeDetector); |
|
46 | - $this->cacheFactory = $cacheFactory; |
|
47 | - } |
|
41 | + public function __construct( |
|
42 | + IMimeTypeDetector $mimetypeDetector, |
|
43 | + ICacheFactory $cacheFactory |
|
44 | + ) { |
|
45 | + parent::__construct($mimetypeDetector); |
|
46 | + $this->cacheFactory = $cacheFactory; |
|
47 | + } |
|
48 | 48 | |
49 | - protected function configure() { |
|
50 | - $this |
|
51 | - ->setName('maintenance:theme:update') |
|
52 | - ->setDescription('Apply custom theme changes'); |
|
53 | - } |
|
49 | + protected function configure() { |
|
50 | + $this |
|
51 | + ->setName('maintenance:theme:update') |
|
52 | + ->setDescription('Apply custom theme changes'); |
|
53 | + } |
|
54 | 54 | |
55 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | - // run mimetypelist.js update since themes might change mimetype icons |
|
57 | - parent::execute($input, $output); |
|
55 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | + // run mimetypelist.js update since themes might change mimetype icons |
|
57 | + parent::execute($input, $output); |
|
58 | 58 | |
59 | - // cleanup image cache |
|
60 | - $c = $this->cacheFactory->createDistributed('imagePath'); |
|
61 | - $c->clear(''); |
|
62 | - $output->writeln('<info>Image cache cleared'); |
|
63 | - } |
|
59 | + // cleanup image cache |
|
60 | + $c = $this->cacheFactory->createDistributed('imagePath'); |
|
61 | + $c->clear(''); |
|
62 | + $output->writeln('<info>Image cache cleared'); |
|
63 | + } |
|
64 | 64 | } |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | require '../../../../3rdparty/autoload.php'; |
24 | 24 | |
25 | 25 | if ($argc !== 6) { |
26 | - echo "Invalid number of arguments" . PHP_EOL; |
|
27 | - exit; |
|
26 | + echo "Invalid number of arguments" . PHP_EOL; |
|
27 | + exit; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | * @return mixed |
34 | 34 | */ |
35 | 35 | function request($client, $method, $uploadUrl, $data = null, $headers = []) { |
36 | - echo "$method $uploadUrl ... "; |
|
37 | - $t0 = microtime(true); |
|
38 | - $result = $client->request($method, $uploadUrl, $data, $headers); |
|
39 | - $t1 = microtime(true); |
|
40 | - echo $result['statusCode'] . " - " . ($t1 - $t0) . ' seconds' . PHP_EOL; |
|
41 | - if (!in_array($result['statusCode'], [200, 201])) { |
|
42 | - echo $result['body'] . PHP_EOL; |
|
43 | - } |
|
44 | - return $result; |
|
36 | + echo "$method $uploadUrl ... "; |
|
37 | + $t0 = microtime(true); |
|
38 | + $result = $client->request($method, $uploadUrl, $data, $headers); |
|
39 | + $t1 = microtime(true); |
|
40 | + echo $result['statusCode'] . " - " . ($t1 - $t0) . ' seconds' . PHP_EOL; |
|
41 | + if (!in_array($result['statusCode'], [200, 201])) { |
|
42 | + echo $result['body'] . PHP_EOL; |
|
43 | + } |
|
44 | + return $result; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | $baseUri = $argv[1]; |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | $chunkSize = $argv[5] * 1024 * 1024; |
52 | 52 | |
53 | 53 | $client = new \Sabre\DAV\Client([ |
54 | - 'baseUri' => $baseUri, |
|
55 | - 'userName' => $userName, |
|
56 | - 'password' => $password |
|
54 | + 'baseUri' => $baseUri, |
|
55 | + 'userName' => $userName, |
|
56 | + 'password' => $password |
|
57 | 57 | ]); |
58 | 58 | |
59 | 59 | $transfer = uniqid('transfer', true); |
@@ -66,14 +66,14 @@ discard block |
||
66 | 66 | |
67 | 67 | $index = 0; |
68 | 68 | while(!feof($stream)) { |
69 | - request($client, 'PUT', "$uploadUrl/$index", fread($stream, $chunkSize)); |
|
70 | - $index++; |
|
69 | + request($client, 'PUT', "$uploadUrl/$index", fread($stream, $chunkSize)); |
|
70 | + $index++; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | $destination = pathinfo($file, PATHINFO_BASENAME); |
74 | 74 | //echo "Moving $uploadUrl/.file to it's final destination $baseUri/files/$userName/$destination" . PHP_EOL; |
75 | 75 | request($client, 'MOVE', "$uploadUrl/.file", null, [ |
76 | - 'Destination' => "$baseUri/files/$userName/$destination", |
|
77 | - 'OC-Total-Length' => filesize($file), |
|
78 | - 'X-OC-MTime' => filemtime($file) |
|
76 | + 'Destination' => "$baseUri/files/$userName/$destination", |
|
77 | + 'OC-Total-Length' => filesize($file), |
|
78 | + 'X-OC-MTime' => filemtime($file) |
|
79 | 79 | ]); |
@@ -14,191 +14,191 @@ |
||
14 | 14 | */ |
15 | 15 | class S3Signature implements SignatureInterface |
16 | 16 | { |
17 | - /** @var array Query string values that must be signed */ |
|
18 | - private $signableQueryString = [ |
|
19 | - 'acl', 'cors', 'delete', 'lifecycle', 'location', 'logging', |
|
20 | - 'notification', 'partNumber', 'policy', 'requestPayment', |
|
21 | - 'response-cache-control', 'response-content-disposition', |
|
22 | - 'response-content-encoding', 'response-content-language', |
|
23 | - 'response-content-type', 'response-expires', 'restore', 'tagging', |
|
24 | - 'torrent', 'uploadId', 'uploads', 'versionId', 'versioning', |
|
25 | - 'versions', 'website' |
|
26 | - ]; |
|
27 | - |
|
28 | - /** @var array Sorted headers that must be signed */ |
|
29 | - private $signableHeaders = ['Content-MD5', 'Content-Type']; |
|
30 | - |
|
31 | - /** @var \Aws\S3\S3UriParser S3 URI parser */ |
|
32 | - private $parser; |
|
33 | - |
|
34 | - public function __construct() |
|
35 | - { |
|
36 | - $this->parser = new S3UriParser(); |
|
37 | - // Ensure that the signable query string parameters are sorted |
|
38 | - sort($this->signableQueryString); |
|
39 | - } |
|
40 | - |
|
41 | - public function signRequest( |
|
42 | - RequestInterface $request, |
|
43 | - CredentialsInterface $credentials |
|
44 | - ) { |
|
45 | - $request = $this->prepareRequest($request, $credentials); |
|
46 | - $stringToSign = $this->createCanonicalizedString($request); |
|
47 | - $auth = 'AWS ' |
|
48 | - . $credentials->getAccessKeyId() . ':' |
|
49 | - . $this->signString($stringToSign, $credentials); |
|
50 | - |
|
51 | - return $request->withHeader('Authorization', $auth); |
|
52 | - } |
|
53 | - |
|
54 | - public function presign( |
|
55 | - RequestInterface $request, |
|
56 | - CredentialsInterface $credentials, |
|
57 | - $expires |
|
58 | - ) { |
|
59 | - $query = []; |
|
60 | - // URL encoding already occurs in the URI template expansion. Undo that |
|
61 | - // and encode using the same encoding as GET object, PUT object, etc. |
|
62 | - $uri = $request->getUri(); |
|
63 | - $path = S3Client::encodeKey(rawurldecode($uri->getPath())); |
|
64 | - $request = $request->withUri($uri->withPath($path)); |
|
65 | - |
|
66 | - // Make sure to handle temporary credentials |
|
67 | - if ($token = $credentials->getSecurityToken()) { |
|
68 | - $request = $request->withHeader('X-Amz-Security-Token', $token); |
|
69 | - $query['X-Amz-Security-Token'] = $token; |
|
70 | - } |
|
71 | - |
|
72 | - if ($expires instanceof \DateTime) { |
|
73 | - $expires = $expires->getTimestamp(); |
|
74 | - } elseif (!is_numeric($expires)) { |
|
75 | - $expires = strtotime($expires); |
|
76 | - } |
|
77 | - |
|
78 | - // Set query params required for pre-signed URLs |
|
79 | - $query['AWSAccessKeyId'] = $credentials->getAccessKeyId(); |
|
80 | - $query['Expires'] = $expires; |
|
81 | - $query['Signature'] = $this->signString( |
|
82 | - $this->createCanonicalizedString($request, $expires), |
|
83 | - $credentials |
|
84 | - ); |
|
85 | - |
|
86 | - // Move X-Amz-* headers to the query string |
|
87 | - foreach ($request->getHeaders() as $name => $header) { |
|
88 | - $name = strtolower($name); |
|
89 | - if (strpos($name, 'x-amz-') === 0) { |
|
90 | - $query[$name] = implode(',', $header); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - $queryString = http_build_query($query, null, '&', PHP_QUERY_RFC3986); |
|
95 | - |
|
96 | - return $request->withUri($request->getUri()->withQuery($queryString)); |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param RequestInterface $request |
|
101 | - * @param CredentialsInterface $creds |
|
102 | - * |
|
103 | - * @return RequestInterface |
|
104 | - */ |
|
105 | - private function prepareRequest( |
|
106 | - RequestInterface $request, |
|
107 | - CredentialsInterface $creds |
|
108 | - ) { |
|
109 | - $modify = [ |
|
110 | - 'remove_headers' => ['X-Amz-Date'], |
|
111 | - 'set_headers' => ['Date' => gmdate(\DateTime::RFC2822)] |
|
112 | - ]; |
|
113 | - |
|
114 | - // Add the security token header if one is being used by the credentials |
|
115 | - if ($token = $creds->getSecurityToken()) { |
|
116 | - $modify['set_headers']['X-Amz-Security-Token'] = $token; |
|
117 | - } |
|
118 | - |
|
119 | - return Psr7\modify_request($request, $modify); |
|
120 | - } |
|
121 | - |
|
122 | - private function signString($string, CredentialsInterface $credentials) |
|
123 | - { |
|
124 | - return base64_encode( |
|
125 | - hash_hmac('sha1', $string, $credentials->getSecretKey(), true) |
|
126 | - ); |
|
127 | - } |
|
128 | - |
|
129 | - private function createCanonicalizedString( |
|
130 | - RequestInterface $request, |
|
131 | - $expires = null |
|
132 | - ) { |
|
133 | - $buffer = $request->getMethod() . "\n"; |
|
134 | - |
|
135 | - // Add the interesting headers |
|
136 | - foreach ($this->signableHeaders as $header) { |
|
137 | - $buffer .= $request->getHeaderLine($header) . "\n"; |
|
138 | - } |
|
139 | - |
|
140 | - $date = $expires ?: $request->getHeaderLine('date'); |
|
141 | - $buffer .= "{$date}\n" |
|
142 | - . $this->createCanonicalizedAmzHeaders($request) |
|
143 | - . $this->createCanonicalizedResource($request); |
|
144 | - |
|
145 | - return $buffer; |
|
146 | - } |
|
147 | - |
|
148 | - private function createCanonicalizedAmzHeaders(RequestInterface $request) |
|
149 | - { |
|
150 | - $headers = []; |
|
151 | - foreach ($request->getHeaders() as $name => $header) { |
|
152 | - $name = strtolower($name); |
|
153 | - if (strpos($name, 'x-amz-') === 0) { |
|
154 | - $value = implode(',', $header); |
|
155 | - if (strlen($value) > 0) { |
|
156 | - $headers[$name] = $name . ':' . $value; |
|
157 | - } |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - if (!$headers) { |
|
162 | - return ''; |
|
163 | - } |
|
164 | - |
|
165 | - ksort($headers); |
|
166 | - |
|
167 | - return implode("\n", $headers) . "\n"; |
|
168 | - } |
|
169 | - |
|
170 | - private function createCanonicalizedResource(RequestInterface $request) |
|
171 | - { |
|
172 | - $data = $this->parser->parse($request->getUri()); |
|
173 | - $buffer = '/'; |
|
174 | - |
|
175 | - if ($data['bucket']) { |
|
176 | - $buffer .= $data['bucket']; |
|
177 | - if (!empty($data['key']) || !$data['path_style']) { |
|
178 | - $buffer .= '/' . $data['key']; |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - // Add sub resource parameters if present. |
|
183 | - $query = $request->getUri()->getQuery(); |
|
184 | - |
|
185 | - if ($query) { |
|
186 | - $params = Psr7\parse_query($query); |
|
187 | - $first = true; |
|
188 | - foreach ($this->signableQueryString as $key) { |
|
189 | - if (array_key_exists($key, $params)) { |
|
190 | - $value = $params[$key]; |
|
191 | - $buffer .= $first ? '?' : '&'; |
|
192 | - $first = false; |
|
193 | - $buffer .= $key; |
|
194 | - // Don't add values for empty sub-resources |
|
195 | - if (strlen($value)) { |
|
196 | - $buffer .= "={$value}"; |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - return $buffer; |
|
203 | - } |
|
17 | + /** @var array Query string values that must be signed */ |
|
18 | + private $signableQueryString = [ |
|
19 | + 'acl', 'cors', 'delete', 'lifecycle', 'location', 'logging', |
|
20 | + 'notification', 'partNumber', 'policy', 'requestPayment', |
|
21 | + 'response-cache-control', 'response-content-disposition', |
|
22 | + 'response-content-encoding', 'response-content-language', |
|
23 | + 'response-content-type', 'response-expires', 'restore', 'tagging', |
|
24 | + 'torrent', 'uploadId', 'uploads', 'versionId', 'versioning', |
|
25 | + 'versions', 'website' |
|
26 | + ]; |
|
27 | + |
|
28 | + /** @var array Sorted headers that must be signed */ |
|
29 | + private $signableHeaders = ['Content-MD5', 'Content-Type']; |
|
30 | + |
|
31 | + /** @var \Aws\S3\S3UriParser S3 URI parser */ |
|
32 | + private $parser; |
|
33 | + |
|
34 | + public function __construct() |
|
35 | + { |
|
36 | + $this->parser = new S3UriParser(); |
|
37 | + // Ensure that the signable query string parameters are sorted |
|
38 | + sort($this->signableQueryString); |
|
39 | + } |
|
40 | + |
|
41 | + public function signRequest( |
|
42 | + RequestInterface $request, |
|
43 | + CredentialsInterface $credentials |
|
44 | + ) { |
|
45 | + $request = $this->prepareRequest($request, $credentials); |
|
46 | + $stringToSign = $this->createCanonicalizedString($request); |
|
47 | + $auth = 'AWS ' |
|
48 | + . $credentials->getAccessKeyId() . ':' |
|
49 | + . $this->signString($stringToSign, $credentials); |
|
50 | + |
|
51 | + return $request->withHeader('Authorization', $auth); |
|
52 | + } |
|
53 | + |
|
54 | + public function presign( |
|
55 | + RequestInterface $request, |
|
56 | + CredentialsInterface $credentials, |
|
57 | + $expires |
|
58 | + ) { |
|
59 | + $query = []; |
|
60 | + // URL encoding already occurs in the URI template expansion. Undo that |
|
61 | + // and encode using the same encoding as GET object, PUT object, etc. |
|
62 | + $uri = $request->getUri(); |
|
63 | + $path = S3Client::encodeKey(rawurldecode($uri->getPath())); |
|
64 | + $request = $request->withUri($uri->withPath($path)); |
|
65 | + |
|
66 | + // Make sure to handle temporary credentials |
|
67 | + if ($token = $credentials->getSecurityToken()) { |
|
68 | + $request = $request->withHeader('X-Amz-Security-Token', $token); |
|
69 | + $query['X-Amz-Security-Token'] = $token; |
|
70 | + } |
|
71 | + |
|
72 | + if ($expires instanceof \DateTime) { |
|
73 | + $expires = $expires->getTimestamp(); |
|
74 | + } elseif (!is_numeric($expires)) { |
|
75 | + $expires = strtotime($expires); |
|
76 | + } |
|
77 | + |
|
78 | + // Set query params required for pre-signed URLs |
|
79 | + $query['AWSAccessKeyId'] = $credentials->getAccessKeyId(); |
|
80 | + $query['Expires'] = $expires; |
|
81 | + $query['Signature'] = $this->signString( |
|
82 | + $this->createCanonicalizedString($request, $expires), |
|
83 | + $credentials |
|
84 | + ); |
|
85 | + |
|
86 | + // Move X-Amz-* headers to the query string |
|
87 | + foreach ($request->getHeaders() as $name => $header) { |
|
88 | + $name = strtolower($name); |
|
89 | + if (strpos($name, 'x-amz-') === 0) { |
|
90 | + $query[$name] = implode(',', $header); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + $queryString = http_build_query($query, null, '&', PHP_QUERY_RFC3986); |
|
95 | + |
|
96 | + return $request->withUri($request->getUri()->withQuery($queryString)); |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param RequestInterface $request |
|
101 | + * @param CredentialsInterface $creds |
|
102 | + * |
|
103 | + * @return RequestInterface |
|
104 | + */ |
|
105 | + private function prepareRequest( |
|
106 | + RequestInterface $request, |
|
107 | + CredentialsInterface $creds |
|
108 | + ) { |
|
109 | + $modify = [ |
|
110 | + 'remove_headers' => ['X-Amz-Date'], |
|
111 | + 'set_headers' => ['Date' => gmdate(\DateTime::RFC2822)] |
|
112 | + ]; |
|
113 | + |
|
114 | + // Add the security token header if one is being used by the credentials |
|
115 | + if ($token = $creds->getSecurityToken()) { |
|
116 | + $modify['set_headers']['X-Amz-Security-Token'] = $token; |
|
117 | + } |
|
118 | + |
|
119 | + return Psr7\modify_request($request, $modify); |
|
120 | + } |
|
121 | + |
|
122 | + private function signString($string, CredentialsInterface $credentials) |
|
123 | + { |
|
124 | + return base64_encode( |
|
125 | + hash_hmac('sha1', $string, $credentials->getSecretKey(), true) |
|
126 | + ); |
|
127 | + } |
|
128 | + |
|
129 | + private function createCanonicalizedString( |
|
130 | + RequestInterface $request, |
|
131 | + $expires = null |
|
132 | + ) { |
|
133 | + $buffer = $request->getMethod() . "\n"; |
|
134 | + |
|
135 | + // Add the interesting headers |
|
136 | + foreach ($this->signableHeaders as $header) { |
|
137 | + $buffer .= $request->getHeaderLine($header) . "\n"; |
|
138 | + } |
|
139 | + |
|
140 | + $date = $expires ?: $request->getHeaderLine('date'); |
|
141 | + $buffer .= "{$date}\n" |
|
142 | + . $this->createCanonicalizedAmzHeaders($request) |
|
143 | + . $this->createCanonicalizedResource($request); |
|
144 | + |
|
145 | + return $buffer; |
|
146 | + } |
|
147 | + |
|
148 | + private function createCanonicalizedAmzHeaders(RequestInterface $request) |
|
149 | + { |
|
150 | + $headers = []; |
|
151 | + foreach ($request->getHeaders() as $name => $header) { |
|
152 | + $name = strtolower($name); |
|
153 | + if (strpos($name, 'x-amz-') === 0) { |
|
154 | + $value = implode(',', $header); |
|
155 | + if (strlen($value) > 0) { |
|
156 | + $headers[$name] = $name . ':' . $value; |
|
157 | + } |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + if (!$headers) { |
|
162 | + return ''; |
|
163 | + } |
|
164 | + |
|
165 | + ksort($headers); |
|
166 | + |
|
167 | + return implode("\n", $headers) . "\n"; |
|
168 | + } |
|
169 | + |
|
170 | + private function createCanonicalizedResource(RequestInterface $request) |
|
171 | + { |
|
172 | + $data = $this->parser->parse($request->getUri()); |
|
173 | + $buffer = '/'; |
|
174 | + |
|
175 | + if ($data['bucket']) { |
|
176 | + $buffer .= $data['bucket']; |
|
177 | + if (!empty($data['key']) || !$data['path_style']) { |
|
178 | + $buffer .= '/' . $data['key']; |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + // Add sub resource parameters if present. |
|
183 | + $query = $request->getUri()->getQuery(); |
|
184 | + |
|
185 | + if ($query) { |
|
186 | + $params = Psr7\parse_query($query); |
|
187 | + $first = true; |
|
188 | + foreach ($this->signableQueryString as $key) { |
|
189 | + if (array_key_exists($key, $params)) { |
|
190 | + $value = $params[$key]; |
|
191 | + $buffer .= $first ? '?' : '&'; |
|
192 | + $first = false; |
|
193 | + $buffer .= $key; |
|
194 | + // Don't add values for empty sub-resources |
|
195 | + if (strlen($value)) { |
|
196 | + $buffer .= "={$value}"; |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + return $buffer; |
|
203 | + } |
|
204 | 204 | } |
@@ -28,85 +28,85 @@ |
||
28 | 28 | use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface; |
29 | 29 | |
30 | 30 | class TimestampFormatter implements OutputFormatterInterface { |
31 | - /** @var IConfig */ |
|
32 | - protected $config; |
|
31 | + /** @var IConfig */ |
|
32 | + protected $config; |
|
33 | 33 | |
34 | - /** @var OutputFormatterInterface */ |
|
35 | - protected $formatter; |
|
34 | + /** @var OutputFormatterInterface */ |
|
35 | + protected $formatter; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param IConfig $config |
|
39 | - * @param OutputFormatterInterface $formatter |
|
40 | - */ |
|
41 | - public function __construct(IConfig $config, OutputFormatterInterface $formatter) { |
|
42 | - $this->config = $config; |
|
43 | - $this->formatter = $formatter; |
|
44 | - } |
|
37 | + /** |
|
38 | + * @param IConfig $config |
|
39 | + * @param OutputFormatterInterface $formatter |
|
40 | + */ |
|
41 | + public function __construct(IConfig $config, OutputFormatterInterface $formatter) { |
|
42 | + $this->config = $config; |
|
43 | + $this->formatter = $formatter; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Sets the decorated flag. |
|
48 | - * |
|
49 | - * @param bool $decorated Whether to decorate the messages or not |
|
50 | - */ |
|
51 | - public function setDecorated($decorated) { |
|
52 | - $this->formatter->setDecorated($decorated); |
|
53 | - } |
|
46 | + /** |
|
47 | + * Sets the decorated flag. |
|
48 | + * |
|
49 | + * @param bool $decorated Whether to decorate the messages or not |
|
50 | + */ |
|
51 | + public function setDecorated($decorated) { |
|
52 | + $this->formatter->setDecorated($decorated); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Gets the decorated flag. |
|
57 | - * |
|
58 | - * @return bool true if the output will decorate messages, false otherwise |
|
59 | - */ |
|
60 | - public function isDecorated() { |
|
61 | - return $this->formatter->isDecorated(); |
|
62 | - } |
|
55 | + /** |
|
56 | + * Gets the decorated flag. |
|
57 | + * |
|
58 | + * @return bool true if the output will decorate messages, false otherwise |
|
59 | + */ |
|
60 | + public function isDecorated() { |
|
61 | + return $this->formatter->isDecorated(); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Sets a new style. |
|
66 | - * |
|
67 | - * @param string $name The style name |
|
68 | - * @param OutputFormatterStyleInterface $style The style instance |
|
69 | - */ |
|
70 | - public function setStyle($name, OutputFormatterStyleInterface $style) { |
|
71 | - $this->formatter->setStyle($name, $style); |
|
72 | - } |
|
64 | + /** |
|
65 | + * Sets a new style. |
|
66 | + * |
|
67 | + * @param string $name The style name |
|
68 | + * @param OutputFormatterStyleInterface $style The style instance |
|
69 | + */ |
|
70 | + public function setStyle($name, OutputFormatterStyleInterface $style) { |
|
71 | + $this->formatter->setStyle($name, $style); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Checks if output formatter has style with specified name. |
|
76 | - * |
|
77 | - * @param string $name |
|
78 | - * @return bool |
|
79 | - */ |
|
80 | - public function hasStyle($name) { |
|
81 | - return $this->formatter->hasStyle($name); |
|
82 | - } |
|
74 | + /** |
|
75 | + * Checks if output formatter has style with specified name. |
|
76 | + * |
|
77 | + * @param string $name |
|
78 | + * @return bool |
|
79 | + */ |
|
80 | + public function hasStyle($name) { |
|
81 | + return $this->formatter->hasStyle($name); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Gets style options from style with specified name. |
|
86 | - * |
|
87 | - * @param string $name |
|
88 | - * @return OutputFormatterStyleInterface |
|
89 | - * @throws \InvalidArgumentException When style isn't defined |
|
90 | - */ |
|
91 | - public function getStyle($name) { |
|
92 | - return $this->formatter->getStyle($name); |
|
93 | - } |
|
84 | + /** |
|
85 | + * Gets style options from style with specified name. |
|
86 | + * |
|
87 | + * @param string $name |
|
88 | + * @return OutputFormatterStyleInterface |
|
89 | + * @throws \InvalidArgumentException When style isn't defined |
|
90 | + */ |
|
91 | + public function getStyle($name) { |
|
92 | + return $this->formatter->getStyle($name); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Formats a message according to the given styles. |
|
97 | - * |
|
98 | - * @param string $message The message to style |
|
99 | - * @return string The styled message, prepended with a timestamp using the |
|
100 | - * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" |
|
101 | - */ |
|
102 | - public function format($message) { |
|
95 | + /** |
|
96 | + * Formats a message according to the given styles. |
|
97 | + * |
|
98 | + * @param string $message The message to style |
|
99 | + * @return string The styled message, prepended with a timestamp using the |
|
100 | + * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00" |
|
101 | + */ |
|
102 | + public function format($message) { |
|
103 | 103 | |
104 | - $timeZone = $this->config->getSystemValue('logtimezone', 'UTC'); |
|
105 | - $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null; |
|
104 | + $timeZone = $this->config->getSystemValue('logtimezone', 'UTC'); |
|
105 | + $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null; |
|
106 | 106 | |
107 | - $time = new \DateTime('now', $timeZone); |
|
108 | - $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
|
107 | + $time = new \DateTime('now', $timeZone); |
|
108 | + $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTime::ATOM)); |
|
109 | 109 | |
110 | - return $timestampInfo . ' ' . $this->formatter->format($message); |
|
111 | - } |
|
110 | + return $timestampInfo . ' ' . $this->formatter->format($message); |
|
111 | + } |
|
112 | 112 | } |
@@ -29,53 +29,53 @@ |
||
29 | 29 | |
30 | 30 | class Mount extends MountPoint implements MoveableMount { |
31 | 31 | |
32 | - /** |
|
33 | - * @var \OCA\Files_Sharing\External\Manager |
|
34 | - */ |
|
35 | - protected $manager; |
|
32 | + /** |
|
33 | + * @var \OCA\Files_Sharing\External\Manager |
|
34 | + */ |
|
35 | + protected $manager; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string|\OC\Files\Storage\Storage $storage |
|
39 | - * @param string $mountpoint |
|
40 | - * @param array $options |
|
41 | - * @param \OCA\Files_Sharing\External\Manager $manager |
|
42 | - * @param \OC\Files\Storage\StorageFactory $loader |
|
43 | - */ |
|
44 | - public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
45 | - parent::__construct($storage, $mountpoint, $options, $loader); |
|
46 | - $this->manager = $manager; |
|
47 | - } |
|
37 | + /** |
|
38 | + * @param string|\OC\Files\Storage\Storage $storage |
|
39 | + * @param string $mountpoint |
|
40 | + * @param array $options |
|
41 | + * @param \OCA\Files_Sharing\External\Manager $manager |
|
42 | + * @param \OC\Files\Storage\StorageFactory $loader |
|
43 | + */ |
|
44 | + public function __construct($storage, $mountpoint, $options, $manager, $loader = null) { |
|
45 | + parent::__construct($storage, $mountpoint, $options, $loader); |
|
46 | + $this->manager = $manager; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Move the mount point to $target |
|
51 | - * |
|
52 | - * @param string $target the target mount point |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function moveMount($target) { |
|
56 | - $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
57 | - $this->setMountPoint($target); |
|
49 | + /** |
|
50 | + * Move the mount point to $target |
|
51 | + * |
|
52 | + * @param string $target the target mount point |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function moveMount($target) { |
|
56 | + $result = $this->manager->setMountPoint($this->mountPoint, $target); |
|
57 | + $this->setMountPoint($target); |
|
58 | 58 | |
59 | - return $result; |
|
60 | - } |
|
59 | + return $result; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Remove the mount points |
|
64 | - * |
|
65 | - * @return mixed |
|
66 | - * @return bool |
|
67 | - */ |
|
68 | - public function removeMount() { |
|
69 | - return $this->manager->removeShare($this->mountPoint); |
|
70 | - } |
|
62 | + /** |
|
63 | + * Remove the mount points |
|
64 | + * |
|
65 | + * @return mixed |
|
66 | + * @return bool |
|
67 | + */ |
|
68 | + public function removeMount() { |
|
69 | + return $this->manager->removeShare($this->mountPoint); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Get the type of mount point, used to distinguish things like shares and external storages |
|
74 | - * in the web interface |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function getMountType() { |
|
79 | - return 'shared'; |
|
80 | - } |
|
72 | + /** |
|
73 | + * Get the type of mount point, used to distinguish things like shares and external storages |
|
74 | + * in the web interface |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function getMountType() { |
|
79 | + return 'shared'; |
|
80 | + } |
|
81 | 81 | } |
@@ -30,27 +30,27 @@ |
||
30 | 30 | |
31 | 31 | class MySqlExpressionBuilder extends ExpressionBuilder { |
32 | 32 | |
33 | - /** @var string */ |
|
34 | - protected $charset; |
|
35 | - |
|
36 | - /** |
|
37 | - * @param \OCP\IDBConnection|Connection $connection |
|
38 | - * @param IQueryBuilder $queryBuilder |
|
39 | - */ |
|
40 | - public function __construct(IDBConnection $connection, IQueryBuilder $queryBuilder) { |
|
41 | - parent::__construct($connection, $queryBuilder); |
|
42 | - |
|
43 | - $params = $connection->getParams(); |
|
44 | - $this->charset = isset($params['charset']) ? $params['charset'] : 'utf8'; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * @inheritdoc |
|
49 | - */ |
|
50 | - public function iLike($x, $y, $type = null) { |
|
51 | - $x = $this->helper->quoteColumnName($x); |
|
52 | - $y = $this->helper->quoteColumnName($y); |
|
53 | - return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->charset . '_general_ci LIKE', $y); |
|
54 | - } |
|
33 | + /** @var string */ |
|
34 | + protected $charset; |
|
35 | + |
|
36 | + /** |
|
37 | + * @param \OCP\IDBConnection|Connection $connection |
|
38 | + * @param IQueryBuilder $queryBuilder |
|
39 | + */ |
|
40 | + public function __construct(IDBConnection $connection, IQueryBuilder $queryBuilder) { |
|
41 | + parent::__construct($connection, $queryBuilder); |
|
42 | + |
|
43 | + $params = $connection->getParams(); |
|
44 | + $this->charset = isset($params['charset']) ? $params['charset'] : 'utf8'; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * @inheritdoc |
|
49 | + */ |
|
50 | + public function iLike($x, $y, $type = null) { |
|
51 | + $x = $this->helper->quoteColumnName($x); |
|
52 | + $y = $this->helper->quoteColumnName($y); |
|
53 | + return $this->expressionBuilder->comparison($x, ' COLLATE ' . $this->charset . '_general_ci LIKE', $y); |
|
54 | + } |
|
55 | 55 | |
56 | 56 | } |
@@ -30,140 +30,140 @@ |
||
30 | 30 | use OCP\IMemcache; |
31 | 31 | |
32 | 32 | class APCu extends Cache implements IMemcache { |
33 | - use CASTrait { |
|
34 | - cas as casEmulated; |
|
35 | - } |
|
33 | + use CASTrait { |
|
34 | + cas as casEmulated; |
|
35 | + } |
|
36 | 36 | |
37 | - use CADTrait; |
|
37 | + use CADTrait; |
|
38 | 38 | |
39 | - public function get($key) { |
|
40 | - $result = apcu_fetch($this->getPrefix() . $key, $success); |
|
41 | - if (!$success) { |
|
42 | - return null; |
|
43 | - } |
|
44 | - return $result; |
|
45 | - } |
|
39 | + public function get($key) { |
|
40 | + $result = apcu_fetch($this->getPrefix() . $key, $success); |
|
41 | + if (!$success) { |
|
42 | + return null; |
|
43 | + } |
|
44 | + return $result; |
|
45 | + } |
|
46 | 46 | |
47 | - public function set($key, $value, $ttl = 0) { |
|
48 | - return apcu_store($this->getPrefix() . $key, $value, $ttl); |
|
49 | - } |
|
47 | + public function set($key, $value, $ttl = 0) { |
|
48 | + return apcu_store($this->getPrefix() . $key, $value, $ttl); |
|
49 | + } |
|
50 | 50 | |
51 | - public function hasKey($key) { |
|
52 | - return apcu_exists($this->getPrefix() . $key); |
|
53 | - } |
|
51 | + public function hasKey($key) { |
|
52 | + return apcu_exists($this->getPrefix() . $key); |
|
53 | + } |
|
54 | 54 | |
55 | - public function remove($key) { |
|
56 | - return apcu_delete($this->getPrefix() . $key); |
|
57 | - } |
|
55 | + public function remove($key) { |
|
56 | + return apcu_delete($this->getPrefix() . $key); |
|
57 | + } |
|
58 | 58 | |
59 | - public function clear($prefix = '') { |
|
60 | - $ns = $this->getPrefix() . $prefix; |
|
61 | - $ns = preg_quote($ns, '/'); |
|
62 | - if(class_exists('\APCIterator')) { |
|
63 | - $iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY); |
|
64 | - } else { |
|
65 | - $iter = new \APCUIterator('/^' . $ns . '/', APC_ITER_KEY); |
|
66 | - } |
|
67 | - return apcu_delete($iter); |
|
68 | - } |
|
59 | + public function clear($prefix = '') { |
|
60 | + $ns = $this->getPrefix() . $prefix; |
|
61 | + $ns = preg_quote($ns, '/'); |
|
62 | + if(class_exists('\APCIterator')) { |
|
63 | + $iter = new \APCIterator('user', '/^' . $ns . '/', APC_ITER_KEY); |
|
64 | + } else { |
|
65 | + $iter = new \APCUIterator('/^' . $ns . '/', APC_ITER_KEY); |
|
66 | + } |
|
67 | + return apcu_delete($iter); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Set a value in the cache if it's not already stored |
|
72 | - * |
|
73 | - * @param string $key |
|
74 | - * @param mixed $value |
|
75 | - * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
76 | - * @return bool |
|
77 | - */ |
|
78 | - public function add($key, $value, $ttl = 0) { |
|
79 | - return apcu_add($this->getPrefix() . $key, $value, $ttl); |
|
80 | - } |
|
70 | + /** |
|
71 | + * Set a value in the cache if it's not already stored |
|
72 | + * |
|
73 | + * @param string $key |
|
74 | + * @param mixed $value |
|
75 | + * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
76 | + * @return bool |
|
77 | + */ |
|
78 | + public function add($key, $value, $ttl = 0) { |
|
79 | + return apcu_add($this->getPrefix() . $key, $value, $ttl); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Increase a stored number |
|
84 | - * |
|
85 | - * @param string $key |
|
86 | - * @param int $step |
|
87 | - * @return int | bool |
|
88 | - */ |
|
89 | - public function inc($key, $step = 1) { |
|
90 | - $this->add($key, 0); |
|
91 | - /** |
|
92 | - * TODO - hack around a PHP 7 specific issue in APCu |
|
93 | - * |
|
94 | - * on PHP 7 the apcu_inc method on a non-existing object will increment |
|
95 | - * "0" and result in "1" as value - therefore we check for existence |
|
96 | - * first |
|
97 | - * |
|
98 | - * on PHP 5.6 this is not the case |
|
99 | - * |
|
100 | - * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
101 | - * for details |
|
102 | - */ |
|
103 | - return apcu_exists($this->getPrefix() . $key) |
|
104 | - ? apcu_inc($this->getPrefix() . $key, $step) |
|
105 | - : false; |
|
106 | - } |
|
82 | + /** |
|
83 | + * Increase a stored number |
|
84 | + * |
|
85 | + * @param string $key |
|
86 | + * @param int $step |
|
87 | + * @return int | bool |
|
88 | + */ |
|
89 | + public function inc($key, $step = 1) { |
|
90 | + $this->add($key, 0); |
|
91 | + /** |
|
92 | + * TODO - hack around a PHP 7 specific issue in APCu |
|
93 | + * |
|
94 | + * on PHP 7 the apcu_inc method on a non-existing object will increment |
|
95 | + * "0" and result in "1" as value - therefore we check for existence |
|
96 | + * first |
|
97 | + * |
|
98 | + * on PHP 5.6 this is not the case |
|
99 | + * |
|
100 | + * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
101 | + * for details |
|
102 | + */ |
|
103 | + return apcu_exists($this->getPrefix() . $key) |
|
104 | + ? apcu_inc($this->getPrefix() . $key, $step) |
|
105 | + : false; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Decrease a stored number |
|
110 | - * |
|
111 | - * @param string $key |
|
112 | - * @param int $step |
|
113 | - * @return int | bool |
|
114 | - */ |
|
115 | - public function dec($key, $step = 1) { |
|
116 | - /** |
|
117 | - * TODO - hack around a PHP 7 specific issue in APCu |
|
118 | - * |
|
119 | - * on PHP 7 the apcu_dec method on a non-existing object will decrement |
|
120 | - * "0" and result in "-1" as value - therefore we check for existence |
|
121 | - * first |
|
122 | - * |
|
123 | - * on PHP 5.6 this is not the case |
|
124 | - * |
|
125 | - * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
126 | - * for details |
|
127 | - */ |
|
128 | - return apcu_exists($this->getPrefix() . $key) |
|
129 | - ? apcu_dec($this->getPrefix() . $key, $step) |
|
130 | - : false; |
|
131 | - } |
|
108 | + /** |
|
109 | + * Decrease a stored number |
|
110 | + * |
|
111 | + * @param string $key |
|
112 | + * @param int $step |
|
113 | + * @return int | bool |
|
114 | + */ |
|
115 | + public function dec($key, $step = 1) { |
|
116 | + /** |
|
117 | + * TODO - hack around a PHP 7 specific issue in APCu |
|
118 | + * |
|
119 | + * on PHP 7 the apcu_dec method on a non-existing object will decrement |
|
120 | + * "0" and result in "-1" as value - therefore we check for existence |
|
121 | + * first |
|
122 | + * |
|
123 | + * on PHP 5.6 this is not the case |
|
124 | + * |
|
125 | + * see https://github.com/krakjoe/apcu/issues/183#issuecomment-244038221 |
|
126 | + * for details |
|
127 | + */ |
|
128 | + return apcu_exists($this->getPrefix() . $key) |
|
129 | + ? apcu_dec($this->getPrefix() . $key, $step) |
|
130 | + : false; |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Compare and set |
|
135 | - * |
|
136 | - * @param string $key |
|
137 | - * @param mixed $old |
|
138 | - * @param mixed $new |
|
139 | - * @return bool |
|
140 | - */ |
|
141 | - public function cas($key, $old, $new) { |
|
142 | - // apc only does cas for ints |
|
143 | - if (is_int($old) and is_int($new)) { |
|
144 | - return apcu_cas($this->getPrefix() . $key, $old, $new); |
|
145 | - } else { |
|
146 | - return $this->casEmulated($key, $old, $new); |
|
147 | - } |
|
148 | - } |
|
133 | + /** |
|
134 | + * Compare and set |
|
135 | + * |
|
136 | + * @param string $key |
|
137 | + * @param mixed $old |
|
138 | + * @param mixed $new |
|
139 | + * @return bool |
|
140 | + */ |
|
141 | + public function cas($key, $old, $new) { |
|
142 | + // apc only does cas for ints |
|
143 | + if (is_int($old) and is_int($new)) { |
|
144 | + return apcu_cas($this->getPrefix() . $key, $old, $new); |
|
145 | + } else { |
|
146 | + return $this->casEmulated($key, $old, $new); |
|
147 | + } |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * @return bool |
|
152 | - */ |
|
153 | - static public function isAvailable() { |
|
154 | - if (!extension_loaded('apcu')) { |
|
155 | - return false; |
|
156 | - } elseif (!\OC::$server->getIniWrapper()->getBool('apc.enabled')) { |
|
157 | - return false; |
|
158 | - } elseif (!\OC::$server->getIniWrapper()->getBool('apc.enable_cli') && \OC::$CLI) { |
|
159 | - return false; |
|
160 | - } elseif ( |
|
161 | - version_compare(phpversion('apc') ?: '0.0.0', '4.0.6') === -1 && |
|
162 | - version_compare(phpversion('apcu') ?: '0.0.0', '5.1.0') === -1 |
|
163 | - ) { |
|
164 | - return false; |
|
165 | - } else { |
|
166 | - return true; |
|
167 | - } |
|
168 | - } |
|
150 | + /** |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | + static public function isAvailable() { |
|
154 | + if (!extension_loaded('apcu')) { |
|
155 | + return false; |
|
156 | + } elseif (!\OC::$server->getIniWrapper()->getBool('apc.enabled')) { |
|
157 | + return false; |
|
158 | + } elseif (!\OC::$server->getIniWrapper()->getBool('apc.enable_cli') && \OC::$CLI) { |
|
159 | + return false; |
|
160 | + } elseif ( |
|
161 | + version_compare(phpversion('apc') ?: '0.0.0', '4.0.6') === -1 && |
|
162 | + version_compare(phpversion('apcu') ?: '0.0.0', '5.1.0') === -1 |
|
163 | + ) { |
|
164 | + return false; |
|
165 | + } else { |
|
166 | + return true; |
|
167 | + } |
|
168 | + } |
|
169 | 169 | } |
@@ -25,81 +25,81 @@ |
||
25 | 25 | |
26 | 26 | class DatabaseSchemaChecker { |
27 | 27 | |
28 | - /** |
|
29 | - * @param string $appId |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - public function analyse($appId) { |
|
33 | - $appPath = \OC_App::getAppPath($appId); |
|
34 | - if ($appPath === false) { |
|
35 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
36 | - } |
|
37 | - |
|
38 | - if (!file_exists($appPath . '/appinfo/database.xml')) { |
|
39 | - return ['errors' => [], 'warnings' => []]; |
|
40 | - } |
|
41 | - |
|
42 | - libxml_use_internal_errors(true); |
|
43 | - $loadEntities = libxml_disable_entity_loader(false); |
|
44 | - $xml = simplexml_load_file($appPath . '/appinfo/database.xml'); |
|
45 | - libxml_disable_entity_loader($loadEntities); |
|
46 | - |
|
47 | - |
|
48 | - $errors = $warnings = []; |
|
49 | - |
|
50 | - foreach ($xml->table as $table) { |
|
51 | - // Table names |
|
52 | - if (strpos((string)$table->name, '*dbprefix*') !== 0) { |
|
53 | - $errors[] = 'Database schema error: name of table ' . (string)$table->name . ' does not start with *dbprefix*'; |
|
54 | - } |
|
55 | - $tableName = substr((string)$table->name, strlen('*dbprefix*')); |
|
56 | - if (strpos($tableName, '*dbprefix*') !== false) { |
|
57 | - $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table ' . (string)$table->name; |
|
58 | - } |
|
59 | - |
|
60 | - if (strlen($tableName) > 27) { |
|
61 | - $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
62 | - } |
|
63 | - |
|
64 | - $hasAutoIncrement = false; |
|
65 | - |
|
66 | - // Column names |
|
67 | - foreach ($table->declaration->field as $column) { |
|
68 | - if (strpos((string)$column->name, '*dbprefix*') !== false) { |
|
69 | - $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column ' . (string)$column->name . ' on table ' . (string)$table->name; |
|
70 | - } |
|
71 | - |
|
72 | - if (strlen((string)$column->name) > 30) { |
|
73 | - $errors[] = 'Database schema error: Name of column ' . (string)$column->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 30 characters allowed'; |
|
74 | - } |
|
75 | - |
|
76 | - if ($column->autoincrement) { |
|
77 | - if ($hasAutoIncrement) { |
|
78 | - $errors[] = 'Database schema error: Table ' . (string)$table->name . ' has multiple autoincrement columns'; |
|
79 | - } |
|
80 | - |
|
81 | - if (strlen($tableName) > 21) { |
|
82 | - $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
83 | - } |
|
84 | - |
|
85 | - $hasAutoIncrement = true; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - // Index names |
|
90 | - foreach ($table->declaration->index as $index) { |
|
91 | - $hasPrefix = strpos((string)$index->name, '*dbprefix*'); |
|
92 | - if ($hasPrefix !== false && $hasPrefix !== 0) { |
|
93 | - $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index ' . (string)$index->name . ' on table ' . (string)$table->name; |
|
94 | - } |
|
95 | - |
|
96 | - $indexName = $hasPrefix === 0 ? substr((string)$index->name, strlen('*dbprefix*')) : (string)$index->name; |
|
97 | - if (strlen($indexName) > 27) { |
|
98 | - $errors[] = 'Database schema error: Name of index ' . (string)$index->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters + *dbprefix* allowed'; |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - return ['errors' => $errors, 'warnings' => $warnings]; |
|
104 | - } |
|
28 | + /** |
|
29 | + * @param string $appId |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + public function analyse($appId) { |
|
33 | + $appPath = \OC_App::getAppPath($appId); |
|
34 | + if ($appPath === false) { |
|
35 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
36 | + } |
|
37 | + |
|
38 | + if (!file_exists($appPath . '/appinfo/database.xml')) { |
|
39 | + return ['errors' => [], 'warnings' => []]; |
|
40 | + } |
|
41 | + |
|
42 | + libxml_use_internal_errors(true); |
|
43 | + $loadEntities = libxml_disable_entity_loader(false); |
|
44 | + $xml = simplexml_load_file($appPath . '/appinfo/database.xml'); |
|
45 | + libxml_disable_entity_loader($loadEntities); |
|
46 | + |
|
47 | + |
|
48 | + $errors = $warnings = []; |
|
49 | + |
|
50 | + foreach ($xml->table as $table) { |
|
51 | + // Table names |
|
52 | + if (strpos((string)$table->name, '*dbprefix*') !== 0) { |
|
53 | + $errors[] = 'Database schema error: name of table ' . (string)$table->name . ' does not start with *dbprefix*'; |
|
54 | + } |
|
55 | + $tableName = substr((string)$table->name, strlen('*dbprefix*')); |
|
56 | + if (strpos($tableName, '*dbprefix*') !== false) { |
|
57 | + $warnings[] = 'Database schema warning: *dbprefix* should only appear once in name of table ' . (string)$table->name; |
|
58 | + } |
|
59 | + |
|
60 | + if (strlen($tableName) > 27) { |
|
61 | + $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
62 | + } |
|
63 | + |
|
64 | + $hasAutoIncrement = false; |
|
65 | + |
|
66 | + // Column names |
|
67 | + foreach ($table->declaration->field as $column) { |
|
68 | + if (strpos((string)$column->name, '*dbprefix*') !== false) { |
|
69 | + $warnings[] = 'Database schema warning: *dbprefix* should not appear in name of column ' . (string)$column->name . ' on table ' . (string)$table->name; |
|
70 | + } |
|
71 | + |
|
72 | + if (strlen((string)$column->name) > 30) { |
|
73 | + $errors[] = 'Database schema error: Name of column ' . (string)$column->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 30 characters allowed'; |
|
74 | + } |
|
75 | + |
|
76 | + if ($column->autoincrement) { |
|
77 | + if ($hasAutoIncrement) { |
|
78 | + $errors[] = 'Database schema error: Table ' . (string)$table->name . ' has multiple autoincrement columns'; |
|
79 | + } |
|
80 | + |
|
81 | + if (strlen($tableName) > 21) { |
|
82 | + $errors[] = 'Database schema error: Name of table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters (21 characters for tables with autoincrement) + *dbprefix* allowed'; |
|
83 | + } |
|
84 | + |
|
85 | + $hasAutoIncrement = true; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + // Index names |
|
90 | + foreach ($table->declaration->index as $index) { |
|
91 | + $hasPrefix = strpos((string)$index->name, '*dbprefix*'); |
|
92 | + if ($hasPrefix !== false && $hasPrefix !== 0) { |
|
93 | + $warnings[] = 'Database schema warning: *dbprefix* should only appear at the beginning in name of index ' . (string)$index->name . ' on table ' . (string)$table->name; |
|
94 | + } |
|
95 | + |
|
96 | + $indexName = $hasPrefix === 0 ? substr((string)$index->name, strlen('*dbprefix*')) : (string)$index->name; |
|
97 | + if (strlen($indexName) > 27) { |
|
98 | + $errors[] = 'Database schema error: Name of index ' . (string)$index->name . ' on table ' . (string)$table->name . ' is too long (' . strlen($tableName) . '), max. 27 characters + *dbprefix* allowed'; |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + return ['errors' => $errors, 'warnings' => $warnings]; |
|
104 | + } |
|
105 | 105 | } |
@@ -32,19 +32,19 @@ |
||
32 | 32 | |
33 | 33 | class UpdateHtaccess extends Command { |
34 | 34 | |
35 | - protected function configure() { |
|
36 | - $this |
|
37 | - ->setName('maintenance:update:htaccess') |
|
38 | - ->setDescription('Updates the .htaccess file'); |
|
39 | - } |
|
35 | + protected function configure() { |
|
36 | + $this |
|
37 | + ->setName('maintenance:update:htaccess') |
|
38 | + ->setDescription('Updates the .htaccess file'); |
|
39 | + } |
|
40 | 40 | |
41 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
42 | - if (\OC\Setup::updateHtaccess()) { |
|
43 | - $output->writeln('.htaccess has been updated'); |
|
44 | - return 0; |
|
45 | - } else { |
|
46 | - $output->writeln('<error>Error updating .htaccess file, not enough permissions or "overwrite.cli.url" set to an invalid URL?</error>'); |
|
47 | - return 1; |
|
48 | - } |
|
49 | - } |
|
41 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
42 | + if (\OC\Setup::updateHtaccess()) { |
|
43 | + $output->writeln('.htaccess has been updated'); |
|
44 | + return 0; |
|
45 | + } else { |
|
46 | + $output->writeln('<error>Error updating .htaccess file, not enough permissions or "overwrite.cli.url" set to an invalid URL?</error>'); |
|
47 | + return 1; |
|
48 | + } |
|
49 | + } |
|
50 | 50 | } |