1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) 2020 Matthias Held <[email protected]> |
5
|
|
|
* @author Matthias Held <[email protected]> |
6
|
|
|
* @license GNU AGPL version 3 or any later version |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
11
|
|
|
* License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
19
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace OCA\RansomwareDetection\Db; |
23
|
|
|
|
24
|
|
|
use OCP\IDBConnection; |
|
|
|
|
25
|
|
|
use OCP\AppFramework\Db\Mapper; |
|
|
|
|
26
|
|
|
|
27
|
|
|
class RecoveredFileOperationMapper extends Mapper |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @param IDBConnection $db |
31
|
|
|
*/ |
32
|
|
|
public function __construct( |
33
|
|
|
IDBConnection $db |
34
|
|
|
) { |
35
|
|
|
parent::__construct($db, 'rd_recovery'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Find one by id. |
40
|
|
|
* |
41
|
|
|
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
42
|
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
43
|
|
|
* |
44
|
|
|
* @param int $id |
45
|
|
|
* |
46
|
|
|
* @return Entity |
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
public function find($id, $userId) |
49
|
|
|
{ |
50
|
|
|
$sql = 'SELECT * FROM `*PREFIX*rd_recovery` '. |
51
|
|
|
'WHERE `id` = ? AND `user_id` = ?'; |
52
|
|
|
|
53
|
|
|
return $this->findEntity($sql, [$id, $userId]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Find one by file name. |
58
|
|
|
* |
59
|
|
|
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
60
|
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
61
|
|
|
* |
62
|
|
|
* @param string $name |
63
|
|
|
* |
64
|
|
|
* @return Entity |
65
|
|
|
*/ |
66
|
|
|
public function findOneByFileName($name, $userId) |
67
|
|
|
{ |
68
|
|
|
$sql = 'SELECT * FROM `*PREFIX*rd_recovery` '. |
69
|
|
|
'WHERE `original_name` = ? AND `user_id` = ?'; |
70
|
|
|
|
71
|
|
|
return $this->findEntity($sql, [$name, $userId]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Find the one with the highest id. |
76
|
|
|
* |
77
|
|
|
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
78
|
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
79
|
|
|
* |
80
|
|
|
* @return Entity |
81
|
|
|
*/ |
82
|
|
|
public function findOneWithHighestId($userId) |
83
|
|
|
{ |
84
|
|
|
$sql = 'SELECT * FROM `*PREFIX*rd_recovery` WHERE `user_id` = ?'. |
85
|
|
|
'ORDER BY id DESC LIMIT 1'; |
86
|
|
|
|
87
|
|
|
return $this->findEntity($sql, [$userId]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Find all. |
92
|
|
|
* |
93
|
|
|
* @param int $limit |
94
|
|
|
* @param int $offset |
95
|
|
|
* |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
public function findAll(array $params = [], $limit = null, $offset = null) |
99
|
|
|
{ |
100
|
|
|
$sql = 'SELECT * FROM `*PREFIX*rd_recovery` WHERE `user_id` = ?'; |
101
|
|
|
|
102
|
|
|
return $this->findEntities($sql, $params, $limit, $offset); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Find a sequence by its id. |
107
|
|
|
* |
108
|
|
|
* @param array $params |
109
|
|
|
* @param int $limit |
110
|
|
|
* @param int $offset |
111
|
|
|
* |
112
|
|
|
* @return array |
113
|
|
|
*/ |
114
|
|
|
public function findSequenceById(array $params = [], $limit = null, $offset = null) |
115
|
|
|
{ |
116
|
|
|
$sql = 'SELECT * FROM `*PREFIX*rd_recovery` WHERE `sequence` = ? AND `user_id` = ?'; |
117
|
|
|
|
118
|
|
|
return $this->findEntities($sql, $params, $limit, $offset); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Delete entity by id. |
123
|
|
|
* |
124
|
|
|
* @param int $id |
125
|
|
|
*/ |
126
|
|
|
public function deleteById($id, $userId) |
127
|
|
|
{ |
128
|
|
|
$sql = 'DELETE FROM `*PREFIX*rd_recovery` WHERE `id` = ? AND `user_id` = ?'; |
129
|
|
|
$stmt = $this->execute($sql, [$id, $userId]); |
130
|
|
|
$stmt->closeCursor(); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Deletes a sequence of file operations. |
135
|
|
|
* |
136
|
|
|
* @param int $sequence |
137
|
|
|
*/ |
138
|
|
|
public function deleteSequenceById($sequence, $userId) |
139
|
|
|
{ |
140
|
|
|
$sql = 'DELETE FROM `*PREFIX*rd_recovery` WHERE `sequence` = ? AND `user_id` = ?'; |
141
|
|
|
$stmt = $this->execute($sql, [$sequence, $userId]); |
142
|
|
|
$stmt->closeCursor(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Delete all entries before $timestamp. |
147
|
|
|
* |
148
|
|
|
* @param int $timestamp |
149
|
|
|
*/ |
150
|
|
|
public function deleteFileOperationsBefore($timestamp) |
151
|
|
|
{ |
152
|
|
|
$sql = 'DELETE FROM `*PREFIX*rd_recovery` WHERE `timestamp` < ?'; |
153
|
|
|
$stmt = $this->execute($sql, [$timestamp]); |
154
|
|
|
$stmt->closeCursor(); |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths