1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ownCloud - Files_antivirus |
4
|
|
|
* |
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
6
|
|
|
* later. See the COPYING file. |
7
|
|
|
* |
8
|
|
|
* @author Viktar Dubiniuk <[email protected]> |
9
|
|
|
* |
10
|
|
|
* @copyright Viktar Dubiniuk 2018 |
11
|
|
|
* @license AGPL-3.0 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace OCA\Files_Antivirus\Dav; |
15
|
|
|
|
16
|
|
|
use OCA\DAV\Upload\FutureFile; |
17
|
|
|
use OCP\IUserSession; |
18
|
|
|
use Sabre\DAV\Server; |
19
|
|
|
use Sabre\DAV\ServerPlugin; |
20
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
21
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Sabre plugin for the the antivirus |
25
|
|
|
*/ |
26
|
|
|
class AntivirusPlugin extends ServerPlugin { |
27
|
|
|
const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \Sabre\DAV\Server $server |
31
|
|
|
*/ |
32
|
|
|
private $server; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var EventDispatcherInterface |
36
|
|
|
*/ |
37
|
|
|
private $dispatcher; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Constructor |
41
|
|
|
* |
42
|
|
|
* @param IUserSession $userSession |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
IUserSession $userSession, EventDispatcherInterface $dispatcher |
46
|
|
|
) { |
47
|
|
|
$this->userSession = $userSession; |
48
|
|
|
$this->dispatcher = $dispatcher; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* This initializes the plugin. |
53
|
|
|
* |
54
|
|
|
* This function is called by Sabre\DAV\Server, after |
55
|
|
|
* addPlugin is called. |
56
|
|
|
* |
57
|
|
|
* This method should set up the required event subscriptions. |
58
|
|
|
* |
59
|
|
|
* @param Server $server |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
function initialize(Server $server) { |
|
|
|
|
64
|
|
|
$this->server = $server; |
65
|
|
|
$this->server->on('beforeMove', [$this, 'beforeMove'], 1); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $source |
71
|
|
|
* @param string $destination |
72
|
|
|
* |
73
|
|
|
* @return bool|void |
74
|
|
|
* @throws \Sabre\DAV\Exception\NotFound |
75
|
|
|
*/ |
76
|
|
|
public function beforeMove($source, $destination) { |
77
|
|
|
$sourceNode = $this->server->tree->getNodeForPath($source); |
78
|
|
|
if (!$sourceNode instanceof FutureFile) { |
|
|
|
|
79
|
|
|
return; |
80
|
|
|
} |
81
|
|
|
$finalSize = $sourceNode->getSize(); |
82
|
|
|
$this->dispatcher->dispatch( |
83
|
|
|
'\OCA\Files_Antivirus\Dav\AntivirusPlugin::beforeMove', |
84
|
|
|
new GenericEvent( |
85
|
|
|
null, |
86
|
|
|
[ |
87
|
|
|
'path' => $destination, |
88
|
|
|
'finalSize' => $finalSize |
89
|
|
|
] |
90
|
|
|
) |
91
|
|
|
); |
92
|
|
|
return true; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.