Completed
Pull Request — master (#14)
by Piotr
01:21
created

PaperHiveMetadata   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 51
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A insertBookID() 0 14 3
A getBookID() 0 11 2
A deleteBookID() 0 5 1
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\DatabaseException;
28
29
class PaperHiveMetadata {
30
31
	/**
32
	 * @param $fileId
33
	 * @param $docId
34
	 * @return bool
35
	 * @throws \OC\DatabaseException
36
	 */
37
	public function insertBookID($fileId, $docId) {
38
		try {
39
			$query = \OC_DB::prepare("INSERT INTO `*PREFIX*paperhive` (`fileid`,`bookid`) VALUES (?,?)");
40
			$result = $query->execute([$fileId, $docId]);
41
		} catch (DatabaseException $e) {
0 ignored issues
show
Bug introduced by
The class OC\DatabaseException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
42
			$result = false;
43
		}
44
45
		if (!$result) {
46
			\OCP\Util::writeLog('files_paperhive', 'paperhive database couldn\'t be updated for the files owner', \OCP\Util::ERROR);
47
			return false;
48
		}
49
		return true;
50
	}
51
52
	/**
53
	 * @param $fileId
54
	 * @return bool
55
	 * @throws DatabaseException
56
	 */
57
	public function getBookID($fileId) {
58
		$query = \OC_DB::prepare('SELECT `bookid`'
59
			. ' FROM `*PREFIX*paperhive` WHERE `fileid`=? LIMIT 1');
60
		$result = $query->execute([$fileId]);
61
62
		while ($row = $result->fetchRow()) {
63
			return $row['bookid'];
64
		}
65
66
		return false;
67
	}
68
69
	/**
70
	 * @param $fileId
71
	 * @return bool
72
	 * @throws DatabaseException
73
	 */
74
	public function deleteBookID($fileId) {
75
		$query = \OC_DB::prepare('DELETE FROM `*PREFIX*paperhive` WHERE `fileid`=?');
76
		$query->execute([$fileId]);
77
		return true;
78
	}
79
}
80