@@ -32,45 +32,45 @@ |
||
32 | 32 | */ |
33 | 33 | class File extends \OCP\Search\Provider { |
34 | 34 | |
35 | - /** |
|
36 | - * Search for files and folders matching the given query |
|
37 | - * @param string $query |
|
38 | - * @return \OCP\Search\Result |
|
39 | - */ |
|
40 | - public function search($query) { |
|
41 | - $files = Filesystem::search($query); |
|
42 | - $results = array(); |
|
43 | - // edit results |
|
44 | - foreach ($files as $fileData) { |
|
45 | - // skip versions |
|
46 | - if (strpos($fileData['path'], '_versions') === 0) { |
|
47 | - continue; |
|
48 | - } |
|
49 | - // skip top-level folder |
|
50 | - if ($fileData['name'] === 'files' && $fileData['parent'] === -1) { |
|
51 | - continue; |
|
52 | - } |
|
53 | - // create audio result |
|
54 | - if($fileData['mimepart'] === 'audio'){ |
|
55 | - $result = new \OC\Search\Result\Audio($fileData); |
|
56 | - } |
|
57 | - // create image result |
|
58 | - elseif($fileData['mimepart'] === 'image'){ |
|
59 | - $result = new \OC\Search\Result\Image($fileData); |
|
60 | - } |
|
61 | - // create folder result |
|
62 | - elseif($fileData['mimetype'] === 'httpd/unix-directory'){ |
|
63 | - $result = new \OC\Search\Result\Folder($fileData); |
|
64 | - } |
|
65 | - // or create file result |
|
66 | - else{ |
|
67 | - $result = new \OC\Search\Result\File($fileData); |
|
68 | - } |
|
69 | - // add to results |
|
70 | - $results[] = $result; |
|
71 | - } |
|
72 | - // return |
|
73 | - return $results; |
|
74 | - } |
|
35 | + /** |
|
36 | + * Search for files and folders matching the given query |
|
37 | + * @param string $query |
|
38 | + * @return \OCP\Search\Result |
|
39 | + */ |
|
40 | + public function search($query) { |
|
41 | + $files = Filesystem::search($query); |
|
42 | + $results = array(); |
|
43 | + // edit results |
|
44 | + foreach ($files as $fileData) { |
|
45 | + // skip versions |
|
46 | + if (strpos($fileData['path'], '_versions') === 0) { |
|
47 | + continue; |
|
48 | + } |
|
49 | + // skip top-level folder |
|
50 | + if ($fileData['name'] === 'files' && $fileData['parent'] === -1) { |
|
51 | + continue; |
|
52 | + } |
|
53 | + // create audio result |
|
54 | + if($fileData['mimepart'] === 'audio'){ |
|
55 | + $result = new \OC\Search\Result\Audio($fileData); |
|
56 | + } |
|
57 | + // create image result |
|
58 | + elseif($fileData['mimepart'] === 'image'){ |
|
59 | + $result = new \OC\Search\Result\Image($fileData); |
|
60 | + } |
|
61 | + // create folder result |
|
62 | + elseif($fileData['mimetype'] === 'httpd/unix-directory'){ |
|
63 | + $result = new \OC\Search\Result\Folder($fileData); |
|
64 | + } |
|
65 | + // or create file result |
|
66 | + else{ |
|
67 | + $result = new \OC\Search\Result\File($fileData); |
|
68 | + } |
|
69 | + // add to results |
|
70 | + $results[] = $result; |
|
71 | + } |
|
72 | + // return |
|
73 | + return $results; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | } |
@@ -34,246 +34,246 @@ |
||
34 | 34 | use OCP\ITempManager; |
35 | 35 | |
36 | 36 | class TempManager implements ITempManager { |
37 | - /** @var string[] Current temporary files and folders, used for cleanup */ |
|
38 | - protected $current = []; |
|
39 | - /** @var string i.e. /tmp on linux systems */ |
|
40 | - protected $tmpBaseDir; |
|
41 | - /** @var ILogger */ |
|
42 | - protected $log; |
|
43 | - /** @var IConfig */ |
|
44 | - protected $config; |
|
37 | + /** @var string[] Current temporary files and folders, used for cleanup */ |
|
38 | + protected $current = []; |
|
39 | + /** @var string i.e. /tmp on linux systems */ |
|
40 | + protected $tmpBaseDir; |
|
41 | + /** @var ILogger */ |
|
42 | + protected $log; |
|
43 | + /** @var IConfig */ |
|
44 | + protected $config; |
|
45 | 45 | |
46 | - /** Prefix */ |
|
47 | - const TMP_PREFIX = 'oc_tmp_'; |
|
46 | + /** Prefix */ |
|
47 | + const TMP_PREFIX = 'oc_tmp_'; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param \OCP\ILogger $logger |
|
51 | - * @param \OCP\IConfig $config |
|
52 | - */ |
|
53 | - public function __construct(ILogger $logger, IConfig $config) { |
|
54 | - $this->log = $logger; |
|
55 | - $this->config = $config; |
|
56 | - $this->tmpBaseDir = $this->getTempBaseDir(); |
|
57 | - } |
|
49 | + /** |
|
50 | + * @param \OCP\ILogger $logger |
|
51 | + * @param \OCP\IConfig $config |
|
52 | + */ |
|
53 | + public function __construct(ILogger $logger, IConfig $config) { |
|
54 | + $this->log = $logger; |
|
55 | + $this->config = $config; |
|
56 | + $this->tmpBaseDir = $this->getTempBaseDir(); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * Builds the filename with suffix and removes potential dangerous characters |
|
61 | - * such as directory separators. |
|
62 | - * |
|
63 | - * @param string $absolutePath Absolute path to the file / folder |
|
64 | - * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
68 | - if($postFix !== '') { |
|
69 | - $postFix = '.' . ltrim($postFix, '.'); |
|
70 | - $postFix = str_replace(['\\', '/'], '', $postFix); |
|
71 | - $absolutePath .= '-'; |
|
72 | - } |
|
59 | + /** |
|
60 | + * Builds the filename with suffix and removes potential dangerous characters |
|
61 | + * such as directory separators. |
|
62 | + * |
|
63 | + * @param string $absolutePath Absolute path to the file / folder |
|
64 | + * @param string $postFix Postfix appended to the temporary file name, may be user controlled |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + private function buildFileNameWithSuffix($absolutePath, $postFix = '') { |
|
68 | + if($postFix !== '') { |
|
69 | + $postFix = '.' . ltrim($postFix, '.'); |
|
70 | + $postFix = str_replace(['\\', '/'], '', $postFix); |
|
71 | + $absolutePath .= '-'; |
|
72 | + } |
|
73 | 73 | |
74 | - return $absolutePath . $postFix; |
|
75 | - } |
|
74 | + return $absolutePath . $postFix; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Create a temporary file and return the path |
|
79 | - * |
|
80 | - * @param string $postFix Postfix appended to the temporary file name |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getTemporaryFile($postFix = '') { |
|
84 | - if (is_writable($this->tmpBaseDir)) { |
|
85 | - // To create an unique file and prevent the risk of race conditions |
|
86 | - // or duplicated temporary files by other means such as collisions |
|
87 | - // we need to create the file using `tempnam` and append a possible |
|
88 | - // postfix to it later |
|
89 | - $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
90 | - $this->current[] = $file; |
|
77 | + /** |
|
78 | + * Create a temporary file and return the path |
|
79 | + * |
|
80 | + * @param string $postFix Postfix appended to the temporary file name |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getTemporaryFile($postFix = '') { |
|
84 | + if (is_writable($this->tmpBaseDir)) { |
|
85 | + // To create an unique file and prevent the risk of race conditions |
|
86 | + // or duplicated temporary files by other means such as collisions |
|
87 | + // we need to create the file using `tempnam` and append a possible |
|
88 | + // postfix to it later |
|
89 | + $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
90 | + $this->current[] = $file; |
|
91 | 91 | |
92 | - // If a postfix got specified sanitize it and create a postfixed |
|
93 | - // temporary file |
|
94 | - if($postFix !== '') { |
|
95 | - $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
96 | - touch($fileNameWithPostfix); |
|
97 | - chmod($fileNameWithPostfix, 0600); |
|
98 | - $this->current[] = $fileNameWithPostfix; |
|
99 | - return $fileNameWithPostfix; |
|
100 | - } |
|
92 | + // If a postfix got specified sanitize it and create a postfixed |
|
93 | + // temporary file |
|
94 | + if($postFix !== '') { |
|
95 | + $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix); |
|
96 | + touch($fileNameWithPostfix); |
|
97 | + chmod($fileNameWithPostfix, 0600); |
|
98 | + $this->current[] = $fileNameWithPostfix; |
|
99 | + return $fileNameWithPostfix; |
|
100 | + } |
|
101 | 101 | |
102 | - return $file; |
|
103 | - } else { |
|
104 | - $this->log->warning( |
|
105 | - 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
106 | - [ |
|
107 | - 'dir' => $this->tmpBaseDir, |
|
108 | - ] |
|
109 | - ); |
|
110 | - return false; |
|
111 | - } |
|
112 | - } |
|
102 | + return $file; |
|
103 | + } else { |
|
104 | + $this->log->warning( |
|
105 | + 'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions', |
|
106 | + [ |
|
107 | + 'dir' => $this->tmpBaseDir, |
|
108 | + ] |
|
109 | + ); |
|
110 | + return false; |
|
111 | + } |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Create a temporary folder and return the path |
|
116 | - * |
|
117 | - * @param string $postFix Postfix appended to the temporary folder name |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function getTemporaryFolder($postFix = '') { |
|
121 | - if (is_writable($this->tmpBaseDir)) { |
|
122 | - // To create an unique directory and prevent the risk of race conditions |
|
123 | - // or duplicated temporary files by other means such as collisions |
|
124 | - // we need to create the file using `tempnam` and append a possible |
|
125 | - // postfix to it later |
|
126 | - $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
127 | - $this->current[] = $uniqueFileName; |
|
114 | + /** |
|
115 | + * Create a temporary folder and return the path |
|
116 | + * |
|
117 | + * @param string $postFix Postfix appended to the temporary folder name |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function getTemporaryFolder($postFix = '') { |
|
121 | + if (is_writable($this->tmpBaseDir)) { |
|
122 | + // To create an unique directory and prevent the risk of race conditions |
|
123 | + // or duplicated temporary files by other means such as collisions |
|
124 | + // we need to create the file using `tempnam` and append a possible |
|
125 | + // postfix to it later |
|
126 | + $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX); |
|
127 | + $this->current[] = $uniqueFileName; |
|
128 | 128 | |
129 | - // Build a name without postfix |
|
130 | - $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
131 | - mkdir($path, 0700); |
|
132 | - $this->current[] = $path; |
|
129 | + // Build a name without postfix |
|
130 | + $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix); |
|
131 | + mkdir($path, 0700); |
|
132 | + $this->current[] = $path; |
|
133 | 133 | |
134 | - return $path . '/'; |
|
135 | - } else { |
|
136 | - $this->log->warning( |
|
137 | - 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
138 | - [ |
|
139 | - 'dir' => $this->tmpBaseDir, |
|
140 | - ] |
|
141 | - ); |
|
142 | - return false; |
|
143 | - } |
|
144 | - } |
|
134 | + return $path . '/'; |
|
135 | + } else { |
|
136 | + $this->log->warning( |
|
137 | + 'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions', |
|
138 | + [ |
|
139 | + 'dir' => $this->tmpBaseDir, |
|
140 | + ] |
|
141 | + ); |
|
142 | + return false; |
|
143 | + } |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Remove the temporary files and folders generated during this request |
|
148 | - */ |
|
149 | - public function clean() { |
|
150 | - $this->cleanFiles($this->current); |
|
151 | - } |
|
146 | + /** |
|
147 | + * Remove the temporary files and folders generated during this request |
|
148 | + */ |
|
149 | + public function clean() { |
|
150 | + $this->cleanFiles($this->current); |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * @param string[] $files |
|
155 | - */ |
|
156 | - protected function cleanFiles($files) { |
|
157 | - foreach ($files as $file) { |
|
158 | - if (file_exists($file)) { |
|
159 | - try { |
|
160 | - \OC_Helper::rmdirr($file); |
|
161 | - } catch (\UnexpectedValueException $ex) { |
|
162 | - $this->log->warning( |
|
163 | - "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
164 | - [ |
|
165 | - 'file' => $file, |
|
166 | - 'error' => $ex->getMessage(), |
|
167 | - ] |
|
168 | - ); |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
153 | + /** |
|
154 | + * @param string[] $files |
|
155 | + */ |
|
156 | + protected function cleanFiles($files) { |
|
157 | + foreach ($files as $file) { |
|
158 | + if (file_exists($file)) { |
|
159 | + try { |
|
160 | + \OC_Helper::rmdirr($file); |
|
161 | + } catch (\UnexpectedValueException $ex) { |
|
162 | + $this->log->warning( |
|
163 | + "Error deleting temporary file/folder: {file} - Reason: {error}", |
|
164 | + [ |
|
165 | + 'file' => $file, |
|
166 | + 'error' => $ex->getMessage(), |
|
167 | + ] |
|
168 | + ); |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Remove old temporary files and folders that were failed to be cleaned |
|
176 | - */ |
|
177 | - public function cleanOld() { |
|
178 | - $this->cleanFiles($this->getOldFiles()); |
|
179 | - } |
|
174 | + /** |
|
175 | + * Remove old temporary files and folders that were failed to be cleaned |
|
176 | + */ |
|
177 | + public function cleanOld() { |
|
178 | + $this->cleanFiles($this->getOldFiles()); |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Get all temporary files and folders generated by oc older than an hour |
|
183 | - * |
|
184 | - * @return string[] |
|
185 | - */ |
|
186 | - protected function getOldFiles() { |
|
187 | - $cutOfTime = time() - 3600; |
|
188 | - $files = []; |
|
189 | - $dh = opendir($this->tmpBaseDir); |
|
190 | - if ($dh) { |
|
191 | - while (($file = readdir($dh)) !== false) { |
|
192 | - if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
193 | - $path = $this->tmpBaseDir . '/' . $file; |
|
194 | - $mtime = filemtime($path); |
|
195 | - if ($mtime < $cutOfTime) { |
|
196 | - $files[] = $path; |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - return $files; |
|
202 | - } |
|
181 | + /** |
|
182 | + * Get all temporary files and folders generated by oc older than an hour |
|
183 | + * |
|
184 | + * @return string[] |
|
185 | + */ |
|
186 | + protected function getOldFiles() { |
|
187 | + $cutOfTime = time() - 3600; |
|
188 | + $files = []; |
|
189 | + $dh = opendir($this->tmpBaseDir); |
|
190 | + if ($dh) { |
|
191 | + while (($file = readdir($dh)) !== false) { |
|
192 | + if (substr($file, 0, 7) === self::TMP_PREFIX) { |
|
193 | + $path = $this->tmpBaseDir . '/' . $file; |
|
194 | + $mtime = filemtime($path); |
|
195 | + if ($mtime < $cutOfTime) { |
|
196 | + $files[] = $path; |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + return $files; |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Get the temporary base directory configured on the server |
|
206 | - * |
|
207 | - * @return string Path to the temporary directory or null |
|
208 | - * @throws \UnexpectedValueException |
|
209 | - */ |
|
210 | - public function getTempBaseDir() { |
|
211 | - if ($this->tmpBaseDir) { |
|
212 | - return $this->tmpBaseDir; |
|
213 | - } |
|
204 | + /** |
|
205 | + * Get the temporary base directory configured on the server |
|
206 | + * |
|
207 | + * @return string Path to the temporary directory or null |
|
208 | + * @throws \UnexpectedValueException |
|
209 | + */ |
|
210 | + public function getTempBaseDir() { |
|
211 | + if ($this->tmpBaseDir) { |
|
212 | + return $this->tmpBaseDir; |
|
213 | + } |
|
214 | 214 | |
215 | - $directories = []; |
|
216 | - if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
217 | - $directories[] = $temp; |
|
218 | - } |
|
219 | - if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) { |
|
220 | - $directories[] = $temp; |
|
221 | - } |
|
222 | - if ($temp = getenv('TMP')) { |
|
223 | - $directories[] = $temp; |
|
224 | - } |
|
225 | - if ($temp = getenv('TEMP')) { |
|
226 | - $directories[] = $temp; |
|
227 | - } |
|
228 | - if ($temp = getenv('TMPDIR')) { |
|
229 | - $directories[] = $temp; |
|
230 | - } |
|
231 | - if ($temp = sys_get_temp_dir()) { |
|
232 | - $directories[] = $temp; |
|
233 | - } |
|
215 | + $directories = []; |
|
216 | + if ($temp = $this->config->getSystemValue('tempdirectory', null)) { |
|
217 | + $directories[] = $temp; |
|
218 | + } |
|
219 | + if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) { |
|
220 | + $directories[] = $temp; |
|
221 | + } |
|
222 | + if ($temp = getenv('TMP')) { |
|
223 | + $directories[] = $temp; |
|
224 | + } |
|
225 | + if ($temp = getenv('TEMP')) { |
|
226 | + $directories[] = $temp; |
|
227 | + } |
|
228 | + if ($temp = getenv('TMPDIR')) { |
|
229 | + $directories[] = $temp; |
|
230 | + } |
|
231 | + if ($temp = sys_get_temp_dir()) { |
|
232 | + $directories[] = $temp; |
|
233 | + } |
|
234 | 234 | |
235 | - foreach ($directories as $dir) { |
|
236 | - if ($this->checkTemporaryDirectory($dir)) { |
|
237 | - return $dir; |
|
238 | - } |
|
239 | - } |
|
235 | + foreach ($directories as $dir) { |
|
236 | + if ($this->checkTemporaryDirectory($dir)) { |
|
237 | + return $dir; |
|
238 | + } |
|
239 | + } |
|
240 | 240 | |
241 | - $temp = tempnam(dirname(__FILE__), ''); |
|
242 | - if (file_exists($temp)) { |
|
243 | - unlink($temp); |
|
244 | - return dirname($temp); |
|
245 | - } |
|
246 | - throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
247 | - } |
|
241 | + $temp = tempnam(dirname(__FILE__), ''); |
|
242 | + if (file_exists($temp)) { |
|
243 | + unlink($temp); |
|
244 | + return dirname($temp); |
|
245 | + } |
|
246 | + throw new \UnexpectedValueException('Unable to detect system temporary directory'); |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Check if a temporary directory is ready for use |
|
251 | - * |
|
252 | - * @param mixed $directory |
|
253 | - * @return bool |
|
254 | - */ |
|
255 | - private function checkTemporaryDirectory($directory) { |
|
256 | - // suppress any possible errors caused by is_writable |
|
257 | - // checks missing or invalid path or characters, wrong permissions etc |
|
258 | - try { |
|
259 | - if (is_writable($directory)) { |
|
260 | - return true; |
|
261 | - } |
|
262 | - } catch (\Exception $e) { |
|
263 | - } |
|
264 | - $this->log->warning('Temporary directory {dir} is not present or writable', |
|
265 | - ['dir' => $directory] |
|
266 | - ); |
|
267 | - return false; |
|
268 | - } |
|
249 | + /** |
|
250 | + * Check if a temporary directory is ready for use |
|
251 | + * |
|
252 | + * @param mixed $directory |
|
253 | + * @return bool |
|
254 | + */ |
|
255 | + private function checkTemporaryDirectory($directory) { |
|
256 | + // suppress any possible errors caused by is_writable |
|
257 | + // checks missing or invalid path or characters, wrong permissions etc |
|
258 | + try { |
|
259 | + if (is_writable($directory)) { |
|
260 | + return true; |
|
261 | + } |
|
262 | + } catch (\Exception $e) { |
|
263 | + } |
|
264 | + $this->log->warning('Temporary directory {dir} is not present or writable', |
|
265 | + ['dir' => $directory] |
|
266 | + ); |
|
267 | + return false; |
|
268 | + } |
|
269 | 269 | |
270 | - /** |
|
271 | - * Override the temporary base directory |
|
272 | - * |
|
273 | - * @param string $directory |
|
274 | - */ |
|
275 | - public function overrideTempBaseDir($directory) { |
|
276 | - $this->tmpBaseDir = $directory; |
|
277 | - } |
|
270 | + /** |
|
271 | + * Override the temporary base directory |
|
272 | + * |
|
273 | + * @param string $directory |
|
274 | + */ |
|
275 | + public function overrideTempBaseDir($directory) { |
|
276 | + $this->tmpBaseDir = $directory; |
|
277 | + } |
|
278 | 278 | |
279 | 279 | } |
@@ -33,193 +33,193 @@ |
||
33 | 33 | use OCP\IMemcache; |
34 | 34 | |
35 | 35 | class Memcached extends Cache implements IMemcache { |
36 | - use CASTrait; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var \Memcached $cache |
|
40 | - */ |
|
41 | - private static $cache = null; |
|
42 | - |
|
43 | - use CADTrait; |
|
44 | - |
|
45 | - public function __construct($prefix = '') { |
|
46 | - parent::__construct($prefix); |
|
47 | - if (is_null(self::$cache)) { |
|
48 | - self::$cache = new \Memcached(); |
|
49 | - |
|
50 | - $defaultOptions = [ |
|
51 | - \Memcached::OPT_CONNECT_TIMEOUT => 50, |
|
52 | - \Memcached::OPT_RETRY_TIMEOUT => 50, |
|
53 | - \Memcached::OPT_SEND_TIMEOUT => 50, |
|
54 | - \Memcached::OPT_RECV_TIMEOUT => 50, |
|
55 | - \Memcached::OPT_POLL_TIMEOUT => 50, |
|
56 | - |
|
57 | - // Enable compression |
|
58 | - \Memcached::OPT_COMPRESSION => true, |
|
59 | - |
|
60 | - // Turn on consistent hashing |
|
61 | - \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
|
62 | - |
|
63 | - // Enable Binary Protocol |
|
64 | - //\Memcached::OPT_BINARY_PROTOCOL => true, |
|
65 | - ]; |
|
66 | - // by default enable igbinary serializer if available |
|
67 | - if (\Memcached::HAVE_IGBINARY) { |
|
68 | - $defaultOptions[\Memcached::OPT_SERIALIZER] = |
|
69 | - \Memcached::SERIALIZER_IGBINARY; |
|
70 | - } |
|
71 | - $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []); |
|
72 | - if (is_array($options)) { |
|
73 | - $options = $options + $defaultOptions; |
|
74 | - self::$cache->setOptions($options); |
|
75 | - } else { |
|
76 | - throw new HintException("Expected 'memcached_options' config to be an array, got $options"); |
|
77 | - } |
|
78 | - |
|
79 | - $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers'); |
|
80 | - if (!$servers) { |
|
81 | - $server = \OC::$server->getSystemConfig()->getValue('memcached_server'); |
|
82 | - if ($server) { |
|
83 | - $servers = [$server]; |
|
84 | - } else { |
|
85 | - $servers = [['localhost', 11211]]; |
|
86 | - } |
|
87 | - } |
|
88 | - self::$cache->addServers($servers); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * entries in XCache gets namespaced to prevent collisions between owncloud instances and users |
|
94 | - */ |
|
95 | - protected function getNameSpace() { |
|
96 | - return $this->prefix; |
|
97 | - } |
|
98 | - |
|
99 | - public function get($key) { |
|
100 | - $result = self::$cache->get($this->getNameSpace() . $key); |
|
101 | - if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
|
102 | - return null; |
|
103 | - } else { |
|
104 | - return $result; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - public function set($key, $value, $ttl = 0) { |
|
109 | - if ($ttl > 0) { |
|
110 | - $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
111 | - } else { |
|
112 | - $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
113 | - } |
|
114 | - if ($result !== true) { |
|
115 | - $this->verifyReturnCode(); |
|
116 | - } |
|
117 | - return $result; |
|
118 | - } |
|
119 | - |
|
120 | - public function hasKey($key) { |
|
121 | - self::$cache->get($this->getNameSpace() . $key); |
|
122 | - return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
|
123 | - } |
|
124 | - |
|
125 | - public function remove($key) { |
|
126 | - $result= self::$cache->delete($this->getNameSpace() . $key); |
|
127 | - if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
|
128 | - $this->verifyReturnCode(); |
|
129 | - } |
|
130 | - return $result; |
|
131 | - } |
|
132 | - |
|
133 | - public function clear($prefix = '') { |
|
134 | - $prefix = $this->getNameSpace() . $prefix; |
|
135 | - $allKeys = self::$cache->getAllKeys(); |
|
136 | - if ($allKeys === false) { |
|
137 | - // newer Memcached doesn't like getAllKeys(), flush everything |
|
138 | - self::$cache->flush(); |
|
139 | - return true; |
|
140 | - } |
|
141 | - $keys = array(); |
|
142 | - $prefixLength = strlen($prefix); |
|
143 | - foreach ($allKeys as $key) { |
|
144 | - if (substr($key, 0, $prefixLength) === $prefix) { |
|
145 | - $keys[] = $key; |
|
146 | - } |
|
147 | - } |
|
148 | - if (method_exists(self::$cache, 'deleteMulti')) { |
|
149 | - self::$cache->deleteMulti($keys); |
|
150 | - } else { |
|
151 | - foreach ($keys as $key) { |
|
152 | - self::$cache->delete($key); |
|
153 | - } |
|
154 | - } |
|
155 | - return true; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Set a value in the cache if it's not already stored |
|
160 | - * |
|
161 | - * @param string $key |
|
162 | - * @param mixed $value |
|
163 | - * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
164 | - * @return bool |
|
165 | - * @throws \Exception |
|
166 | - */ |
|
167 | - public function add($key, $value, $ttl = 0) { |
|
168 | - $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
169 | - if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
|
170 | - $this->verifyReturnCode(); |
|
171 | - } |
|
172 | - return $result; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Increase a stored number |
|
177 | - * |
|
178 | - * @param string $key |
|
179 | - * @param int $step |
|
180 | - * @return int | bool |
|
181 | - */ |
|
182 | - public function inc($key, $step = 1) { |
|
183 | - $this->add($key, 0); |
|
184 | - $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
185 | - |
|
186 | - if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
187 | - return false; |
|
188 | - } |
|
189 | - |
|
190 | - return $result; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Decrease a stored number |
|
195 | - * |
|
196 | - * @param string $key |
|
197 | - * @param int $step |
|
198 | - * @return int | bool |
|
199 | - */ |
|
200 | - public function dec($key, $step = 1) { |
|
201 | - $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
202 | - |
|
203 | - if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
204 | - return false; |
|
205 | - } |
|
206 | - |
|
207 | - return $result; |
|
208 | - } |
|
209 | - |
|
210 | - static public function isAvailable() { |
|
211 | - return extension_loaded('memcached'); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @throws \Exception |
|
216 | - */ |
|
217 | - private function verifyReturnCode() { |
|
218 | - $code = self::$cache->getResultCode(); |
|
219 | - if ($code === \Memcached::RES_SUCCESS) { |
|
220 | - return; |
|
221 | - } |
|
222 | - $message = self::$cache->getResultMessage(); |
|
223 | - throw new \Exception("Error $code interacting with memcached : $message"); |
|
224 | - } |
|
36 | + use CASTrait; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var \Memcached $cache |
|
40 | + */ |
|
41 | + private static $cache = null; |
|
42 | + |
|
43 | + use CADTrait; |
|
44 | + |
|
45 | + public function __construct($prefix = '') { |
|
46 | + parent::__construct($prefix); |
|
47 | + if (is_null(self::$cache)) { |
|
48 | + self::$cache = new \Memcached(); |
|
49 | + |
|
50 | + $defaultOptions = [ |
|
51 | + \Memcached::OPT_CONNECT_TIMEOUT => 50, |
|
52 | + \Memcached::OPT_RETRY_TIMEOUT => 50, |
|
53 | + \Memcached::OPT_SEND_TIMEOUT => 50, |
|
54 | + \Memcached::OPT_RECV_TIMEOUT => 50, |
|
55 | + \Memcached::OPT_POLL_TIMEOUT => 50, |
|
56 | + |
|
57 | + // Enable compression |
|
58 | + \Memcached::OPT_COMPRESSION => true, |
|
59 | + |
|
60 | + // Turn on consistent hashing |
|
61 | + \Memcached::OPT_LIBKETAMA_COMPATIBLE => true, |
|
62 | + |
|
63 | + // Enable Binary Protocol |
|
64 | + //\Memcached::OPT_BINARY_PROTOCOL => true, |
|
65 | + ]; |
|
66 | + // by default enable igbinary serializer if available |
|
67 | + if (\Memcached::HAVE_IGBINARY) { |
|
68 | + $defaultOptions[\Memcached::OPT_SERIALIZER] = |
|
69 | + \Memcached::SERIALIZER_IGBINARY; |
|
70 | + } |
|
71 | + $options = \OC::$server->getConfig()->getSystemValue('memcached_options', []); |
|
72 | + if (is_array($options)) { |
|
73 | + $options = $options + $defaultOptions; |
|
74 | + self::$cache->setOptions($options); |
|
75 | + } else { |
|
76 | + throw new HintException("Expected 'memcached_options' config to be an array, got $options"); |
|
77 | + } |
|
78 | + |
|
79 | + $servers = \OC::$server->getSystemConfig()->getValue('memcached_servers'); |
|
80 | + if (!$servers) { |
|
81 | + $server = \OC::$server->getSystemConfig()->getValue('memcached_server'); |
|
82 | + if ($server) { |
|
83 | + $servers = [$server]; |
|
84 | + } else { |
|
85 | + $servers = [['localhost', 11211]]; |
|
86 | + } |
|
87 | + } |
|
88 | + self::$cache->addServers($servers); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * entries in XCache gets namespaced to prevent collisions between owncloud instances and users |
|
94 | + */ |
|
95 | + protected function getNameSpace() { |
|
96 | + return $this->prefix; |
|
97 | + } |
|
98 | + |
|
99 | + public function get($key) { |
|
100 | + $result = self::$cache->get($this->getNameSpace() . $key); |
|
101 | + if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) { |
|
102 | + return null; |
|
103 | + } else { |
|
104 | + return $result; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + public function set($key, $value, $ttl = 0) { |
|
109 | + if ($ttl > 0) { |
|
110 | + $result = self::$cache->set($this->getNameSpace() . $key, $value, $ttl); |
|
111 | + } else { |
|
112 | + $result = self::$cache->set($this->getNameSpace() . $key, $value); |
|
113 | + } |
|
114 | + if ($result !== true) { |
|
115 | + $this->verifyReturnCode(); |
|
116 | + } |
|
117 | + return $result; |
|
118 | + } |
|
119 | + |
|
120 | + public function hasKey($key) { |
|
121 | + self::$cache->get($this->getNameSpace() . $key); |
|
122 | + return self::$cache->getResultCode() === \Memcached::RES_SUCCESS; |
|
123 | + } |
|
124 | + |
|
125 | + public function remove($key) { |
|
126 | + $result= self::$cache->delete($this->getNameSpace() . $key); |
|
127 | + if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) { |
|
128 | + $this->verifyReturnCode(); |
|
129 | + } |
|
130 | + return $result; |
|
131 | + } |
|
132 | + |
|
133 | + public function clear($prefix = '') { |
|
134 | + $prefix = $this->getNameSpace() . $prefix; |
|
135 | + $allKeys = self::$cache->getAllKeys(); |
|
136 | + if ($allKeys === false) { |
|
137 | + // newer Memcached doesn't like getAllKeys(), flush everything |
|
138 | + self::$cache->flush(); |
|
139 | + return true; |
|
140 | + } |
|
141 | + $keys = array(); |
|
142 | + $prefixLength = strlen($prefix); |
|
143 | + foreach ($allKeys as $key) { |
|
144 | + if (substr($key, 0, $prefixLength) === $prefix) { |
|
145 | + $keys[] = $key; |
|
146 | + } |
|
147 | + } |
|
148 | + if (method_exists(self::$cache, 'deleteMulti')) { |
|
149 | + self::$cache->deleteMulti($keys); |
|
150 | + } else { |
|
151 | + foreach ($keys as $key) { |
|
152 | + self::$cache->delete($key); |
|
153 | + } |
|
154 | + } |
|
155 | + return true; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Set a value in the cache if it's not already stored |
|
160 | + * |
|
161 | + * @param string $key |
|
162 | + * @param mixed $value |
|
163 | + * @param int $ttl Time To Live in seconds. Defaults to 60*60*24 |
|
164 | + * @return bool |
|
165 | + * @throws \Exception |
|
166 | + */ |
|
167 | + public function add($key, $value, $ttl = 0) { |
|
168 | + $result = self::$cache->add($this->getPrefix() . $key, $value, $ttl); |
|
169 | + if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) { |
|
170 | + $this->verifyReturnCode(); |
|
171 | + } |
|
172 | + return $result; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Increase a stored number |
|
177 | + * |
|
178 | + * @param string $key |
|
179 | + * @param int $step |
|
180 | + * @return int | bool |
|
181 | + */ |
|
182 | + public function inc($key, $step = 1) { |
|
183 | + $this->add($key, 0); |
|
184 | + $result = self::$cache->increment($this->getPrefix() . $key, $step); |
|
185 | + |
|
186 | + if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
187 | + return false; |
|
188 | + } |
|
189 | + |
|
190 | + return $result; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Decrease a stored number |
|
195 | + * |
|
196 | + * @param string $key |
|
197 | + * @param int $step |
|
198 | + * @return int | bool |
|
199 | + */ |
|
200 | + public function dec($key, $step = 1) { |
|
201 | + $result = self::$cache->decrement($this->getPrefix() . $key, $step); |
|
202 | + |
|
203 | + if (self::$cache->getResultCode() !== \Memcached::RES_SUCCESS) { |
|
204 | + return false; |
|
205 | + } |
|
206 | + |
|
207 | + return $result; |
|
208 | + } |
|
209 | + |
|
210 | + static public function isAvailable() { |
|
211 | + return extension_loaded('memcached'); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @throws \Exception |
|
216 | + */ |
|
217 | + private function verifyReturnCode() { |
|
218 | + $code = self::$cache->getResultCode(); |
|
219 | + if ($code === \Memcached::RES_SUCCESS) { |
|
220 | + return; |
|
221 | + } |
|
222 | + $message = self::$cache->getResultMessage(); |
|
223 | + throw new \Exception("Error $code interacting with memcached : $message"); |
|
224 | + } |
|
225 | 225 | } |
@@ -37,172 +37,172 @@ |
||
37 | 37 | */ |
38 | 38 | class CleanTags implements IRepairStep { |
39 | 39 | |
40 | - /** @var IDBConnection */ |
|
41 | - protected $connection; |
|
42 | - |
|
43 | - /** @var IUserManager */ |
|
44 | - protected $userManager; |
|
45 | - |
|
46 | - protected $deletedTags = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * @param IDBConnection $connection |
|
50 | - * @param IUserManager $userManager |
|
51 | - */ |
|
52 | - public function __construct(IDBConnection $connection, IUserManager $userManager) { |
|
53 | - $this->connection = $connection; |
|
54 | - $this->userManager = $userManager; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function getName() { |
|
61 | - return 'Clean tags and favorites'; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Updates the configuration after running an update |
|
66 | - */ |
|
67 | - public function run(IOutput $output) { |
|
68 | - $this->deleteOrphanTags($output); |
|
69 | - $this->deleteOrphanFileEntries($output); |
|
70 | - $this->deleteOrphanTagEntries($output); |
|
71 | - $this->deleteOrphanCategoryEntries($output); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Delete tags for deleted users |
|
76 | - */ |
|
77 | - protected function deleteOrphanTags(IOutput $output) { |
|
78 | - $offset = 0; |
|
79 | - while ($this->checkTags($offset)) { |
|
80 | - $offset += 50; |
|
81 | - } |
|
82 | - |
|
83 | - $output->info(sprintf('%d tags of deleted users have been removed.', $this->deletedTags)); |
|
84 | - } |
|
85 | - |
|
86 | - protected function checkTags($offset) { |
|
87 | - $query = $this->connection->getQueryBuilder(); |
|
88 | - $query->select('uid') |
|
89 | - ->from('vcategory') |
|
90 | - ->groupBy('uid') |
|
91 | - ->orderBy('uid') |
|
92 | - ->setMaxResults(50) |
|
93 | - ->setFirstResult($offset); |
|
94 | - $result = $query->execute(); |
|
95 | - |
|
96 | - $users = []; |
|
97 | - $hadResults = false; |
|
98 | - while ($row = $result->fetch()) { |
|
99 | - $hadResults = true; |
|
100 | - if (!$this->userManager->userExists($row['uid'])) { |
|
101 | - $users[] = $row['uid']; |
|
102 | - } |
|
103 | - } |
|
104 | - $result->closeCursor(); |
|
105 | - |
|
106 | - if (!$hadResults) { |
|
107 | - // No more tags, stop looping |
|
108 | - return false; |
|
109 | - } |
|
110 | - |
|
111 | - if (!empty($users)) { |
|
112 | - $query = $this->connection->getQueryBuilder(); |
|
113 | - $query->delete('vcategory') |
|
114 | - ->where($query->expr()->in('uid', $query->createNamedParameter($users, IQueryBuilder::PARAM_STR_ARRAY))); |
|
115 | - $this->deletedTags += $query->execute(); |
|
116 | - } |
|
117 | - return true; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Delete tag entries for deleted files |
|
122 | - */ |
|
123 | - protected function deleteOrphanFileEntries(IOutput $output) { |
|
124 | - $this->deleteOrphanEntries( |
|
125 | - $output, |
|
126 | - '%d tags for delete files have been removed.', |
|
127 | - 'vcategory_to_object', 'objid', |
|
128 | - 'filecache', 'fileid', 'path_hash' |
|
129 | - ); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Delete tag entries for deleted tags |
|
134 | - */ |
|
135 | - protected function deleteOrphanTagEntries(IOutput $output) { |
|
136 | - $this->deleteOrphanEntries( |
|
137 | - $output, |
|
138 | - '%d tag entries for deleted tags have been removed.', |
|
139 | - 'vcategory_to_object', 'categoryid', |
|
140 | - 'vcategory', 'id', 'uid' |
|
141 | - ); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Delete tags that have no entries |
|
146 | - */ |
|
147 | - protected function deleteOrphanCategoryEntries(IOutput $output) { |
|
148 | - $this->deleteOrphanEntries( |
|
149 | - $output, |
|
150 | - '%d tags with no entries have been removed.', |
|
151 | - 'vcategory', 'id', |
|
152 | - 'vcategory_to_object', 'categoryid', 'type' |
|
153 | - ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Deletes all entries from $deleteTable that do not have a matching entry in $sourceTable |
|
158 | - * |
|
159 | - * A query joins $deleteTable.$deleteId = $sourceTable.$sourceId and checks |
|
160 | - * whether $sourceNullColumn is null. If it is null, the entry in $deleteTable |
|
161 | - * is being deleted. |
|
162 | - * |
|
163 | - * @param string $repairInfo |
|
164 | - * @param string $deleteTable |
|
165 | - * @param string $deleteId |
|
166 | - * @param string $sourceTable |
|
167 | - * @param string $sourceId |
|
168 | - * @param string $sourceNullColumn If this column is null in the source table, |
|
169 | - * the entry is deleted in the $deleteTable |
|
170 | - * @suppress SqlInjectionChecker |
|
171 | - */ |
|
172 | - protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) { |
|
173 | - $qb = $this->connection->getQueryBuilder(); |
|
174 | - |
|
175 | - $qb->select('d.' . $deleteId) |
|
176 | - ->from($deleteTable, 'd') |
|
177 | - ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, 's.' . $sourceId)) |
|
178 | - ->where( |
|
179 | - $qb->expr()->eq('d.type', $qb->expr()->literal('files')) |
|
180 | - ) |
|
181 | - ->andWhere( |
|
182 | - $qb->expr()->isNull('s.' . $sourceNullColumn) |
|
183 | - ); |
|
184 | - $result = $qb->execute(); |
|
185 | - |
|
186 | - $orphanItems = array(); |
|
187 | - while ($row = $result->fetch()) { |
|
188 | - $orphanItems[] = (int) $row[$deleteId]; |
|
189 | - } |
|
190 | - |
|
191 | - if (!empty($orphanItems)) { |
|
192 | - $orphanItemsBatch = array_chunk($orphanItems, 200); |
|
193 | - foreach ($orphanItemsBatch as $items) { |
|
194 | - $qb->delete($deleteTable) |
|
195 | - ->where( |
|
196 | - $qb->expr()->eq('type', $qb->expr()->literal('files')) |
|
197 | - ) |
|
198 | - ->andWhere($qb->expr()->in($deleteId, $qb->createParameter('ids'))); |
|
199 | - $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY); |
|
200 | - $qb->execute(); |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - if ($repairInfo) { |
|
205 | - $output->info(sprintf($repairInfo, count($orphanItems))); |
|
206 | - } |
|
207 | - } |
|
40 | + /** @var IDBConnection */ |
|
41 | + protected $connection; |
|
42 | + |
|
43 | + /** @var IUserManager */ |
|
44 | + protected $userManager; |
|
45 | + |
|
46 | + protected $deletedTags = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * @param IDBConnection $connection |
|
50 | + * @param IUserManager $userManager |
|
51 | + */ |
|
52 | + public function __construct(IDBConnection $connection, IUserManager $userManager) { |
|
53 | + $this->connection = $connection; |
|
54 | + $this->userManager = $userManager; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function getName() { |
|
61 | + return 'Clean tags and favorites'; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Updates the configuration after running an update |
|
66 | + */ |
|
67 | + public function run(IOutput $output) { |
|
68 | + $this->deleteOrphanTags($output); |
|
69 | + $this->deleteOrphanFileEntries($output); |
|
70 | + $this->deleteOrphanTagEntries($output); |
|
71 | + $this->deleteOrphanCategoryEntries($output); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Delete tags for deleted users |
|
76 | + */ |
|
77 | + protected function deleteOrphanTags(IOutput $output) { |
|
78 | + $offset = 0; |
|
79 | + while ($this->checkTags($offset)) { |
|
80 | + $offset += 50; |
|
81 | + } |
|
82 | + |
|
83 | + $output->info(sprintf('%d tags of deleted users have been removed.', $this->deletedTags)); |
|
84 | + } |
|
85 | + |
|
86 | + protected function checkTags($offset) { |
|
87 | + $query = $this->connection->getQueryBuilder(); |
|
88 | + $query->select('uid') |
|
89 | + ->from('vcategory') |
|
90 | + ->groupBy('uid') |
|
91 | + ->orderBy('uid') |
|
92 | + ->setMaxResults(50) |
|
93 | + ->setFirstResult($offset); |
|
94 | + $result = $query->execute(); |
|
95 | + |
|
96 | + $users = []; |
|
97 | + $hadResults = false; |
|
98 | + while ($row = $result->fetch()) { |
|
99 | + $hadResults = true; |
|
100 | + if (!$this->userManager->userExists($row['uid'])) { |
|
101 | + $users[] = $row['uid']; |
|
102 | + } |
|
103 | + } |
|
104 | + $result->closeCursor(); |
|
105 | + |
|
106 | + if (!$hadResults) { |
|
107 | + // No more tags, stop looping |
|
108 | + return false; |
|
109 | + } |
|
110 | + |
|
111 | + if (!empty($users)) { |
|
112 | + $query = $this->connection->getQueryBuilder(); |
|
113 | + $query->delete('vcategory') |
|
114 | + ->where($query->expr()->in('uid', $query->createNamedParameter($users, IQueryBuilder::PARAM_STR_ARRAY))); |
|
115 | + $this->deletedTags += $query->execute(); |
|
116 | + } |
|
117 | + return true; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Delete tag entries for deleted files |
|
122 | + */ |
|
123 | + protected function deleteOrphanFileEntries(IOutput $output) { |
|
124 | + $this->deleteOrphanEntries( |
|
125 | + $output, |
|
126 | + '%d tags for delete files have been removed.', |
|
127 | + 'vcategory_to_object', 'objid', |
|
128 | + 'filecache', 'fileid', 'path_hash' |
|
129 | + ); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Delete tag entries for deleted tags |
|
134 | + */ |
|
135 | + protected function deleteOrphanTagEntries(IOutput $output) { |
|
136 | + $this->deleteOrphanEntries( |
|
137 | + $output, |
|
138 | + '%d tag entries for deleted tags have been removed.', |
|
139 | + 'vcategory_to_object', 'categoryid', |
|
140 | + 'vcategory', 'id', 'uid' |
|
141 | + ); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Delete tags that have no entries |
|
146 | + */ |
|
147 | + protected function deleteOrphanCategoryEntries(IOutput $output) { |
|
148 | + $this->deleteOrphanEntries( |
|
149 | + $output, |
|
150 | + '%d tags with no entries have been removed.', |
|
151 | + 'vcategory', 'id', |
|
152 | + 'vcategory_to_object', 'categoryid', 'type' |
|
153 | + ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Deletes all entries from $deleteTable that do not have a matching entry in $sourceTable |
|
158 | + * |
|
159 | + * A query joins $deleteTable.$deleteId = $sourceTable.$sourceId and checks |
|
160 | + * whether $sourceNullColumn is null. If it is null, the entry in $deleteTable |
|
161 | + * is being deleted. |
|
162 | + * |
|
163 | + * @param string $repairInfo |
|
164 | + * @param string $deleteTable |
|
165 | + * @param string $deleteId |
|
166 | + * @param string $sourceTable |
|
167 | + * @param string $sourceId |
|
168 | + * @param string $sourceNullColumn If this column is null in the source table, |
|
169 | + * the entry is deleted in the $deleteTable |
|
170 | + * @suppress SqlInjectionChecker |
|
171 | + */ |
|
172 | + protected function deleteOrphanEntries(IOutput $output, $repairInfo, $deleteTable, $deleteId, $sourceTable, $sourceId, $sourceNullColumn) { |
|
173 | + $qb = $this->connection->getQueryBuilder(); |
|
174 | + |
|
175 | + $qb->select('d.' . $deleteId) |
|
176 | + ->from($deleteTable, 'd') |
|
177 | + ->leftJoin('d', $sourceTable, 's', $qb->expr()->eq('d.' . $deleteId, 's.' . $sourceId)) |
|
178 | + ->where( |
|
179 | + $qb->expr()->eq('d.type', $qb->expr()->literal('files')) |
|
180 | + ) |
|
181 | + ->andWhere( |
|
182 | + $qb->expr()->isNull('s.' . $sourceNullColumn) |
|
183 | + ); |
|
184 | + $result = $qb->execute(); |
|
185 | + |
|
186 | + $orphanItems = array(); |
|
187 | + while ($row = $result->fetch()) { |
|
188 | + $orphanItems[] = (int) $row[$deleteId]; |
|
189 | + } |
|
190 | + |
|
191 | + if (!empty($orphanItems)) { |
|
192 | + $orphanItemsBatch = array_chunk($orphanItems, 200); |
|
193 | + foreach ($orphanItemsBatch as $items) { |
|
194 | + $qb->delete($deleteTable) |
|
195 | + ->where( |
|
196 | + $qb->expr()->eq('type', $qb->expr()->literal('files')) |
|
197 | + ) |
|
198 | + ->andWhere($qb->expr()->in($deleteId, $qb->createParameter('ids'))); |
|
199 | + $qb->setParameter('ids', $items, IQueryBuilder::PARAM_INT_ARRAY); |
|
200 | + $qb->execute(); |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + if ($repairInfo) { |
|
205 | + $output->info(sprintf($repairInfo, count($orphanItems))); |
|
206 | + } |
|
207 | + } |
|
208 | 208 | } |
@@ -29,179 +29,179 @@ |
||
29 | 29 | |
30 | 30 | class MigrationSchemaChecker extends NodeVisitorAbstract { |
31 | 31 | |
32 | - /** @var string */ |
|
33 | - protected $schemaVariableName = null; |
|
34 | - /** @var array */ |
|
35 | - protected $tableVariableNames = []; |
|
36 | - /** @var array */ |
|
37 | - public $errors = []; |
|
32 | + /** @var string */ |
|
33 | + protected $schemaVariableName = null; |
|
34 | + /** @var array */ |
|
35 | + protected $tableVariableNames = []; |
|
36 | + /** @var array */ |
|
37 | + public $errors = []; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param Node $node |
|
41 | - * @return void |
|
42 | - * |
|
43 | - * @suppress PhanUndeclaredProperty |
|
44 | - */ |
|
45 | - public function enterNode(Node $node) { |
|
46 | - /** |
|
47 | - * Check tables |
|
48 | - */ |
|
49 | - if ($this->schemaVariableName !== null && |
|
50 | - $node instanceof Node\Expr\Assign && |
|
51 | - $node->var instanceof Node\Expr\Variable && |
|
52 | - $node->expr instanceof Node\Expr\MethodCall && |
|
53 | - $node->expr->var instanceof Node\Expr\Variable && |
|
54 | - $node->expr->var->name === $this->schemaVariableName) { |
|
39 | + /** |
|
40 | + * @param Node $node |
|
41 | + * @return void |
|
42 | + * |
|
43 | + * @suppress PhanUndeclaredProperty |
|
44 | + */ |
|
45 | + public function enterNode(Node $node) { |
|
46 | + /** |
|
47 | + * Check tables |
|
48 | + */ |
|
49 | + if ($this->schemaVariableName !== null && |
|
50 | + $node instanceof Node\Expr\Assign && |
|
51 | + $node->var instanceof Node\Expr\Variable && |
|
52 | + $node->expr instanceof Node\Expr\MethodCall && |
|
53 | + $node->expr->var instanceof Node\Expr\Variable && |
|
54 | + $node->expr->var->name === $this->schemaVariableName) { |
|
55 | 55 | |
56 | - if ($node->expr->name === 'createTable') { |
|
57 | - if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) { |
|
58 | - if (!$this->checkNameLength($node->expr->args[0]->value->value)) { |
|
59 | - $this->errors[] = [ |
|
60 | - 'line' => $node->getLine(), |
|
61 | - 'disallowedToken' => $node->expr->args[0]->value->value, |
|
62 | - 'reason' => 'Table name is too long (max. 27)', |
|
63 | - ]; |
|
64 | - } else { |
|
65 | - $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value; |
|
66 | - } |
|
67 | - } |
|
68 | - } else if ($node->expr->name === 'getTable') { |
|
69 | - if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) { |
|
70 | - $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value; |
|
71 | - } |
|
72 | - } |
|
73 | - } else if ($this->schemaVariableName !== null && |
|
74 | - $node instanceof Node\Expr\MethodCall && |
|
75 | - $node->var instanceof Node\Expr\Variable && |
|
76 | - $node->var->name === $this->schemaVariableName) { |
|
56 | + if ($node->expr->name === 'createTable') { |
|
57 | + if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) { |
|
58 | + if (!$this->checkNameLength($node->expr->args[0]->value->value)) { |
|
59 | + $this->errors[] = [ |
|
60 | + 'line' => $node->getLine(), |
|
61 | + 'disallowedToken' => $node->expr->args[0]->value->value, |
|
62 | + 'reason' => 'Table name is too long (max. 27)', |
|
63 | + ]; |
|
64 | + } else { |
|
65 | + $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value; |
|
66 | + } |
|
67 | + } |
|
68 | + } else if ($node->expr->name === 'getTable') { |
|
69 | + if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) { |
|
70 | + $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value; |
|
71 | + } |
|
72 | + } |
|
73 | + } else if ($this->schemaVariableName !== null && |
|
74 | + $node instanceof Node\Expr\MethodCall && |
|
75 | + $node->var instanceof Node\Expr\Variable && |
|
76 | + $node->var->name === $this->schemaVariableName) { |
|
77 | 77 | |
78 | - if ($node->name === 'renameTable') { |
|
79 | - $this->errors[] = [ |
|
80 | - 'line' => $node->getLine(), |
|
81 | - 'disallowedToken' => 'Deprecated method', |
|
82 | - 'reason' => sprintf( |
|
83 | - '`$%s->renameTable()` must not be used', |
|
84 | - $node->var->name |
|
85 | - ), |
|
86 | - ]; |
|
87 | - } |
|
78 | + if ($node->name === 'renameTable') { |
|
79 | + $this->errors[] = [ |
|
80 | + 'line' => $node->getLine(), |
|
81 | + 'disallowedToken' => 'Deprecated method', |
|
82 | + 'reason' => sprintf( |
|
83 | + '`$%s->renameTable()` must not be used', |
|
84 | + $node->var->name |
|
85 | + ), |
|
86 | + ]; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Check columns and Indexes |
|
91 | - */ |
|
92 | - } else if (!empty($this->tableVariableNames) && |
|
93 | - $node instanceof Node\Expr\MethodCall && |
|
94 | - $node->var instanceof Node\Expr\Variable && |
|
95 | - isset($this->tableVariableNames[$node->var->name])) { |
|
89 | + /** |
|
90 | + * Check columns and Indexes |
|
91 | + */ |
|
92 | + } else if (!empty($this->tableVariableNames) && |
|
93 | + $node instanceof Node\Expr\MethodCall && |
|
94 | + $node->var instanceof Node\Expr\Variable && |
|
95 | + isset($this->tableVariableNames[$node->var->name])) { |
|
96 | 96 | |
97 | - if ($node->name === 'addColumn' || $node->name === 'changeColumn') { |
|
98 | - if (isset($node->args[0]) && $node->args[0]->value instanceof Node\Scalar\String_) { |
|
99 | - if (!$this->checkNameLength($node->args[0]->value->value)) { |
|
100 | - $this->errors[] = [ |
|
101 | - 'line' => $node->getLine(), |
|
102 | - 'disallowedToken' => $node->args[0]->value->value, |
|
103 | - 'reason' => sprintf( |
|
104 | - 'Column name is too long on table `%s` (max. 27)', |
|
105 | - $this->tableVariableNames[$node->var->name] |
|
106 | - ), |
|
107 | - ]; |
|
108 | - } |
|
97 | + if ($node->name === 'addColumn' || $node->name === 'changeColumn') { |
|
98 | + if (isset($node->args[0]) && $node->args[0]->value instanceof Node\Scalar\String_) { |
|
99 | + if (!$this->checkNameLength($node->args[0]->value->value)) { |
|
100 | + $this->errors[] = [ |
|
101 | + 'line' => $node->getLine(), |
|
102 | + 'disallowedToken' => $node->args[0]->value->value, |
|
103 | + 'reason' => sprintf( |
|
104 | + 'Column name is too long on table `%s` (max. 27)', |
|
105 | + $this->tableVariableNames[$node->var->name] |
|
106 | + ), |
|
107 | + ]; |
|
108 | + } |
|
109 | 109 | |
110 | - // On autoincrement the max length of the table name is 21 instead of 27 |
|
111 | - if (isset($node->args[2]) && $node->args[2]->value instanceof Node\Expr\Array_) { |
|
112 | - /** @var Node\Expr\Array_ $options */ |
|
113 | - $options = $node->args[2]->value; |
|
114 | - if ($this->checkColumnForAutoincrement($options)) { |
|
115 | - if (!$this->checkNameLength($this->tableVariableNames[$node->var->name], true)) { |
|
116 | - $this->errors[] = [ |
|
117 | - 'line' => $node->getLine(), |
|
118 | - 'disallowedToken' => $this->tableVariableNames[$node->var->name], |
|
119 | - 'reason' => 'Table name is too long because of autoincrement (max. 21)', |
|
120 | - ]; |
|
121 | - } |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } else if ($node->name === 'addIndex' || |
|
126 | - $node->name === 'addUniqueIndex' || |
|
127 | - $node->name === 'renameIndex' || |
|
128 | - $node->name === 'setPrimaryKey') { |
|
129 | - if (isset($node->args[1]) && $node->args[1]->value instanceof Node\Scalar\String_) { |
|
130 | - if (!$this->checkNameLength($node->args[1]->value->value)) { |
|
131 | - $this->errors[] = [ |
|
132 | - 'line' => $node->getLine(), |
|
133 | - 'disallowedToken' => $node->args[1]->value->value, |
|
134 | - 'reason' => sprintf( |
|
135 | - 'Index name is too long on table `%s` (max. 27)', |
|
136 | - $this->tableVariableNames[$node->var->name] |
|
137 | - ), |
|
138 | - ]; |
|
139 | - } |
|
140 | - } |
|
141 | - } else if ($node->name === 'addForeignKeyConstraint') { |
|
142 | - if (isset($node->args[4]) && $node->args[4]->value instanceof Node\Scalar\String_) { |
|
143 | - if (!$this->checkNameLength($node->args[4]->value->value)) { |
|
144 | - $this->errors[] = [ |
|
145 | - 'line' => $node->getLine(), |
|
146 | - 'disallowedToken' => $node->args[4]->value->value, |
|
147 | - 'reason' => sprintf( |
|
148 | - 'Constraint name is too long on table `%s` (max. 27)', |
|
149 | - $this->tableVariableNames[$node->var->name] |
|
150 | - ), |
|
151 | - ]; |
|
152 | - } |
|
153 | - } |
|
154 | - } else if ($node->name === 'renameColumn') { |
|
155 | - $this->errors[] = [ |
|
156 | - 'line' => $node->getLine(), |
|
157 | - 'disallowedToken' => 'Deprecated method', |
|
158 | - 'reason' => sprintf( |
|
159 | - '`$%s->renameColumn()` must not be used', |
|
160 | - $node->var->name |
|
161 | - ), |
|
162 | - ]; |
|
163 | - } |
|
110 | + // On autoincrement the max length of the table name is 21 instead of 27 |
|
111 | + if (isset($node->args[2]) && $node->args[2]->value instanceof Node\Expr\Array_) { |
|
112 | + /** @var Node\Expr\Array_ $options */ |
|
113 | + $options = $node->args[2]->value; |
|
114 | + if ($this->checkColumnForAutoincrement($options)) { |
|
115 | + if (!$this->checkNameLength($this->tableVariableNames[$node->var->name], true)) { |
|
116 | + $this->errors[] = [ |
|
117 | + 'line' => $node->getLine(), |
|
118 | + 'disallowedToken' => $this->tableVariableNames[$node->var->name], |
|
119 | + 'reason' => 'Table name is too long because of autoincrement (max. 21)', |
|
120 | + ]; |
|
121 | + } |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } else if ($node->name === 'addIndex' || |
|
126 | + $node->name === 'addUniqueIndex' || |
|
127 | + $node->name === 'renameIndex' || |
|
128 | + $node->name === 'setPrimaryKey') { |
|
129 | + if (isset($node->args[1]) && $node->args[1]->value instanceof Node\Scalar\String_) { |
|
130 | + if (!$this->checkNameLength($node->args[1]->value->value)) { |
|
131 | + $this->errors[] = [ |
|
132 | + 'line' => $node->getLine(), |
|
133 | + 'disallowedToken' => $node->args[1]->value->value, |
|
134 | + 'reason' => sprintf( |
|
135 | + 'Index name is too long on table `%s` (max. 27)', |
|
136 | + $this->tableVariableNames[$node->var->name] |
|
137 | + ), |
|
138 | + ]; |
|
139 | + } |
|
140 | + } |
|
141 | + } else if ($node->name === 'addForeignKeyConstraint') { |
|
142 | + if (isset($node->args[4]) && $node->args[4]->value instanceof Node\Scalar\String_) { |
|
143 | + if (!$this->checkNameLength($node->args[4]->value->value)) { |
|
144 | + $this->errors[] = [ |
|
145 | + 'line' => $node->getLine(), |
|
146 | + 'disallowedToken' => $node->args[4]->value->value, |
|
147 | + 'reason' => sprintf( |
|
148 | + 'Constraint name is too long on table `%s` (max. 27)', |
|
149 | + $this->tableVariableNames[$node->var->name] |
|
150 | + ), |
|
151 | + ]; |
|
152 | + } |
|
153 | + } |
|
154 | + } else if ($node->name === 'renameColumn') { |
|
155 | + $this->errors[] = [ |
|
156 | + 'line' => $node->getLine(), |
|
157 | + 'disallowedToken' => 'Deprecated method', |
|
158 | + 'reason' => sprintf( |
|
159 | + '`$%s->renameColumn()` must not be used', |
|
160 | + $node->var->name |
|
161 | + ), |
|
162 | + ]; |
|
163 | + } |
|
164 | 164 | |
165 | - /** |
|
166 | - * Find the schema |
|
167 | - */ |
|
168 | - } else if ($node instanceof Node\Expr\Assign && |
|
169 | - $node->expr instanceof Node\Expr\FuncCall && |
|
170 | - $node->var instanceof Node\Expr\Variable && |
|
171 | - $node->expr->name instanceof Node\Expr\Variable && |
|
172 | - $node->expr->name->name === 'schemaClosure') { |
|
173 | - // E.g. $schema = $schemaClosure(); |
|
174 | - $this->schemaVariableName = $node->var->name; |
|
175 | - } |
|
176 | - } |
|
165 | + /** |
|
166 | + * Find the schema |
|
167 | + */ |
|
168 | + } else if ($node instanceof Node\Expr\Assign && |
|
169 | + $node->expr instanceof Node\Expr\FuncCall && |
|
170 | + $node->var instanceof Node\Expr\Variable && |
|
171 | + $node->expr->name instanceof Node\Expr\Variable && |
|
172 | + $node->expr->name->name === 'schemaClosure') { |
|
173 | + // E.g. $schema = $schemaClosure(); |
|
174 | + $this->schemaVariableName = $node->var->name; |
|
175 | + } |
|
176 | + } |
|
177 | 177 | |
178 | - protected function checkNameLength($tableName, $hasAutoincrement = false) { |
|
179 | - if ($hasAutoincrement) { |
|
180 | - return strlen($tableName) <= 21; |
|
181 | - } |
|
182 | - return strlen($tableName) <= 27; |
|
183 | - } |
|
178 | + protected function checkNameLength($tableName, $hasAutoincrement = false) { |
|
179 | + if ($hasAutoincrement) { |
|
180 | + return strlen($tableName) <= 21; |
|
181 | + } |
|
182 | + return strlen($tableName) <= 27; |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * @param Node\Expr\Array_ $optionsArray |
|
187 | - * @return bool Whether the column is an autoincrement column |
|
188 | - */ |
|
189 | - protected function checkColumnForAutoincrement(Node\Expr\Array_ $optionsArray) { |
|
190 | - foreach ($optionsArray->items as $option) { |
|
191 | - if ($option->key instanceof Node\Scalar\String_) { |
|
192 | - if ($option->key->value === 'autoincrement' && |
|
193 | - $option->value instanceof Node\Expr\ConstFetch) { |
|
194 | - /** @var Node\Expr\ConstFetch $const */ |
|
195 | - $const = $option->value; |
|
185 | + /** |
|
186 | + * @param Node\Expr\Array_ $optionsArray |
|
187 | + * @return bool Whether the column is an autoincrement column |
|
188 | + */ |
|
189 | + protected function checkColumnForAutoincrement(Node\Expr\Array_ $optionsArray) { |
|
190 | + foreach ($optionsArray->items as $option) { |
|
191 | + if ($option->key instanceof Node\Scalar\String_) { |
|
192 | + if ($option->key->value === 'autoincrement' && |
|
193 | + $option->value instanceof Node\Expr\ConstFetch) { |
|
194 | + /** @var Node\Expr\ConstFetch $const */ |
|
195 | + $const = $option->value; |
|
196 | 196 | |
197 | - if ($const->name instanceof Name && |
|
198 | - $const->name->parts === ['true']) { |
|
199 | - return true; |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
197 | + if ($const->name instanceof Name && |
|
198 | + $const->name->parts === ['true']) { |
|
199 | + return true; |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | 204 | |
205 | - return false; |
|
206 | - } |
|
205 | + return false; |
|
206 | + } |
|
207 | 207 | } |
@@ -25,16 +25,16 @@ |
||
25 | 25 | |
26 | 26 | class Exception extends \Exception { |
27 | 27 | |
28 | - /** @var Result */ |
|
29 | - private $result; |
|
28 | + /** @var Result */ |
|
29 | + private $result; |
|
30 | 30 | |
31 | - public function __construct(Result $result) { |
|
32 | - parent::__construct(); |
|
33 | - $this->result = $result; |
|
34 | - } |
|
31 | + public function __construct(Result $result) { |
|
32 | + parent::__construct(); |
|
33 | + $this->result = $result; |
|
34 | + } |
|
35 | 35 | |
36 | - public function getResult() { |
|
37 | - return $this->result; |
|
38 | - } |
|
36 | + public function getResult() { |
|
37 | + return $this->result; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | } |
@@ -32,85 +32,85 @@ |
||
32 | 32 | */ |
33 | 33 | class File extends \OCP\Search\Result { |
34 | 34 | |
35 | - /** |
|
36 | - * Type name; translated in templates |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - public $type = 'file'; |
|
35 | + /** |
|
36 | + * Type name; translated in templates |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + public $type = 'file'; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Path to file |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public $path; |
|
41 | + /** |
|
42 | + * Path to file |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public $path; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Size, in bytes |
|
49 | - * @var int |
|
50 | - */ |
|
51 | - public $size; |
|
47 | + /** |
|
48 | + * Size, in bytes |
|
49 | + * @var int |
|
50 | + */ |
|
51 | + public $size; |
|
52 | 52 | |
53 | - /** |
|
54 | - * Date modified, in human readable form |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public $modified; |
|
53 | + /** |
|
54 | + * Date modified, in human readable form |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public $modified; |
|
58 | 58 | |
59 | - /** |
|
60 | - * File mime type |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $mime_type; |
|
59 | + /** |
|
60 | + * File mime type |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $mime_type; |
|
64 | 64 | |
65 | - /** |
|
66 | - * File permissions: |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $permissions; |
|
65 | + /** |
|
66 | + * File permissions: |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $permissions; |
|
71 | 71 | |
72 | - /** |
|
73 | - * Create a new file search result |
|
74 | - * @param FileInfo $data file data given by provider |
|
75 | - */ |
|
76 | - public function __construct(FileInfo $data) { |
|
72 | + /** |
|
73 | + * Create a new file search result |
|
74 | + * @param FileInfo $data file data given by provider |
|
75 | + */ |
|
76 | + public function __construct(FileInfo $data) { |
|
77 | 77 | |
78 | - $path = $this->getRelativePath($data->getPath()); |
|
78 | + $path = $this->getRelativePath($data->getPath()); |
|
79 | 79 | |
80 | - $info = pathinfo($path); |
|
81 | - $this->id = $data->getId(); |
|
82 | - $this->name = $info['basename']; |
|
83 | - $this->link = \OC::$server->getURLGenerator()->linkToRoute( |
|
84 | - 'files.view.index', |
|
85 | - [ |
|
86 | - 'dir' => $info['dirname'], |
|
87 | - 'scrollto' => $info['basename'], |
|
88 | - ] |
|
89 | - ); |
|
90 | - $this->permissions = $data->getPermissions(); |
|
91 | - $this->path = $path; |
|
92 | - $this->size = $data->getSize(); |
|
93 | - $this->modified = $data->getMtime(); |
|
94 | - $this->mime_type = $data->getMimetype(); |
|
95 | - } |
|
80 | + $info = pathinfo($path); |
|
81 | + $this->id = $data->getId(); |
|
82 | + $this->name = $info['basename']; |
|
83 | + $this->link = \OC::$server->getURLGenerator()->linkToRoute( |
|
84 | + 'files.view.index', |
|
85 | + [ |
|
86 | + 'dir' => $info['dirname'], |
|
87 | + 'scrollto' => $info['basename'], |
|
88 | + ] |
|
89 | + ); |
|
90 | + $this->permissions = $data->getPermissions(); |
|
91 | + $this->path = $path; |
|
92 | + $this->size = $data->getSize(); |
|
93 | + $this->modified = $data->getMtime(); |
|
94 | + $this->mime_type = $data->getMimetype(); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * @var Folder $userFolderCache |
|
99 | - */ |
|
100 | - static protected $userFolderCache = null; |
|
97 | + /** |
|
98 | + * @var Folder $userFolderCache |
|
99 | + */ |
|
100 | + static protected $userFolderCache = null; |
|
101 | 101 | |
102 | - /** |
|
103 | - * converts a path relative to the users files folder |
|
104 | - * eg /user/files/foo.txt -> /foo.txt |
|
105 | - * @param string $path |
|
106 | - * @return string relative path |
|
107 | - */ |
|
108 | - protected function getRelativePath ($path) { |
|
109 | - if (!isset(self::$userFolderCache)) { |
|
110 | - $user = \OC::$server->getUserSession()->getUser()->getUID(); |
|
111 | - self::$userFolderCache = \OC::$server->getUserFolder($user); |
|
112 | - } |
|
113 | - return self::$userFolderCache->getRelativePath($path); |
|
114 | - } |
|
102 | + /** |
|
103 | + * converts a path relative to the users files folder |
|
104 | + * eg /user/files/foo.txt -> /foo.txt |
|
105 | + * @param string $path |
|
106 | + * @return string relative path |
|
107 | + */ |
|
108 | + protected function getRelativePath ($path) { |
|
109 | + if (!isset(self::$userFolderCache)) { |
|
110 | + $user = \OC::$server->getUserSession()->getUser()->getUID(); |
|
111 | + self::$userFolderCache = \OC::$server->getUserFolder($user); |
|
112 | + } |
|
113 | + return self::$userFolderCache->getRelativePath($path); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | } |
@@ -32,26 +32,26 @@ |
||
32 | 32 | * @package OC\BackgroundJob |
33 | 33 | */ |
34 | 34 | abstract class TimedJob extends Job { |
35 | - protected $interval = 0; |
|
35 | + protected $interval = 0; |
|
36 | 36 | |
37 | - /** |
|
38 | - * set the interval for the job |
|
39 | - * |
|
40 | - * @param int $interval |
|
41 | - */ |
|
42 | - public function setInterval($interval) { |
|
43 | - $this->interval = $interval; |
|
44 | - } |
|
37 | + /** |
|
38 | + * set the interval for the job |
|
39 | + * |
|
40 | + * @param int $interval |
|
41 | + */ |
|
42 | + public function setInterval($interval) { |
|
43 | + $this->interval = $interval; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * run the job if |
|
48 | - * |
|
49 | - * @param JobList $jobList |
|
50 | - * @param ILogger|null $logger |
|
51 | - */ |
|
52 | - public function execute($jobList, ILogger $logger = null) { |
|
53 | - if ((time() - $this->lastRun) > $this->interval) { |
|
54 | - parent::execute($jobList, $logger); |
|
55 | - } |
|
56 | - } |
|
46 | + /** |
|
47 | + * run the job if |
|
48 | + * |
|
49 | + * @param JobList $jobList |
|
50 | + * @param ILogger|null $logger |
|
51 | + */ |
|
52 | + public function execute($jobList, ILogger $logger = null) { |
|
53 | + if ((time() - $this->lastRun) > $this->interval) { |
|
54 | + parent::execute($jobList, $logger); |
|
55 | + } |
|
56 | + } |
|
57 | 57 | } |
@@ -32,14 +32,14 @@ |
||
32 | 32 | * @package OC\BackgroundJob |
33 | 33 | */ |
34 | 34 | abstract class QueuedJob extends Job { |
35 | - /** |
|
36 | - * run the job, then remove it from the joblist |
|
37 | - * |
|
38 | - * @param JobList $jobList |
|
39 | - * @param ILogger|null $logger |
|
40 | - */ |
|
41 | - public function execute($jobList, ILogger $logger = null) { |
|
42 | - $jobList->remove($this, $this->argument); |
|
43 | - parent::execute($jobList, $logger); |
|
44 | - } |
|
35 | + /** |
|
36 | + * run the job, then remove it from the joblist |
|
37 | + * |
|
38 | + * @param JobList $jobList |
|
39 | + * @param ILogger|null $logger |
|
40 | + */ |
|
41 | + public function execute($jobList, ILogger $logger = null) { |
|
42 | + $jobList->remove($this, $this->argument); |
|
43 | + parent::execute($jobList, $logger); |
|
44 | + } |
|
45 | 45 | } |