1<?php 2/** 3 * @copyright Copyright (c) 2016, ownCloud, Inc. 4 * 5 * @author Joas Schilling <coding@schilljs.com> 6 * @author John Molakvoæ <skjnldsv@protonmail.com> 7 * 8 * @license AGPL-3.0 9 * 10 * This code is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Affero General Public License, version 3, 12 * as published by the Free Software Foundation. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Affero General Public License for more details. 18 * 19 * You should have received a copy of the GNU Affero General Public License, version 3, 20 * along with this program. If not, see <http://www.gnu.org/licenses/> 21 * 22 */ 23 24namespace OCA\Activity\AppInfo; 25 26use OC\Files\View; 27use OCA\Activity\Capabilities; 28use OCA\Activity\Consumer; 29use OCA\Activity\FilesHooksStatic; 30use OCA\Activity\Hooks; 31use OCA\Activity\Listener\LoadSidebarScripts; 32use OCA\Activity\NotificationGenerator; 33use OCA\Activity\Dashboard\ActivityWidget; 34use OCA\Files\Event\LoadSidebar; 35use OCP\AppFramework\App; 36use OCP\AppFramework\Bootstrap\IBootContext; 37use OCP\AppFramework\Bootstrap\IBootstrap; 38use OCP\AppFramework\Bootstrap\IRegistrationContext; 39use OCP\Util; 40 41class Application extends App implements IBootstrap { 42 public const APP_ID = 'activity'; 43 44 public function __construct(array $params = []) { 45 parent::__construct(self::APP_ID, $params); 46 } 47 48 public function register(IRegistrationContext $context): void { 49 // Allow automatic DI for the View, until we migrated to Nodes API 50 $context->registerService(View::class, function () { 51 return new View(''); 52 }, false); 53 54 $context->registerCapability(Capabilities::class); 55 $context->registerEventListener(LoadSidebar::class, LoadSidebarScripts::class); 56 $context->registerDashboardWidget(ActivityWidget::class); 57 } 58 59 public function boot(IBootContext $context): void { 60 $this->registerActivityConsumer(); 61 $this->registerHooksAndEvents(); 62 $this->registerNotifier(); 63 } 64 65 /** 66 * Registers the consumer to the Activity Manager 67 */ 68 private function registerActivityConsumer() { 69 $c = $this->getContainer(); 70 /** @var \OCP\IServerContainer $server */ 71 $server = $c->getServer(); 72 73 $server->getActivityManager()->registerConsumer(function () use ($c) { 74 return $c->query(Consumer::class); 75 }); 76 } 77 78 public function registerNotifier() { 79 $server = $this->getContainer()->getServer(); 80 $server->getNotificationManager()->registerNotifierService(NotificationGenerator::class); 81 } 82 83 /** 84 * Register the hooks and events 85 */ 86 private function registerHooksAndEvents() { 87 Util::connectHook('OC_User', 'post_deleteUser', Hooks::class, 'deleteUser'); 88 Util::connectHook('OC_User', 'post_login', Hooks::class, 'setDefaultsForUser'); 89 90 $this->registerFilesActivity(); 91 } 92 93 /** 94 * Register the hooks for filesystem operations 95 */ 96 private function registerFilesActivity() { 97 // All other events from other apps have to be send via the Consumer 98 Util::connectHook('OC_Filesystem', 'post_create', FilesHooksStatic::class, 'fileCreate'); 99 Util::connectHook('OC_Filesystem', 'post_update', FilesHooksStatic::class, 'fileUpdate'); 100 Util::connectHook('OC_Filesystem', 'delete', FilesHooksStatic::class, 'fileDelete'); 101 Util::connectHook('OC_Filesystem', 'rename', FilesHooksStatic::class, 'fileMove'); 102 Util::connectHook('OC_Filesystem', 'post_rename', FilesHooksStatic::class, 'fileMovePost'); 103 Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', FilesHooksStatic::class, 'fileRestore'); 104 Util::connectHook('OCP\Share', 'post_shared', FilesHooksStatic::class, 'share'); 105 106 $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher(); 107 $eventDispatcher->addListener('OCP\Share::preUnshare', [FilesHooksStatic::class, 'unShare']); 108 $eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [FilesHooksStatic::class, 'unShareSelf']); 109 } 110} 111