Completed
Push — master ( 13dc69...5586be )
by Joas
13s
created

Application   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 88
ccs 50
cts 50
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
A registerActivityConsumer() 0 9 1
A registerHooksAndEvents() 0 8 1
A registerFilesActivity() 0 11 1
A registerPersonalPage() 0 3 1
A registerNavigationEntry() 0 16 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 22
			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 navigation entry
61
	 */
62 1
	public function registerNavigationEntry() {
63 1
		$c = $this->getContainer();
64
		/** @var \OCP\IServerContainer $server */
65 1
		$server = $c->getServer();
66
67
		$navigationEntry = function () use ($c, $server) {
68
			return [
69 1
				'id' => $c->getAppName(),
70 1
				'order' => 1,
71 1
				'name' => $c->query(IL10N::class)->t('Activity'),
72 1
				'href' => $server->getURLGenerator()->linkToRoute('activity.Activities.showList'),
73 1
				'icon' => $server->getURLGenerator()->imagePath($c->getAppName(), 'activity.svg'),
74
			];
75 1
		};
76 1
		$server->getNavigationManager()->add($navigationEntry);
77 1
	}
78
79
	/**
80
	 * Registers the consumer to the Activity Manager
81
	 */
82 1
	public function registerActivityConsumer() {
83 1
		$c = $this->getContainer();
84
		/** @var \OCP\IServerContainer $server */
85 1
		$server = $c->getServer();
86
87 1
		$server->getActivityManager()->registerConsumer(function() use ($c) {
88 1
			return $c->query(Consumer::class);
89 1
		});
90 1
	}
91
92
	/**
93
	 * Register the hooks and events
94
	 */
95 1
	public function registerHooksAndEvents() {
96 1
		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
97 1
		$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', [FilesHooksStatic::class, 'onLoadFilesAppScripts']);
98
99 1
		Util::connectHook('OC_User', 'post_deleteUser', Hooks::class, 'deleteUser');
100
101 1
		$this->registerFilesActivity();
102 1
	}
103
104
	/**
105
	 * Register the hooks for filesystem operations
106
	 */
107 1
	public function registerFilesActivity() {
108
		// All other events from other apps have to be send via the Consumer
109 1
		Util::connectHook('OC_Filesystem', 'post_create', FilesHooksStatic::class, 'fileCreate');
110 1
		Util::connectHook('OC_Filesystem', 'post_update', FilesHooksStatic::class, 'fileUpdate');
111 1
		Util::connectHook('OC_Filesystem', 'delete', FilesHooksStatic::class, 'fileDelete');
112 1
		Util::connectHook('OC_Filesystem', 'rename', FilesHooksStatic::class, 'fileMove');
113 1
		Util::connectHook('OC_Filesystem', 'post_rename', FilesHooksStatic::class, 'fileMovePost');
114 1
		Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', FilesHooksStatic::class, 'fileRestore');
115 1
		Util::connectHook('OCP\Share', 'post_shared', FilesHooksStatic::class, 'share');
116 1
		Util::connectHook('OCP\Share', 'pre_unshare', FilesHooksStatic::class, 'unShare');
117 1
	}
118
119
	/**
120
	 * Register personal settings for notifications and emails
121
	 */
122 1
	public function registerPersonalPage() {
123 1
		\OCP\App::registerPersonal($this->getContainer()->getAppName(), 'personal');
124 1
	}
125
}
126