1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Piotr Mrowczynski <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2018, Piotr Mrowczynski. |
6
|
|
|
* @license AGPL-3.0 |
7
|
|
|
* |
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
10
|
|
|
* as published by the Free Software Foundation. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* This class handles hooks. |
24
|
|
|
*/ |
25
|
|
|
namespace OCA\Files_PaperHive; |
26
|
|
|
|
27
|
|
|
use OC\Files\View; |
28
|
|
|
|
29
|
|
|
class Hooks { |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var View |
33
|
|
|
*/ |
34
|
|
|
private $view; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var PaperHiveMetadata |
38
|
|
|
*/ |
39
|
|
|
private $paperHiveMetadata; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
*/ |
43
|
|
|
public function __construct(View $view, PaperHiveMetadata $paperHiveMetadata) { |
44
|
|
|
$this->paperHiveMetadata = $paperHiveMetadata; |
45
|
|
|
$this->view = $view; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Delete book metadata from file |
50
|
|
|
* |
51
|
|
|
* @param $path |
52
|
|
|
*/ |
53
|
|
|
public function deleteBookMetadata($path) { |
54
|
|
|
if ($fileInfo = $this->view->getFileInfo($path)) { |
55
|
|
|
$this->paperHiveMetadata->deleteBookID($fileInfo['fileid']); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Hook to remove metadata from file before deleting |
61
|
|
|
* @param array $params |
62
|
|
|
*/ |
63
|
|
|
public static function delete_metadata_hook($params) { |
64
|
|
|
$path = $params[\OC\Files\Filesystem::signal_param_path]; |
65
|
|
|
if ($path<>'') { |
66
|
|
|
$hook = self::createForStaticLegacyCode(); |
|
|
|
|
67
|
|
|
$hook->deleteBookMetadata($path); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @var Hooks |
73
|
|
|
*/ |
74
|
|
|
private static $instance; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @deprecated use DI |
78
|
|
|
* @return Hooks |
79
|
|
|
*/ |
80
|
|
|
public static function createForStaticLegacyCode() { |
81
|
|
|
if (!self::$instance) { |
82
|
|
|
$user = \OC::$server->getUserSession()->getUser(); |
83
|
|
|
if ($user) { |
84
|
|
|
$uid = $user->getUID(); |
85
|
|
|
} else { |
86
|
|
|
throw new \BadMethodCallException('no user logged in'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
self::$instance = new Hooks( |
90
|
|
|
new View( |
91
|
|
|
'/' . $uid . '/files/' |
92
|
|
|
), |
93
|
|
|
new PaperHiveMetadata( |
94
|
|
|
\OC::$server->getDatabaseConnection(), |
95
|
|
|
\OC::$server->getLogger() |
96
|
|
|
) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
return self::$instance; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.