|
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\Service; |
|
23
|
|
|
|
|
24
|
|
|
use OCA\RansomwareDetection\Db\RecoveredFileOperationMapper; |
|
25
|
|
|
use OCA\RansomwareDetection\Db\FileOperationMapper; |
|
26
|
|
|
|
|
27
|
|
|
class RecoveredFileOperationService |
|
28
|
|
|
{ |
|
29
|
|
|
/** @var RecoveredFileOperationMapper */ |
|
30
|
|
|
protected $recoveredMapper; |
|
31
|
|
|
|
|
32
|
|
|
/** @var FileOperationMapper */ |
|
33
|
|
|
protected $mapper; |
|
34
|
|
|
|
|
35
|
|
|
/** @var string */ |
|
36
|
|
|
protected $userId; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param RecoveredFileOperationMapper $recoveredMapper |
|
40
|
|
|
* @param FileOperationMapper $mapper |
|
41
|
|
|
* @param string $userId |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct( |
|
44
|
|
|
RecoveredFileOperationMapper $recoveredMapper, |
|
45
|
|
|
FileOperationMapper $mapper, |
|
46
|
|
|
$userId |
|
47
|
|
|
) { |
|
48
|
|
|
$this->recoveredMapper = $recoveredMapper; |
|
49
|
|
|
$this->mapper = $mapper; |
|
50
|
|
|
$this->userId = $userId; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Find one by the id. |
|
55
|
|
|
* |
|
56
|
|
|
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
57
|
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
58
|
|
|
* |
|
59
|
|
|
* @param int $id |
|
60
|
|
|
* |
|
61
|
|
|
* @return Entity |
|
|
|
|
|
|
62
|
|
|
*/ |
|
63
|
|
|
public function find($id) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->recoveredMapper->find($id, $this->userId); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Find one by the file name. |
|
70
|
|
|
* |
|
71
|
|
|
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
72
|
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $name |
|
75
|
|
|
* |
|
76
|
|
|
* @return Entity |
|
77
|
|
|
*/ |
|
78
|
|
|
public function findOneByFileName($name) |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->recoveredMapper->findOneByFileName($name, $this->userId); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Find one with the highest id. |
|
85
|
|
|
* |
|
86
|
|
|
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found |
|
87
|
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result |
|
88
|
|
|
* |
|
89
|
|
|
* @return Entity |
|
90
|
|
|
*/ |
|
91
|
|
|
public function findOneWithHighestId() |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->recoveredMapper->findOneWithHighestId($this->userId); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Find all. |
|
98
|
|
|
* |
|
99
|
|
|
* @param array $params |
|
100
|
|
|
* @param int $limit |
|
101
|
|
|
* @param int $offset |
|
102
|
|
|
* |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
|
|
public function findAll(array $params = [], $limit = null, $offset = null) |
|
106
|
|
|
{ |
|
107
|
|
|
array_push($params, $this->userId); |
|
108
|
|
|
|
|
109
|
|
|
return $this->recoveredMapper->findAll($params, $limit, $offset); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Find sequence by id. |
|
114
|
|
|
* |
|
115
|
|
|
* @param array $params |
|
116
|
|
|
* @param int $limit |
|
117
|
|
|
* @param int $offset |
|
118
|
|
|
* |
|
119
|
|
|
* @return array |
|
120
|
|
|
*/ |
|
121
|
|
|
public function findSequenceById(array $params = [], $limit = null, $offset = null) |
|
122
|
|
|
{ |
|
123
|
|
|
array_push($params, $this->userId); |
|
124
|
|
|
|
|
125
|
|
|
return $this->recoveredMapper->findSequenceById($params, $limit, $offset); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Delete one by id. |
|
130
|
|
|
* |
|
131
|
|
|
* @param int $id |
|
132
|
|
|
*/ |
|
133
|
|
|
public function deleteById($id) |
|
134
|
|
|
{ |
|
135
|
|
|
$fileOperation = $this->recoveredMapper->find($id, $this->userId); |
|
136
|
|
|
$this->recoveredMapper->deleteById($id, $this->userId); |
|
137
|
|
|
$this->mapper->insert($fileOperation->toFileOperation()); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Delete sequence by id. |
|
142
|
|
|
* |
|
143
|
|
|
* @param int $sequence |
|
144
|
|
|
*/ |
|
145
|
|
|
public function deleteSequenceById($sequence) |
|
146
|
|
|
{ |
|
147
|
|
|
$this->recoveredMapper->deleteSequenceById($sequence, $this->userId); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Delete all entries before $timestamp. |
|
152
|
|
|
* |
|
153
|
|
|
* @param int $timestamp |
|
154
|
|
|
*/ |
|
155
|
|
|
public function deleteFileOperationsBefore($timestamp) |
|
156
|
|
|
{ |
|
157
|
|
|
$this->recoveredMapper->deleteFileOperationsBefore($timestamp); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|
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