1
0

Application.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author John Molakvoæ <skjnldsv@protonmail.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Mario Danic <mario@lovelyhq.com>
  12. * @author Morris Jobke <hey@morrisjobke.de>
  13. * @author Robin Appelman <robin@icewind.nl>
  14. * @author Roeland Jago Douma <roeland@famdouma.nl>
  15. * @author Thomas Citharel <nextcloud@tcit.fr>
  16. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  17. *
  18. * @license AGPL-3.0
  19. *
  20. * This code is free software: you can redistribute it and/or modify
  21. * it under the terms of the GNU Affero General Public License, version 3,
  22. * as published by the Free Software Foundation.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU Affero General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Affero General Public License, version 3,
  30. * along with this program. If not, see <http://www.gnu.org/licenses/>
  31. *
  32. */
  33. namespace OC\Core;
  34. use OC\Authentication\Events\RemoteWipeFinished;
  35. use OC\Authentication\Events\RemoteWipeStarted;
  36. use OC\Authentication\Listeners\RemoteWipeActivityListener;
  37. use OC\Authentication\Listeners\RemoteWipeEmailListener;
  38. use OC\Authentication\Listeners\RemoteWipeNotificationsListener;
  39. use OC\Authentication\Listeners\UserDeletedFilesCleanupListener;
  40. use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
  41. use OC\Authentication\Listeners\UserDeletedTokenCleanupListener;
  42. use OC\Authentication\Listeners\UserDeletedWebAuthnCleanupListener;
  43. use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
  44. use OC\Core\Listener\BeforeTemplateRenderedListener;
  45. use OC\Core\Notification\CoreNotifier;
  46. use OC\TagManager;
  47. use OCP\AppFramework\App;
  48. use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
  49. use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
  50. use OCP\DB\Events\AddMissingIndicesEvent;
  51. use OCP\DB\Events\AddMissingPrimaryKeyEvent;
  52. use OCP\EventDispatcher\IEventDispatcher;
  53. use OCP\User\Events\BeforeUserDeletedEvent;
  54. use OCP\User\Events\UserDeletedEvent;
  55. use OCP\Util;
  56. /**
  57. * Class Application
  58. *
  59. * @package OC\Core
  60. */
  61. class Application extends App {
  62. public function __construct() {
  63. parent::__construct('core');
  64. $container = $this->getContainer();
  65. $container->registerService('defaultMailAddress', function () {
  66. return Util::getDefaultEmailAddress('lostpassword-noreply');
  67. });
  68. $server = $container->getServer();
  69. /** @var IEventDispatcher $eventDispatcher */
  70. $eventDispatcher = $server->get(IEventDispatcher::class);
  71. $notificationManager = $server->getNotificationManager();
  72. $notificationManager->registerNotifierService(CoreNotifier::class);
  73. $notificationManager->registerNotifierService(AuthenticationNotifier::class);
  74. $eventDispatcher->addListener(AddMissingIndicesEvent::class, function (AddMissingIndicesEvent $event) {
  75. $event->addMissingIndex(
  76. 'share',
  77. 'share_with_index',
  78. ['share_with']
  79. );
  80. $event->addMissingIndex(
  81. 'share',
  82. 'parent_index',
  83. ['parent']
  84. );
  85. $event->addMissingIndex(
  86. 'share',
  87. 'owner_index',
  88. ['uid_owner']
  89. );
  90. $event->addMissingIndex(
  91. 'share',
  92. 'initiator_index',
  93. ['uid_initiator']
  94. );
  95. $event->addMissingIndex(
  96. 'filecache',
  97. 'fs_mtime',
  98. ['mtime']
  99. );
  100. $event->addMissingIndex(
  101. 'filecache',
  102. 'fs_size',
  103. ['size']
  104. );
  105. $event->addMissingIndex(
  106. 'filecache',
  107. 'fs_id_storage_size',
  108. ['fileid', 'storage', 'size']
  109. );
  110. $event->addMissingIndex(
  111. 'filecache',
  112. 'fs_storage_path_prefix',
  113. ['storage', 'path'],
  114. ['lengths' => [null, 64]]
  115. );
  116. $event->addMissingIndex(
  117. 'filecache',
  118. 'fs_parent',
  119. ['parent']
  120. );
  121. $event->addMissingIndex(
  122. 'twofactor_providers',
  123. 'twofactor_providers_uid',
  124. ['uid']
  125. );
  126. $event->addMissingUniqueIndex(
  127. 'login_flow_v2',
  128. 'poll_token',
  129. ['poll_token'],
  130. [],
  131. true
  132. );
  133. $event->addMissingUniqueIndex(
  134. 'login_flow_v2',
  135. 'login_token',
  136. ['login_token'],
  137. [],
  138. true
  139. );
  140. $event->addMissingIndex(
  141. 'login_flow_v2',
  142. 'timestamp',
  143. ['timestamp'],
  144. [],
  145. true
  146. );
  147. $event->addMissingIndex(
  148. 'whats_new',
  149. 'version',
  150. ['version'],
  151. [],
  152. true
  153. );
  154. $event->addMissingIndex(
  155. 'cards',
  156. 'cards_abiduri',
  157. ['addressbookid', 'uri'],
  158. [],
  159. true
  160. );
  161. $event->addMissingIndex(
  162. 'cards',
  163. 'cards_abid',
  164. ['addressbookid'],
  165. [],
  166. true
  167. );
  168. $event->addMissingIndex(
  169. 'cards',
  170. 'cards_abiduri',
  171. ['addressbookid', 'uri'],
  172. [],
  173. true
  174. );
  175. $event->addMissingIndex(
  176. 'cards_properties',
  177. 'cards_prop_abid',
  178. ['addressbookid'],
  179. [],
  180. true
  181. );
  182. $event->addMissingIndex(
  183. 'calendarobjects_props',
  184. 'calendarobject_calid_index',
  185. ['calendarid', 'calendartype']
  186. );
  187. $event->addMissingIndex(
  188. 'schedulingobjects',
  189. 'schedulobj_principuri_index',
  190. ['principaluri']
  191. );
  192. $event->addMissingIndex(
  193. 'properties',
  194. 'properties_path_index',
  195. ['userid', 'propertypath']
  196. );
  197. $event->addMissingIndex(
  198. 'properties',
  199. 'properties_pathonly_index',
  200. ['propertypath']
  201. );
  202. $event->addMissingIndex(
  203. 'jobs',
  204. 'job_lastcheck_reserved',
  205. ['last_checked', 'reserved_at']
  206. );
  207. $event->addMissingIndex(
  208. 'direct_edit',
  209. 'direct_edit_timestamp',
  210. ['timestamp']
  211. );
  212. $event->addMissingIndex(
  213. 'preferences',
  214. 'preferences_app_key',
  215. ['appid', 'configkey']
  216. );
  217. $event->addMissingIndex(
  218. 'mounts',
  219. 'mounts_class_index',
  220. ['mount_provider_class']
  221. );
  222. $event->addMissingIndex(
  223. 'mounts',
  224. 'mounts_user_root_path_index',
  225. ['user_id', 'root_id', 'mount_point'],
  226. ['lengths' => [null, null, 128]]
  227. );
  228. $event->addMissingIndex(
  229. 'systemtag_object_mapping',
  230. 'systag_by_tagid',
  231. ['systemtagid', 'objecttype']
  232. );
  233. });
  234. $eventDispatcher->addListener(AddMissingPrimaryKeyEvent::class, function (AddMissingPrimaryKeyEvent $event) {
  235. $event->addMissingPrimaryKey(
  236. 'federated_reshares',
  237. 'federated_res_pk',
  238. ['share_id'],
  239. 'share_id_index'
  240. );
  241. $event->addMissingPrimaryKey(
  242. 'systemtag_object_mapping',
  243. 'som_pk',
  244. ['objecttype', 'objectid', 'systemtagid'],
  245. 'mapping'
  246. );
  247. $event->addMissingPrimaryKey(
  248. 'comments_read_markers',
  249. 'crm_pk',
  250. ['user_id', 'object_type', 'object_id'],
  251. 'comments_marker_index'
  252. );
  253. $event->addMissingPrimaryKey(
  254. 'collres_resources',
  255. 'crr_pk',
  256. ['collection_id', 'resource_type', 'resource_id'],
  257. 'collres_unique_res'
  258. );
  259. $event->addMissingPrimaryKey(
  260. 'collres_accesscache',
  261. 'cra_pk',
  262. ['user_id', 'collection_id', 'resource_type', 'resource_id'],
  263. 'collres_unique_user'
  264. );
  265. $event->addMissingPrimaryKey(
  266. 'filecache_extended',
  267. 'fce_pk',
  268. ['fileid'],
  269. 'fce_fileid_idx'
  270. );
  271. });
  272. $eventDispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
  273. $eventDispatcher->addServiceListener(BeforeLoginTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
  274. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  275. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  276. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  277. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  278. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  279. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  280. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
  281. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
  282. $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
  283. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
  284. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
  285. // Tags
  286. $eventDispatcher->addServiceListener(UserDeletedEvent::class, TagManager::class);
  287. }
  288. }