Application.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core;
  8. use OC\Authentication\Events\RemoteWipeFinished;
  9. use OC\Authentication\Events\RemoteWipeStarted;
  10. use OC\Authentication\Listeners\RemoteWipeActivityListener;
  11. use OC\Authentication\Listeners\RemoteWipeEmailListener;
  12. use OC\Authentication\Listeners\RemoteWipeNotificationsListener;
  13. use OC\Authentication\Listeners\UserDeletedFilesCleanupListener;
  14. use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
  15. use OC\Authentication\Listeners\UserDeletedTokenCleanupListener;
  16. use OC\Authentication\Listeners\UserDeletedWebAuthnCleanupListener;
  17. use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
  18. use OC\Core\Listener\BeforeTemplateRenderedListener;
  19. use OC\Core\Notification\CoreNotifier;
  20. use OC\TagManager;
  21. use OCP\AppFramework\App;
  22. use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
  23. use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
  24. use OCP\DB\Events\AddMissingIndicesEvent;
  25. use OCP\DB\Events\AddMissingPrimaryKeyEvent;
  26. use OCP\EventDispatcher\IEventDispatcher;
  27. use OCP\Notification\IManager as INotificationManager;
  28. use OCP\User\Events\BeforeUserDeletedEvent;
  29. use OCP\User\Events\UserDeletedEvent;
  30. use OCP\Util;
  31. /**
  32. * Class Application
  33. *
  34. * @package OC\Core
  35. */
  36. class Application extends App {
  37. public function __construct() {
  38. parent::__construct('core');
  39. $container = $this->getContainer();
  40. $container->registerService('defaultMailAddress', function () {
  41. return Util::getDefaultEmailAddress('lostpassword-noreply');
  42. });
  43. $server = $container->getServer();
  44. /** @var IEventDispatcher $eventDispatcher */
  45. $eventDispatcher = $server->get(IEventDispatcher::class);
  46. $notificationManager = $server->get(INotificationManager::class);
  47. $notificationManager->registerNotifierService(CoreNotifier::class);
  48. $notificationManager->registerNotifierService(AuthenticationNotifier::class);
  49. $eventDispatcher->addListener(AddMissingIndicesEvent::class, function (AddMissingIndicesEvent $event) {
  50. $event->addMissingIndex(
  51. 'share',
  52. 'share_with_index',
  53. ['share_with']
  54. );
  55. $event->addMissingIndex(
  56. 'share',
  57. 'parent_index',
  58. ['parent']
  59. );
  60. $event->addMissingIndex(
  61. 'share',
  62. 'owner_index',
  63. ['uid_owner']
  64. );
  65. $event->addMissingIndex(
  66. 'share',
  67. 'initiator_index',
  68. ['uid_initiator']
  69. );
  70. $event->addMissingIndex(
  71. 'filecache',
  72. 'fs_mtime',
  73. ['mtime']
  74. );
  75. $event->addMissingIndex(
  76. 'filecache',
  77. 'fs_size',
  78. ['size']
  79. );
  80. $event->addMissingIndex(
  81. 'filecache',
  82. 'fs_id_storage_size',
  83. ['fileid', 'storage', 'size']
  84. );
  85. $event->addMissingIndex(
  86. 'filecache',
  87. 'fs_storage_path_prefix',
  88. ['storage', 'path'],
  89. ['lengths' => [null, 64]]
  90. );
  91. $event->addMissingIndex(
  92. 'filecache',
  93. 'fs_parent',
  94. ['parent']
  95. );
  96. $event->addMissingIndex(
  97. 'filecache',
  98. 'fs_name_hash',
  99. ['name']
  100. );
  101. $event->addMissingIndex(
  102. 'twofactor_providers',
  103. 'twofactor_providers_uid',
  104. ['uid']
  105. );
  106. $event->addMissingUniqueIndex(
  107. 'login_flow_v2',
  108. 'poll_token',
  109. ['poll_token'],
  110. [],
  111. true
  112. );
  113. $event->addMissingUniqueIndex(
  114. 'login_flow_v2',
  115. 'login_token',
  116. ['login_token'],
  117. [],
  118. true
  119. );
  120. $event->addMissingIndex(
  121. 'login_flow_v2',
  122. 'timestamp',
  123. ['timestamp'],
  124. [],
  125. true
  126. );
  127. $event->addMissingIndex(
  128. 'whats_new',
  129. 'version',
  130. ['version'],
  131. [],
  132. true
  133. );
  134. $event->addMissingIndex(
  135. 'cards',
  136. 'cards_abiduri',
  137. ['addressbookid', 'uri'],
  138. [],
  139. true
  140. );
  141. $event->addMissingIndex(
  142. 'cards_properties',
  143. 'cards_prop_abid',
  144. ['addressbookid'],
  145. [],
  146. true
  147. );
  148. $event->addMissingIndex(
  149. 'calendarobjects_props',
  150. 'calendarobject_calid_index',
  151. ['calendarid', 'calendartype']
  152. );
  153. $event->addMissingIndex(
  154. 'schedulingobjects',
  155. 'schedulobj_principuri_index',
  156. ['principaluri']
  157. );
  158. $event->addMissingIndex(
  159. 'schedulingobjects',
  160. 'schedulobj_lastmodified_idx',
  161. ['lastmodified']
  162. );
  163. $event->addMissingIndex(
  164. 'properties',
  165. 'properties_path_index',
  166. ['userid', 'propertypath']
  167. );
  168. $event->addMissingIndex(
  169. 'properties',
  170. 'properties_pathonly_index',
  171. ['propertypath']
  172. );
  173. $event->addMissingIndex(
  174. 'jobs',
  175. 'job_lastcheck_reserved',
  176. ['last_checked', 'reserved_at']
  177. );
  178. $event->addMissingIndex(
  179. 'direct_edit',
  180. 'direct_edit_timestamp',
  181. ['timestamp']
  182. );
  183. $event->addMissingIndex(
  184. 'preferences',
  185. 'preferences_app_key',
  186. ['appid', 'configkey']
  187. );
  188. $event->addMissingIndex(
  189. 'mounts',
  190. 'mounts_class_index',
  191. ['mount_provider_class']
  192. );
  193. $event->addMissingIndex(
  194. 'mounts',
  195. 'mounts_user_root_path_index',
  196. ['user_id', 'root_id', 'mount_point'],
  197. ['lengths' => [null, null, 128]]
  198. );
  199. $event->addMissingIndex(
  200. 'systemtag_object_mapping',
  201. 'systag_by_tagid',
  202. ['systemtagid', 'objecttype']
  203. );
  204. $event->addMissingIndex(
  205. 'systemtag_object_mapping',
  206. 'systag_by_objectid',
  207. ['objectid']
  208. );
  209. });
  210. $eventDispatcher->addListener(AddMissingPrimaryKeyEvent::class, function (AddMissingPrimaryKeyEvent $event) {
  211. $event->addMissingPrimaryKey(
  212. 'federated_reshares',
  213. 'federated_res_pk',
  214. ['share_id'],
  215. 'share_id_index'
  216. );
  217. $event->addMissingPrimaryKey(
  218. 'systemtag_object_mapping',
  219. 'som_pk',
  220. ['objecttype', 'objectid', 'systemtagid'],
  221. 'mapping'
  222. );
  223. $event->addMissingPrimaryKey(
  224. 'comments_read_markers',
  225. 'crm_pk',
  226. ['user_id', 'object_type', 'object_id'],
  227. 'comments_marker_index'
  228. );
  229. $event->addMissingPrimaryKey(
  230. 'collres_resources',
  231. 'crr_pk',
  232. ['collection_id', 'resource_type', 'resource_id'],
  233. 'collres_unique_res'
  234. );
  235. $event->addMissingPrimaryKey(
  236. 'collres_accesscache',
  237. 'cra_pk',
  238. ['user_id', 'collection_id', 'resource_type', 'resource_id'],
  239. 'collres_unique_user'
  240. );
  241. $event->addMissingPrimaryKey(
  242. 'filecache_extended',
  243. 'fce_pk',
  244. ['fileid'],
  245. 'fce_fileid_idx'
  246. );
  247. });
  248. $eventDispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
  249. $eventDispatcher->addServiceListener(BeforeLoginTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
  250. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  251. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  252. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  253. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  254. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  255. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  256. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
  257. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
  258. $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
  259. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
  260. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
  261. // Tags
  262. $eventDispatcher->addServiceListener(UserDeletedEvent::class, TagManager::class);
  263. }
  264. }