1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2015 Victor Dubiniuk <[email protected]> |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. |
6
|
|
|
* See the COPYING-README file. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OCA\Files_Antivirus\Controller; |
10
|
|
|
|
11
|
|
|
use \OCP\AppFramework\Controller; |
12
|
|
|
use \OCP\IRequest; |
13
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
14
|
|
|
|
15
|
|
|
use \OCA\Files_Antivirus\Db\Rule; |
16
|
|
|
use \OCA\Files_Antivirus\Db\RuleMapper; |
17
|
|
|
|
18
|
|
|
class RuleController extends Controller { |
19
|
|
|
|
20
|
|
|
/** @var RuleMapper */ |
21
|
|
|
private $ruleMapper; |
22
|
|
|
|
23
|
|
|
public function __construct($appName, IRequest $request, RuleMapper $ruleMapper) { |
24
|
|
|
parent::__construct($appName, $request); |
25
|
|
|
$this->ruleMapper = $ruleMapper; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns all rules |
30
|
|
|
* @return JSONResponse |
31
|
|
|
*/ |
32
|
|
|
public function listAll() { |
33
|
|
|
$statuses = $this->ruleMapper->findAll(); |
34
|
|
|
return new JSONResponse(['statuses' => $statuses]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Removes all rules |
39
|
|
|
* @return JSONResponse |
40
|
|
|
*/ |
41
|
|
|
public function clear() { |
42
|
|
|
$this->ruleMapper->deleteAll(); |
43
|
|
|
return new JSONResponse(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Resets a table to initial state |
48
|
|
|
* @return JSONResponse |
49
|
|
|
*/ |
50
|
|
|
public function reset() { |
51
|
|
|
$this->ruleMapper->deleteAll(); |
52
|
|
|
$this->ruleMapper->populate(); |
53
|
|
|
return new JSONResponse(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Adds/Updates a rule |
58
|
|
|
* @param int $id |
59
|
|
|
* @param int $statusType |
60
|
|
|
* @param string $match |
61
|
|
|
* @param string $description |
62
|
|
|
* @param int $status |
63
|
|
|
* @return JSONResponse |
64
|
|
|
*/ |
65
|
|
|
public function save($id, $statusType, $match, $description, $status) { |
66
|
|
|
if ($id) { |
67
|
|
|
$rule = $this->ruleMapper->find($id); |
68
|
|
|
} else { |
69
|
|
|
$rule = new Rule(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$rule->setStatusType($statusType); |
73
|
|
|
$rule->setDescription($description); |
74
|
|
|
$rule->setStatus($status); |
75
|
|
|
|
76
|
|
|
if ($statusType === Rule::RULE_TYPE_CODE) { |
77
|
|
|
$rule->setResult($match); |
78
|
|
|
} else { |
79
|
|
|
$rule->setMatch($match); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if ($id) { |
83
|
|
|
$newRule = $this->ruleMapper->update($rule); |
|
|
|
|
84
|
|
|
} else { |
85
|
|
|
$newRule = $this->ruleMapper->insert($rule); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return new JSONResponse($newRule); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Deletes a rule |
93
|
|
|
* @param int $id |
94
|
|
|
* @return JSONResponse |
95
|
|
|
*/ |
96
|
|
|
public function delete($id) { |
97
|
|
|
try { |
98
|
|
|
$rule = $this->ruleMapper->find($id); |
99
|
|
|
$this->ruleMapper->delete($rule); |
|
|
|
|
100
|
|
|
} catch (\Exception $e) { |
101
|
|
|
//TODO: Handle |
102
|
|
|
} |
103
|
|
|
return new JSONResponse($rule); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.