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

PaperHiveMetadata::getBookID()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 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