@@ -6,27 +6,27 @@ |
||
6 | 6 | $baseDir = $vendorDir; |
7 | 7 | |
8 | 8 | return array( |
9 | - 'OCA\\TwoFactorBackupCodes\\Activity\\Provider' => $baseDir . '/../lib/Activity/Provider.php', |
|
10 | - 'OCA\\TwoFactorBackupCodes\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
11 | - 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\CheckBackupCodes' => $baseDir . '/../lib/BackgroundJob/CheckBackupCodes.php', |
|
12 | - 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\RememberBackupCodesJob' => $baseDir . '/../lib/BackgroundJob/RememberBackupCodesJob.php', |
|
13 | - 'OCA\\TwoFactorBackupCodes\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php', |
|
14 | - 'OCA\\TwoFactorBackupCodes\\Db\\BackupCode' => $baseDir . '/../lib/Db/BackupCode.php', |
|
15 | - 'OCA\\TwoFactorBackupCodes\\Db\\BackupCodeMapper' => $baseDir . '/../lib/Db/BackupCodeMapper.php', |
|
16 | - 'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => $baseDir . '/../lib/Event/CodesGenerated.php', |
|
17 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => $baseDir . '/../lib/Listener/ActivityPublisher.php', |
|
18 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => $baseDir . '/../lib/Listener/ClearNotifications.php', |
|
19 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => $baseDir . '/../lib/Listener/ProviderDisabled.php', |
|
20 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => $baseDir . '/../lib/Listener/ProviderEnabled.php', |
|
21 | - 'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => $baseDir . '/../lib/Listener/RegistryUpdater.php', |
|
22 | - 'OCA\\TwoFactorBackupCodes\\Migration\\CheckBackupCodes' => $baseDir . '/../lib/Migration/CheckBackupCodes.php', |
|
23 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607104347' => $baseDir . '/../lib/Migration/Version1002Date20170607104347.php', |
|
24 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607113030' => $baseDir . '/../lib/Migration/Version1002Date20170607113030.php', |
|
25 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170919123342' => $baseDir . '/../lib/Migration/Version1002Date20170919123342.php', |
|
26 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170926101419' => $baseDir . '/../lib/Migration/Version1002Date20170926101419.php', |
|
27 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20180821043638' => $baseDir . '/../lib/Migration/Version1002Date20180821043638.php', |
|
28 | - 'OCA\\TwoFactorBackupCodes\\Notifications\\Notifier' => $baseDir . '/../lib/Notifications/Notifier.php', |
|
29 | - 'OCA\\TwoFactorBackupCodes\\Provider\\BackupCodesProvider' => $baseDir . '/../lib/Provider/BackupCodesProvider.php', |
|
30 | - 'OCA\\TwoFactorBackupCodes\\Service\\BackupCodeStorage' => $baseDir . '/../lib/Service/BackupCodeStorage.php', |
|
31 | - 'OCA\\TwoFactorBackupCodes\\Settings\\Personal' => $baseDir . '/../lib/Settings/Personal.php', |
|
9 | + 'OCA\\TwoFactorBackupCodes\\Activity\\Provider' => $baseDir.'/../lib/Activity/Provider.php', |
|
10 | + 'OCA\\TwoFactorBackupCodes\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
11 | + 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\CheckBackupCodes' => $baseDir.'/../lib/BackgroundJob/CheckBackupCodes.php', |
|
12 | + 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\RememberBackupCodesJob' => $baseDir.'/../lib/BackgroundJob/RememberBackupCodesJob.php', |
|
13 | + 'OCA\\TwoFactorBackupCodes\\Controller\\SettingsController' => $baseDir.'/../lib/Controller/SettingsController.php', |
|
14 | + 'OCA\\TwoFactorBackupCodes\\Db\\BackupCode' => $baseDir.'/../lib/Db/BackupCode.php', |
|
15 | + 'OCA\\TwoFactorBackupCodes\\Db\\BackupCodeMapper' => $baseDir.'/../lib/Db/BackupCodeMapper.php', |
|
16 | + 'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => $baseDir.'/../lib/Event/CodesGenerated.php', |
|
17 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => $baseDir.'/../lib/Listener/ActivityPublisher.php', |
|
18 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => $baseDir.'/../lib/Listener/ClearNotifications.php', |
|
19 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => $baseDir.'/../lib/Listener/ProviderDisabled.php', |
|
20 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => $baseDir.'/../lib/Listener/ProviderEnabled.php', |
|
21 | + 'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => $baseDir.'/../lib/Listener/RegistryUpdater.php', |
|
22 | + 'OCA\\TwoFactorBackupCodes\\Migration\\CheckBackupCodes' => $baseDir.'/../lib/Migration/CheckBackupCodes.php', |
|
23 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607104347' => $baseDir.'/../lib/Migration/Version1002Date20170607104347.php', |
|
24 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607113030' => $baseDir.'/../lib/Migration/Version1002Date20170607113030.php', |
|
25 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170919123342' => $baseDir.'/../lib/Migration/Version1002Date20170919123342.php', |
|
26 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170926101419' => $baseDir.'/../lib/Migration/Version1002Date20170926101419.php', |
|
27 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20180821043638' => $baseDir.'/../lib/Migration/Version1002Date20180821043638.php', |
|
28 | + 'OCA\\TwoFactorBackupCodes\\Notifications\\Notifier' => $baseDir.'/../lib/Notifications/Notifier.php', |
|
29 | + 'OCA\\TwoFactorBackupCodes\\Provider\\BackupCodesProvider' => $baseDir.'/../lib/Provider/BackupCodesProvider.php', |
|
30 | + 'OCA\\TwoFactorBackupCodes\\Service\\BackupCodeStorage' => $baseDir.'/../lib/Service/BackupCodeStorage.php', |
|
31 | + 'OCA\\TwoFactorBackupCodes\\Settings\\Personal' => $baseDir.'/../lib/Settings/Personal.php', |
|
32 | 32 | ); |
@@ -6,49 +6,49 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitTwoFactorBackupCodes |
8 | 8 | { |
9 | - public static $prefixLengthsPsr4 = array ( |
|
9 | + public static $prefixLengthsPsr4 = array( |
|
10 | 10 | 'O' => |
11 | - array ( |
|
11 | + array( |
|
12 | 12 | 'OCA\\TwoFactorBackupCodes\\' => 25, |
13 | 13 | ), |
14 | 14 | ); |
15 | 15 | |
16 | - public static $prefixDirsPsr4 = array ( |
|
16 | + public static $prefixDirsPsr4 = array( |
|
17 | 17 | 'OCA\\TwoFactorBackupCodes\\' => |
18 | - array ( |
|
19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
18 | + array( |
|
19 | + 0 => __DIR__.'/..'.'/../lib', |
|
20 | 20 | ), |
21 | 21 | ); |
22 | 22 | |
23 | - public static $classMap = array ( |
|
24 | - 'OCA\\TwoFactorBackupCodes\\Activity\\Provider' => __DIR__ . '/..' . '/../lib/Activity/Provider.php', |
|
25 | - 'OCA\\TwoFactorBackupCodes\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
26 | - 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\CheckBackupCodes' => __DIR__ . '/..' . '/../lib/BackgroundJob/CheckBackupCodes.php', |
|
27 | - 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\RememberBackupCodesJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/RememberBackupCodesJob.php', |
|
28 | - 'OCA\\TwoFactorBackupCodes\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php', |
|
29 | - 'OCA\\TwoFactorBackupCodes\\Db\\BackupCode' => __DIR__ . '/..' . '/../lib/Db/BackupCode.php', |
|
30 | - 'OCA\\TwoFactorBackupCodes\\Db\\BackupCodeMapper' => __DIR__ . '/..' . '/../lib/Db/BackupCodeMapper.php', |
|
31 | - 'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => __DIR__ . '/..' . '/../lib/Event/CodesGenerated.php', |
|
32 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => __DIR__ . '/..' . '/../lib/Listener/ActivityPublisher.php', |
|
33 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => __DIR__ . '/..' . '/../lib/Listener/ClearNotifications.php', |
|
34 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => __DIR__ . '/..' . '/../lib/Listener/ProviderDisabled.php', |
|
35 | - 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => __DIR__ . '/..' . '/../lib/Listener/ProviderEnabled.php', |
|
36 | - 'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => __DIR__ . '/..' . '/../lib/Listener/RegistryUpdater.php', |
|
37 | - 'OCA\\TwoFactorBackupCodes\\Migration\\CheckBackupCodes' => __DIR__ . '/..' . '/../lib/Migration/CheckBackupCodes.php', |
|
38 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607104347' => __DIR__ . '/..' . '/../lib/Migration/Version1002Date20170607104347.php', |
|
39 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607113030' => __DIR__ . '/..' . '/../lib/Migration/Version1002Date20170607113030.php', |
|
40 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170919123342' => __DIR__ . '/..' . '/../lib/Migration/Version1002Date20170919123342.php', |
|
41 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170926101419' => __DIR__ . '/..' . '/../lib/Migration/Version1002Date20170926101419.php', |
|
42 | - 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20180821043638' => __DIR__ . '/..' . '/../lib/Migration/Version1002Date20180821043638.php', |
|
43 | - 'OCA\\TwoFactorBackupCodes\\Notifications\\Notifier' => __DIR__ . '/..' . '/../lib/Notifications/Notifier.php', |
|
44 | - 'OCA\\TwoFactorBackupCodes\\Provider\\BackupCodesProvider' => __DIR__ . '/..' . '/../lib/Provider/BackupCodesProvider.php', |
|
45 | - 'OCA\\TwoFactorBackupCodes\\Service\\BackupCodeStorage' => __DIR__ . '/..' . '/../lib/Service/BackupCodeStorage.php', |
|
46 | - 'OCA\\TwoFactorBackupCodes\\Settings\\Personal' => __DIR__ . '/..' . '/../lib/Settings/Personal.php', |
|
23 | + public static $classMap = array( |
|
24 | + 'OCA\\TwoFactorBackupCodes\\Activity\\Provider' => __DIR__.'/..'.'/../lib/Activity/Provider.php', |
|
25 | + 'OCA\\TwoFactorBackupCodes\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
26 | + 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\CheckBackupCodes' => __DIR__.'/..'.'/../lib/BackgroundJob/CheckBackupCodes.php', |
|
27 | + 'OCA\\TwoFactorBackupCodes\\BackgroundJob\\RememberBackupCodesJob' => __DIR__.'/..'.'/../lib/BackgroundJob/RememberBackupCodesJob.php', |
|
28 | + 'OCA\\TwoFactorBackupCodes\\Controller\\SettingsController' => __DIR__.'/..'.'/../lib/Controller/SettingsController.php', |
|
29 | + 'OCA\\TwoFactorBackupCodes\\Db\\BackupCode' => __DIR__.'/..'.'/../lib/Db/BackupCode.php', |
|
30 | + 'OCA\\TwoFactorBackupCodes\\Db\\BackupCodeMapper' => __DIR__.'/..'.'/../lib/Db/BackupCodeMapper.php', |
|
31 | + 'OCA\\TwoFactorBackupCodes\\Event\\CodesGenerated' => __DIR__.'/..'.'/../lib/Event/CodesGenerated.php', |
|
32 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ActivityPublisher' => __DIR__.'/..'.'/../lib/Listener/ActivityPublisher.php', |
|
33 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ClearNotifications' => __DIR__.'/..'.'/../lib/Listener/ClearNotifications.php', |
|
34 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderDisabled' => __DIR__.'/..'.'/../lib/Listener/ProviderDisabled.php', |
|
35 | + 'OCA\\TwoFactorBackupCodes\\Listener\\ProviderEnabled' => __DIR__.'/..'.'/../lib/Listener/ProviderEnabled.php', |
|
36 | + 'OCA\\TwoFactorBackupCodes\\Listener\\RegistryUpdater' => __DIR__.'/..'.'/../lib/Listener/RegistryUpdater.php', |
|
37 | + 'OCA\\TwoFactorBackupCodes\\Migration\\CheckBackupCodes' => __DIR__.'/..'.'/../lib/Migration/CheckBackupCodes.php', |
|
38 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607104347' => __DIR__.'/..'.'/../lib/Migration/Version1002Date20170607104347.php', |
|
39 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170607113030' => __DIR__.'/..'.'/../lib/Migration/Version1002Date20170607113030.php', |
|
40 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170919123342' => __DIR__.'/..'.'/../lib/Migration/Version1002Date20170919123342.php', |
|
41 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20170926101419' => __DIR__.'/..'.'/../lib/Migration/Version1002Date20170926101419.php', |
|
42 | + 'OCA\\TwoFactorBackupCodes\\Migration\\Version1002Date20180821043638' => __DIR__.'/..'.'/../lib/Migration/Version1002Date20180821043638.php', |
|
43 | + 'OCA\\TwoFactorBackupCodes\\Notifications\\Notifier' => __DIR__.'/..'.'/../lib/Notifications/Notifier.php', |
|
44 | + 'OCA\\TwoFactorBackupCodes\\Provider\\BackupCodesProvider' => __DIR__.'/..'.'/../lib/Provider/BackupCodesProvider.php', |
|
45 | + 'OCA\\TwoFactorBackupCodes\\Service\\BackupCodeStorage' => __DIR__.'/..'.'/../lib/Service/BackupCodeStorage.php', |
|
46 | + 'OCA\\TwoFactorBackupCodes\\Settings\\Personal' => __DIR__.'/..'.'/../lib/Settings/Personal.php', |
|
47 | 47 | ); |
48 | 48 | |
49 | 49 | public static function getInitializer(ClassLoader $loader) |
50 | 50 | { |
51 | - return \Closure::bind(function () use ($loader) { |
|
51 | + return \Closure::bind(function() use ($loader) { |
|
52 | 52 | $loader->prefixLengthsPsr4 = ComposerStaticInitTwoFactorBackupCodes::$prefixLengthsPsr4; |
53 | 53 | $loader->prefixDirsPsr4 = ComposerStaticInitTwoFactorBackupCodes::$prefixDirsPsr4; |
54 | 54 | $loader->classMap = ComposerStaticInitTwoFactorBackupCodes::$classMap; |
@@ -41,173 +41,173 @@ |
||
41 | 41 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
42 | 42 | |
43 | 43 | class Storage extends Wrapper { |
44 | - /** @var IMountPoint */ |
|
45 | - private $mountPoint; |
|
46 | - |
|
47 | - /** @var IUserManager */ |
|
48 | - private $userManager; |
|
49 | - |
|
50 | - /** @var ILogger */ |
|
51 | - private $logger; |
|
52 | - |
|
53 | - /** @var EventDispatcherInterface */ |
|
54 | - private $eventDispatcher; |
|
55 | - |
|
56 | - /** @var IRootFolder */ |
|
57 | - private $rootFolder; |
|
58 | - |
|
59 | - /** @var ITrashManager */ |
|
60 | - private $trashManager; |
|
61 | - |
|
62 | - /** |
|
63 | - * Storage constructor. |
|
64 | - * |
|
65 | - * @param array $parameters |
|
66 | - * @param ITrashManager $trashManager |
|
67 | - * @param IUserManager|null $userManager |
|
68 | - * @param ILogger|null $logger |
|
69 | - * @param EventDispatcherInterface|null $eventDispatcher |
|
70 | - * @param IRootFolder|null $rootFolder |
|
71 | - */ |
|
72 | - public function __construct( |
|
73 | - $parameters, |
|
74 | - ITrashManager $trashManager = null, |
|
75 | - IUserManager $userManager = null, |
|
76 | - ILogger $logger = null, |
|
77 | - EventDispatcherInterface $eventDispatcher = null, |
|
78 | - IRootFolder $rootFolder = null |
|
79 | - ) { |
|
80 | - $this->mountPoint = $parameters['mountPoint']; |
|
81 | - $this->trashManager = $trashManager; |
|
82 | - $this->userManager = $userManager; |
|
83 | - $this->logger = $logger; |
|
84 | - $this->eventDispatcher = $eventDispatcher; |
|
85 | - $this->rootFolder = $rootFolder; |
|
86 | - parent::__construct($parameters); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Deletes the given file by moving it into the trashbin. |
|
91 | - * |
|
92 | - * @param string $path path of file or folder to delete |
|
93 | - * |
|
94 | - * @return bool true if the operation succeeded, false otherwise |
|
95 | - */ |
|
96 | - public function unlink($path) { |
|
97 | - try { |
|
98 | - return $this->doDelete($path, 'unlink'); |
|
99 | - } catch (GenericEncryptionException $e) { |
|
100 | - // in case of a encryption exception we delete the file right away |
|
101 | - $this->logger->info( |
|
102 | - "Can't move file" . $path . |
|
103 | - "to the trash bin, therefore it was deleted right away"); |
|
104 | - |
|
105 | - return $this->storage->unlink($path); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Deletes the given folder by moving it into the trashbin. |
|
111 | - * |
|
112 | - * @param string $path path of folder to delete |
|
113 | - * |
|
114 | - * @return bool true if the operation succeeded, false otherwise |
|
115 | - */ |
|
116 | - public function rmdir($path) { |
|
117 | - return $this->doDelete($path, 'rmdir'); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * check if it is a file located in data/user/files only files in the |
|
122 | - * 'files' directory should be moved to the trash |
|
123 | - * |
|
124 | - * @param $path |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - protected function shouldMoveToTrash($path) { |
|
128 | - |
|
129 | - // check if there is a app which want to disable the trash bin for this file |
|
130 | - $fileId = $this->storage->getCache()->getId($path); |
|
131 | - $nodes = $this->rootFolder->getById($fileId); |
|
132 | - foreach ($nodes as $node) { |
|
133 | - $event = $this->createMoveToTrashEvent($node); |
|
134 | - $this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event); |
|
135 | - if ($event->shouldMoveToTrashBin() === false) { |
|
136 | - return false; |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); |
|
141 | - $parts = explode('/', $normalized); |
|
142 | - if (count($parts) < 4) { |
|
143 | - return false; |
|
144 | - } |
|
145 | - |
|
146 | - if ($parts[2] === 'files' && $this->userManager->userExists($parts[1])) { |
|
147 | - return true; |
|
148 | - } |
|
149 | - |
|
150 | - return false; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * get move to trash event |
|
155 | - * |
|
156 | - * @param Node $node |
|
157 | - * @return MoveToTrashEvent |
|
158 | - */ |
|
159 | - protected function createMoveToTrashEvent(Node $node) { |
|
160 | - return new MoveToTrashEvent($node); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Run the delete operation with the given method |
|
165 | - * |
|
166 | - * @param string $path path of file or folder to delete |
|
167 | - * @param string $method either "unlink" or "rmdir" |
|
168 | - * |
|
169 | - * @return bool true if the operation succeeded, false otherwise |
|
170 | - */ |
|
171 | - private function doDelete($path, $method) { |
|
172 | - if ( |
|
173 | - !\OC::$server->getAppManager()->isEnabledForUser('files_trashbin') |
|
174 | - || (pathinfo($path, PATHINFO_EXTENSION) === 'part') |
|
175 | - || $this->shouldMoveToTrash($path) === false |
|
176 | - ) { |
|
177 | - return call_user_func([$this->storage, $method], $path); |
|
178 | - } |
|
179 | - |
|
180 | - // check permissions before we continue, this is especially important for |
|
181 | - // shared files |
|
182 | - if (!$this->isDeletable($path)) { |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - $isMovedToTrash = $this->trashManager->moveToTrash($this, $path); |
|
187 | - if (!$isMovedToTrash) { |
|
188 | - return call_user_func([$this->storage, $method], $path); |
|
189 | - } else { |
|
190 | - return true; |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Setup the storate wrapper callback |
|
196 | - */ |
|
197 | - public static function setupStorage() { |
|
198 | - \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) { |
|
199 | - return new \OCA\Files_Trashbin\Storage( |
|
200 | - ['storage' => $storage, 'mountPoint' => $mountPoint], |
|
201 | - \OC::$server->query(ITrashManager::class), |
|
202 | - \OC::$server->getUserManager(), |
|
203 | - \OC::$server->getLogger(), |
|
204 | - \OC::$server->getEventDispatcher(), |
|
205 | - \OC::$server->getLazyRootFolder() |
|
206 | - ); |
|
207 | - }, 1); |
|
208 | - } |
|
209 | - |
|
210 | - public function getMountPoint() { |
|
211 | - return $this->mountPoint; |
|
212 | - } |
|
44 | + /** @var IMountPoint */ |
|
45 | + private $mountPoint; |
|
46 | + |
|
47 | + /** @var IUserManager */ |
|
48 | + private $userManager; |
|
49 | + |
|
50 | + /** @var ILogger */ |
|
51 | + private $logger; |
|
52 | + |
|
53 | + /** @var EventDispatcherInterface */ |
|
54 | + private $eventDispatcher; |
|
55 | + |
|
56 | + /** @var IRootFolder */ |
|
57 | + private $rootFolder; |
|
58 | + |
|
59 | + /** @var ITrashManager */ |
|
60 | + private $trashManager; |
|
61 | + |
|
62 | + /** |
|
63 | + * Storage constructor. |
|
64 | + * |
|
65 | + * @param array $parameters |
|
66 | + * @param ITrashManager $trashManager |
|
67 | + * @param IUserManager|null $userManager |
|
68 | + * @param ILogger|null $logger |
|
69 | + * @param EventDispatcherInterface|null $eventDispatcher |
|
70 | + * @param IRootFolder|null $rootFolder |
|
71 | + */ |
|
72 | + public function __construct( |
|
73 | + $parameters, |
|
74 | + ITrashManager $trashManager = null, |
|
75 | + IUserManager $userManager = null, |
|
76 | + ILogger $logger = null, |
|
77 | + EventDispatcherInterface $eventDispatcher = null, |
|
78 | + IRootFolder $rootFolder = null |
|
79 | + ) { |
|
80 | + $this->mountPoint = $parameters['mountPoint']; |
|
81 | + $this->trashManager = $trashManager; |
|
82 | + $this->userManager = $userManager; |
|
83 | + $this->logger = $logger; |
|
84 | + $this->eventDispatcher = $eventDispatcher; |
|
85 | + $this->rootFolder = $rootFolder; |
|
86 | + parent::__construct($parameters); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Deletes the given file by moving it into the trashbin. |
|
91 | + * |
|
92 | + * @param string $path path of file or folder to delete |
|
93 | + * |
|
94 | + * @return bool true if the operation succeeded, false otherwise |
|
95 | + */ |
|
96 | + public function unlink($path) { |
|
97 | + try { |
|
98 | + return $this->doDelete($path, 'unlink'); |
|
99 | + } catch (GenericEncryptionException $e) { |
|
100 | + // in case of a encryption exception we delete the file right away |
|
101 | + $this->logger->info( |
|
102 | + "Can't move file" . $path . |
|
103 | + "to the trash bin, therefore it was deleted right away"); |
|
104 | + |
|
105 | + return $this->storage->unlink($path); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Deletes the given folder by moving it into the trashbin. |
|
111 | + * |
|
112 | + * @param string $path path of folder to delete |
|
113 | + * |
|
114 | + * @return bool true if the operation succeeded, false otherwise |
|
115 | + */ |
|
116 | + public function rmdir($path) { |
|
117 | + return $this->doDelete($path, 'rmdir'); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * check if it is a file located in data/user/files only files in the |
|
122 | + * 'files' directory should be moved to the trash |
|
123 | + * |
|
124 | + * @param $path |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + protected function shouldMoveToTrash($path) { |
|
128 | + |
|
129 | + // check if there is a app which want to disable the trash bin for this file |
|
130 | + $fileId = $this->storage->getCache()->getId($path); |
|
131 | + $nodes = $this->rootFolder->getById($fileId); |
|
132 | + foreach ($nodes as $node) { |
|
133 | + $event = $this->createMoveToTrashEvent($node); |
|
134 | + $this->eventDispatcher->dispatch('OCA\Files_Trashbin::moveToTrash', $event); |
|
135 | + if ($event->shouldMoveToTrashBin() === false) { |
|
136 | + return false; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + $normalized = Filesystem::normalizePath($this->mountPoint . '/' . $path); |
|
141 | + $parts = explode('/', $normalized); |
|
142 | + if (count($parts) < 4) { |
|
143 | + return false; |
|
144 | + } |
|
145 | + |
|
146 | + if ($parts[2] === 'files' && $this->userManager->userExists($parts[1])) { |
|
147 | + return true; |
|
148 | + } |
|
149 | + |
|
150 | + return false; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * get move to trash event |
|
155 | + * |
|
156 | + * @param Node $node |
|
157 | + * @return MoveToTrashEvent |
|
158 | + */ |
|
159 | + protected function createMoveToTrashEvent(Node $node) { |
|
160 | + return new MoveToTrashEvent($node); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Run the delete operation with the given method |
|
165 | + * |
|
166 | + * @param string $path path of file or folder to delete |
|
167 | + * @param string $method either "unlink" or "rmdir" |
|
168 | + * |
|
169 | + * @return bool true if the operation succeeded, false otherwise |
|
170 | + */ |
|
171 | + private function doDelete($path, $method) { |
|
172 | + if ( |
|
173 | + !\OC::$server->getAppManager()->isEnabledForUser('files_trashbin') |
|
174 | + || (pathinfo($path, PATHINFO_EXTENSION) === 'part') |
|
175 | + || $this->shouldMoveToTrash($path) === false |
|
176 | + ) { |
|
177 | + return call_user_func([$this->storage, $method], $path); |
|
178 | + } |
|
179 | + |
|
180 | + // check permissions before we continue, this is especially important for |
|
181 | + // shared files |
|
182 | + if (!$this->isDeletable($path)) { |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + $isMovedToTrash = $this->trashManager->moveToTrash($this, $path); |
|
187 | + if (!$isMovedToTrash) { |
|
188 | + return call_user_func([$this->storage, $method], $path); |
|
189 | + } else { |
|
190 | + return true; |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Setup the storate wrapper callback |
|
196 | + */ |
|
197 | + public static function setupStorage() { |
|
198 | + \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) { |
|
199 | + return new \OCA\Files_Trashbin\Storage( |
|
200 | + ['storage' => $storage, 'mountPoint' => $mountPoint], |
|
201 | + \OC::$server->query(ITrashManager::class), |
|
202 | + \OC::$server->getUserManager(), |
|
203 | + \OC::$server->getLogger(), |
|
204 | + \OC::$server->getEventDispatcher(), |
|
205 | + \OC::$server->getLazyRootFolder() |
|
206 | + ); |
|
207 | + }, 1); |
|
208 | + } |
|
209 | + |
|
210 | + public function getMountPoint() { |
|
211 | + return $this->mountPoint; |
|
212 | + } |
|
213 | 213 | } |