Hooks   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 74
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A deleteBookMetadata() 0 5 2
A delete_metadata_hook() 0 7 2
A createForStaticLegacyCode() 0 21 3
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();
0 ignored issues
show
Deprecated Code introduced by
The method OCA\Files_PaperHive\Hook...teForStaticLegacyCode() has been deprecated with message: use DI

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.

Loading history...
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