1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Joas Schilling <[email protected]> |
4
|
|
|
* @author Morris Jobke <[email protected]> |
5
|
|
|
* @author Robin Appelman <[email protected]> |
6
|
|
|
* @author Roeland Jago Douma <[email protected]> |
7
|
|
|
* @author Vincent Petry <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
10
|
|
|
* @license AGPL-3.0 |
11
|
|
|
* |
12
|
|
|
* This code is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
14
|
|
|
* as published by the Free Software Foundation. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace OCA\Files_Sharing; |
27
|
|
|
|
28
|
|
|
use OC\Files\ObjectStore\NoopScanner; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Scanner for SharedStorage |
32
|
|
|
*/ |
33
|
|
|
class Scanner extends \OC\Files\Cache\Scanner { |
34
|
|
|
private $sourceScanner; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Returns metadata from the shared storage, but |
38
|
|
|
* with permissions from the source storage. |
39
|
|
|
* |
40
|
|
|
* @param string $path path of the file for which to retrieve metadata |
41
|
|
|
* |
42
|
|
|
* @return array an array of metadata of the file |
43
|
|
|
*/ |
44
|
|
|
public function getData($path) { |
45
|
|
|
$data = parent::getData($path); |
46
|
|
|
if ($data === null) { |
47
|
|
|
return null; |
48
|
|
|
} |
49
|
|
|
list($sourceStorage, $internalPath) = $this->storage->resolvePath($path); |
|
|
|
|
50
|
|
|
$data['permissions'] = $sourceStorage->getPermissions($internalPath); |
51
|
|
|
return $data; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function getSourceScanner() { |
55
|
|
|
if ($this->sourceScanner) { |
56
|
|
|
return $this->sourceScanner; |
57
|
|
|
} |
58
|
|
|
if ($this->storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
59
|
|
|
/** @var \OC\Files\Storage\Storage $storage */ |
60
|
|
|
list($storage) = $this->storage->resolvePath(''); |
|
|
|
|
61
|
|
|
$this->sourceScanner = $storage->getScanner(); |
62
|
|
|
return $this->sourceScanner; |
63
|
|
|
} else { |
64
|
|
|
return null; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* scan a folder and all it's children, use source scanner if needed |
70
|
|
|
* |
71
|
|
|
* @inheritdoc |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) { |
74
|
|
|
$sourceScanner = $this->getSourceScanner(); |
75
|
|
|
if ($sourceScanner instanceof NoopScanner) { |
76
|
|
|
list(, $internalPath) = $this->storage->resolvePath($path); |
|
|
|
|
77
|
|
|
return $sourceScanner->scan($internalPath, $recursive, $reuse, $lock); |
78
|
|
|
} else { |
79
|
|
|
return parent::scan($path, $recursive, $reuse, $lock); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* scan a single file and use source scanner if needed |
85
|
|
|
* |
86
|
|
|
* @inheritdoc |
87
|
|
|
*/ |
88
|
|
View Code Duplication |
public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData = null, $lock = true) { |
89
|
|
|
$sourceScanner = $this->getSourceScanner(); |
90
|
|
|
if ($sourceScanner instanceof NoopScanner) { |
91
|
|
|
list(, $internalPath) = $this->storage->resolvePath($file); |
|
|
|
|
92
|
|
|
return parent::scan($internalPath, $reuseExisting, $parentId, $cacheData, $lock); |
|
|
|
|
93
|
|
|
} else { |
94
|
|
|
return parent::scanFile($file, $reuseExisting, $parentId, $cacheData, $lock); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: