Completed
Pull Request — master (#125)
by Joas
241:57 queued 240:00
created

Application   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 36.96%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 80
ccs 17
cts 46
cp 0.3696
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 1
A register() 0 5 1
A registerActivityConsumer() 0 9 1
A registerHooksAndEvents() 0 9 1
A registerFilesActivity() 0 11 1
A registerPersonalPage() 0 3 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Joas Schilling <[email protected]>
6
 *
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
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, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OCA\Activity\AppInfo;
24
25
use OC\Files\View;
26
use OCA\Activity\Capabilities;
27
use OCA\Activity\Consumer;
28
use OCA\Activity\Controller\Activities;
29
use OCA\Activity\Controller\APIv1;
30
use OCA\Activity\Controller\APIv2;
31
use OCA\Activity\Controller\Feed;
32
use OCA\Activity\Controller\Settings;
33
use OCA\Activity\FilesHooksStatic;
34
use OCA\Activity\Hooks;
35
use OCP\AppFramework\App;
36
use OCP\IL10N;
37
use OCP\Util;
38
39
class Application extends App {
40 48
	public function __construct () {
41 48
		parent::__construct('activity');
42 48
		$container = $this->getContainer();
43
44
		// Allow automatic DI for the View, until we migrated to Nodes API
45
		$container->registerService(View::class, function() {
46 23
			return new View('');
47 48
		}, false);
48
		$container->registerService('isCLI', function() {
49 2
			return \OC::$CLI;
50 48
		});
51
52
		// Aliases for the controllers so we can use the automatic DI
53 48
		$container->registerAlias('ActivitiesController', Activities::class);
54 48
		$container->registerAlias('APIv1Controller', APIv1::class);
55 48
		$container->registerAlias('APIv2Controller', APIv2::class);
56 48
		$container->registerAlias('FeedController', Feed::class);
57 48
		$container->registerAlias('SettingsController', Settings::class);
58
59 48
		$container->registerCapability(Capabilities::class);
60 48
	}
61
62
	/**
63
	 * Register the different app parts
64
	 */
65
	public function register() {
66
		$this->registerActivityConsumer();
67
		$this->registerHooksAndEvents();
68
		$this->registerPersonalPage();
69
	}
70
71
	/**
72
	 * Registers the consumer to the Activity Manager
73
	 */
74 1
	public function registerActivityConsumer() {
75
		$c = $this->getContainer();
76
		/** @var \OCP\IServerContainer $server */
77
		$server = $c->getServer();
78
79 1
		$server->getActivityManager()->registerConsumer(function() use ($c) {
80 1
			return $c->query(Consumer::class);
81
		});
82
	}
83
84
	/**
85
	 * Register the hooks and events
86
	 */
87
	public function registerHooksAndEvents() {
88
		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
89
		$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', [Hooks::class, 'onLoadFilesAppScripts']);
90
91
		Util::connectHook('OC_User', 'post_deleteUser', Hooks::class, 'deleteUser');
92
		Util::connectHook('OC_User', 'post_login', Hooks::class, 'setDefaultsForUser');
93
94
		$this->registerFilesActivity();
95
	}
96
97
	/**
98
	 * Register the hooks for filesystem operations
99
	 */
100
	public function registerFilesActivity() {
101
		// All other events from other apps have to be send via the Consumer
102
		Util::connectHook('OC_Filesystem', 'post_create', FilesHooksStatic::class, 'fileCreate');
103
		Util::connectHook('OC_Filesystem', 'post_update', FilesHooksStatic::class, 'fileUpdate');
104
		Util::connectHook('OC_Filesystem', 'delete', FilesHooksStatic::class, 'fileDelete');
105
		Util::connectHook('OC_Filesystem', 'rename', FilesHooksStatic::class, 'fileMove');
106
		Util::connectHook('OC_Filesystem', 'post_rename', FilesHooksStatic::class, 'fileMovePost');
107
		Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', FilesHooksStatic::class, 'fileRestore');
108
		Util::connectHook('OCP\Share', 'post_shared', FilesHooksStatic::class, 'share');
109
		Util::connectHook('OCP\Share', 'pre_unshare', FilesHooksStatic::class, 'unShare');
110
	}
111
112
	/**
113
	 * Register personal settings for notifications and emails
114
	 */
115
	public function registerPersonalPage() {
116
		\OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal');
117
	}
118
}
119