Completed
Pull Request — master (#452)
by Joas
05:24
created

FilesHooksStatic::fileDelete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * ownCloud - Activity App
5
 *
6
 * @author Joas Schilling
7
 * @copyright 2014 Joas Schilling [email protected]
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
11
 * License as published by the Free Software Foundation; either
12
 * version 3 of the License, or any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
namespace OCA\Activity;
24
25
use OCP\Util;
26
27
/**
28
 * The class to handle the filesystem hooks
29
 */
30
class FilesHooksStatic {
31
	/**
32
	 * Registers the filesystem hooks for basic filesystem operations.
33
	 * All other events has to be triggered by the apps.
34
	 */
35 1
	public static function register() {
36 1
		Util::connectHook('OC_Filesystem', 'post_create', 'OCA\Activity\FilesHooksStatic', 'fileCreate');
37 1
		Util::connectHook('OC_Filesystem', 'post_update', 'OCA\Activity\FilesHooksStatic', 'fileUpdate');
38 1
		Util::connectHook('OC_Filesystem', 'delete', 'OCA\Activity\FilesHooksStatic', 'fileDelete');
39 1
		Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', 'OCA\Activity\FilesHooksStatic', 'fileRestore');
40 1
		Util::connectHook('OCP\Share', 'post_shared', 'OCA\Activity\FilesHooksStatic', 'share');
41
42 1
		$eventDispatcher = \OC::$server->getEventDispatcher();
43 1
		$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', ['OCA\Activity\FilesHooksStatic', 'onLoadFilesAppScripts']);
44 1
	}
45
46
	/**
47
	 * @return FilesHooks
48
	 */
49
	static protected function getHooks() {
50
		$app = new AppInfo\Application();
51
		return $app->getContainer()->query('Hooks');
52
	}
53
54
	/**
55
	 * Store the create hook events
56
	 * @param array $params The hook params
57
	 */
58
	public static function fileCreate($params) {
59
		self::getHooks()->fileCreate($params['path']);
60
	}
61
62
	/**
63
	 * Store the update hook events
64
	 * @param array $params The hook params
65
	 */
66
	public static function fileUpdate($params) {
67
		self::getHooks()->fileUpdate($params['path']);
68
	}
69
70
	/**
71
	 * Store the delete hook events
72
	 * @param array $params The hook params
73
	 */
74
	public static function fileDelete($params) {
75
		self::getHooks()->fileDelete($params['path']);
76
	}
77
78
	/**
79
	 * Store the restore hook events
80
	 * @param array $params The hook params
81
	 */
82
	public static function fileRestore($params) {
83
		self::getHooks()->fileRestore($params['filePath']);
84
	}
85
86
	/**
87
	 * Manage sharing events
88
	 * @param array $params The hook params
89
	 */
90
	public static function share($params) {
91
		self::getHooks()->share($params);
92
	}
93
94
	/**
95
	 * Load additional scripts when the files app is visible
96
	 */
97
	public static function onLoadFilesAppScripts() {
98
		Util::addStyle('activity', 'style');
99
		Util::addScript('activity', 'formatter');
100
		Util::addScript('activity', 'activitymodel');
101
		Util::addScript('activity', 'activitycollection');
102
		Util::addScript('activity', 'activitytabview');
103
		Util::addScript('activity', 'filesplugin');
104
	}
105
}
106