|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Christopher Schäpers <[email protected]> |
|
4
|
|
|
* @author Jörn Friedrich Dreyer <[email protected]> |
|
5
|
|
|
* @author Michael Gapczynski <[email protected]> |
|
6
|
|
|
* @author Morris Jobke <[email protected]> |
|
7
|
|
|
* @author Robin Appelman <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
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\Cache\Wrapper\CacheJail; |
|
29
|
|
|
use OCP\Files\Cache\ICacheEntry; |
|
30
|
|
|
use OCP\Files\Storage\IStorage; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Metadata cache for shared files |
|
34
|
|
|
* |
|
35
|
|
|
* don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead |
|
36
|
|
|
*/ |
|
37
|
|
|
class Cache extends CacheJail { |
|
38
|
|
|
/** |
|
39
|
|
|
* @var \OC\Files\Storage\Shared |
|
40
|
|
|
*/ |
|
41
|
|
|
private $storage; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var IStorage |
|
45
|
|
|
*/ |
|
46
|
|
|
private $sourceStorage; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var ICacheEntry |
|
50
|
|
|
*/ |
|
51
|
|
|
private $sourceRootInfo; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var \OCP\Files\Cache\ICache |
|
55
|
|
|
*/ |
|
56
|
|
|
private $sourceCache; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param \OC\Files\Storage\Shared $storage |
|
60
|
|
|
* @param IStorage $sourceStorage |
|
61
|
|
|
* @param ICacheEntry $sourceRootInfo |
|
62
|
|
|
*/ |
|
63
|
|
|
public function __construct($storage, IStorage $sourceStorage, ICacheEntry $sourceRootInfo) { |
|
64
|
|
|
$this->storage = $storage; |
|
65
|
|
|
$this->sourceStorage = $sourceStorage; |
|
66
|
|
|
$this->sourceRootInfo = $sourceRootInfo; |
|
67
|
|
|
$this->sourceCache = $sourceStorage->getCache(); |
|
68
|
|
|
parent::__construct( |
|
69
|
|
|
$this->sourceCache, |
|
70
|
|
|
$this->sourceRootInfo->getPath() |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getNumericStorageId() { |
|
75
|
|
|
if (isset($this->numericId)) { |
|
76
|
|
|
return $this->numericId; |
|
|
|
|
|
|
77
|
|
|
} else { |
|
78
|
|
|
return false; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
protected function formatCacheEntry($entry) { |
|
83
|
|
|
$path = $entry['path']; |
|
84
|
|
|
$entry = parent::formatCacheEntry($entry); |
|
85
|
|
|
$sharePermissions = $this->storage->getPermissions($path); |
|
86
|
|
|
if (isset($entry['permissions'])) { |
|
87
|
|
|
$entry['permissions'] &= $sharePermissions; |
|
88
|
|
|
} else { |
|
89
|
|
|
$entry['permissions'] = $sharePermissions; |
|
90
|
|
|
} |
|
91
|
|
|
$entry['uid_owner'] = $this->storage->getOwner($path); |
|
92
|
|
|
$entry['displayname_owner'] = \OC_User::getDisplayName($entry['uid_owner']); |
|
93
|
|
|
if ($path === '') { |
|
94
|
|
|
$entry['is_share_mount_point'] = true; |
|
95
|
|
|
} |
|
96
|
|
|
return $entry; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* remove all entries for files that are stored on the storage from the cache |
|
101
|
|
|
*/ |
|
102
|
|
|
public function clear() { |
|
103
|
|
|
// Not a valid action for Shared Cache |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: