Issues (195)

lib/Service/FileOperationService.php (1 issue)

Labels
Severity
1
<?php
2
3
/**
4
 * @copyright Copyright (c) 2017 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\FileOperationMapper;
25
use OCA\RansomwareDetection\Db\RecoveredFileOperationMapper;
26
27
class FileOperationService
28
{
29
    /** @var FileOperationMapper */
30
    protected $mapper;
31
32
    /** @var RecoveredFileOperationMapper */
33
    protected $recoveredMapper;
34
35
    /** @var string */
36
    protected $userId;
37
38
    /**
39
     * @param FileOperationMapper $mapper
40
     * @param RecoveredFileOperationMapper $recoveredMapper
41
     * @param string              $userId
42
     */
43
    public function __construct(
44
        FileOperationMapper $mapper,
45
        RecoveredFileOperationMapper $recoveredMapper,
46
        $userId
47
    ) {
48
        $this->mapper = $mapper;
49
        $this->recoveredMapper = $recoveredMapper;
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
0 ignored issues
show
The type OCA\RansomwareDetection\Service\Entity was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
62
     */
63
    public function find($id)
64
    {
65
        return $this->mapper->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->mapper->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->mapper->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->mapper->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->mapper->findSequenceById($params, $limit, $offset);
126
    }
127
128
    /**
129
     * Delete one by id.
130
     *
131
     * @param int $id
132
     */
133
    public function deleteById($id, $addToHistory = false)
134
    {
135
        $fileOperation = $this->mapper->find($id, $this->userId);
136
        $this->mapper->deleteById($id, $this->userId);
137
        if ($addToHistory) {
138
            $this->recoveredMapper->insert($fileOperation->toRecoveredFileOperation());
139
        }
140
141
    }
142
143
    /**
144
     * Delete sequence by id.
145
     *
146
     * @param int $sequence
147
     */
148
    public function deleteSequenceById($sequence)
149
    {
150
        $params = [];
151
        array_push($params, $sequence);
152
        array_push($params, $this->userId);
153
154
        $fileOperations = $this->mapper->findSequenceById($params, null, null);
155
        $this->mapper->deleteSequenceById($sequence, $this->userId);
156
        foreach ($fileOperations as $fileOperation) {
157
            $this->recoveredMapper->insert($fileOperation->toRecoveredFileOperation());
158
        }
159
    }
160
161
    /**
162
     * Delete all entries before $timestamp.
163
     *
164
     * @param int $timestamp
165
     */
166
    public function deleteFileOperationsBefore($timestamp)
167
    {
168
        $this->mapper->deleteFileOperationsBefore($timestamp);
169
    }
170
}
171