Application.php 7.3 KB

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