Completed
Pull Request — master (#215)
by Morris
23:16
created

Application   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 37.5%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 83
ccs 18
cts 48
cp 0.375
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 22 1
A register() 0 5 1
A registerActivityConsumer() 0 9 1
A registerHooksAndEvents() 0 9 1
A registerFilesActivity() 0 13 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\RemoteActivity;
33
use OCA\Activity\Controller\Settings;
34
use OCA\Activity\FilesHooksStatic;
35
use OCA\Activity\Hooks;
36
use OCP\AppFramework\App;
37
use OCP\IL10N;
38
use OCP\Util;
39
40
class Application extends App {
41 48
	public function __construct () {
42 48
		parent::__construct('activity');
43 48
		$container = $this->getContainer();
44
45
		// Allow automatic DI for the View, until we migrated to Nodes API
46
		$container->registerService(View::class, function() {
47 23
			return new View('');
48 48
		}, false);
49
		$container->registerService('isCLI', function() {
50 2
			return \OC::$CLI;
51 48
		});
52
53
		// Aliases for the controllers so we can use the automatic DI
54 48
		$container->registerAlias('ActivitiesController', Activities::class);
55 48
		$container->registerAlias('APIv1Controller', APIv1::class);
56 48
		$container->registerAlias('APIv2Controller', APIv2::class);
57 48
		$container->registerAlias('FeedController', Feed::class);
58 48
		$container->registerAlias('RemoteActivityController', RemoteActivity::class);
59 48
		$container->registerAlias('SettingsController', Settings::class);
60
61 48
		$container->registerCapability(Capabilities::class);
62 48
	}
63
64
	/**
65
	 * Register the different app parts
66
	 */
67
	public function register() {
68
		$this->registerActivityConsumer();
69
		$this->registerHooksAndEvents();
70
		$this->registerPersonalPage();
71
	}
72
73
	/**
74
	 * Registers the consumer to the Activity Manager
75
	 */
76 1
	public function registerActivityConsumer() {
77
		$c = $this->getContainer();
78
		/** @var \OCP\IServerContainer $server */
79
		$server = $c->getServer();
80
81 1
		$server->getActivityManager()->registerConsumer(function() use ($c) {
82 1
			return $c->query(Consumer::class);
83
		});
84
	}
85
86
	/**
87
	 * Register the hooks and events
88
	 */
89
	public function registerHooksAndEvents() {
90
		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
91
		$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', [Hooks::class, 'onLoadFilesAppScripts']);
92
93
		Util::connectHook('OC_User', 'post_deleteUser', Hooks::class, 'deleteUser');
94
		Util::connectHook('OC_User', 'post_login', Hooks::class, 'setDefaultsForUser');
95
96
		$this->registerFilesActivity();
97
	}
98
99
	/**
100
	 * Register the hooks for filesystem operations
101
	 */
102
	public function registerFilesActivity() {
103
		// All other events from other apps have to be send via the Consumer
104
		Util::connectHook('OC_Filesystem', 'post_create', FilesHooksStatic::class, 'fileCreate');
105
		Util::connectHook('OC_Filesystem', 'post_update', FilesHooksStatic::class, 'fileUpdate');
106
		Util::connectHook('OC_Filesystem', 'delete', FilesHooksStatic::class, 'fileDelete');
107
		Util::connectHook('OC_Filesystem', 'rename', FilesHooksStatic::class, 'fileMove');
108
		Util::connectHook('OC_Filesystem', 'post_rename', FilesHooksStatic::class, 'fileMovePost');
109
		Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', FilesHooksStatic::class, 'fileRestore');
110
		Util::connectHook('OCP\Share', 'post_shared', FilesHooksStatic::class, 'share');
111
112
		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
113
		$eventDispatcher->addListener('OCP\Share::preUnshare', [FilesHooksStatic::class, 'unShare']);
114
	}
115
116
	/**
117
	 * Register personal settings for notifications and emails
118
	 */
119
	public function registerPersonalPage() {
120
		\OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal');
121
	}
122
}
123