Completed
Pull Request — master (#124)
by Joas
09:12
created

Application::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

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