Completed
Push — master ( 6186ee...7b5727 )
by Joas
25s queued 18s
created

Application   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 36.17%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 81
ccs 17
cts 47
cp 0.3617
rs 10
c 0
b 0
f 0

6 Methods

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