Application.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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\Metadata\FileEventListener;
  47. use OC\TagManager;
  48. use OCP\AppFramework\App;
  49. use OCP\AppFramework\Http\Events\BeforeLoginTemplateRenderedEvent;
  50. use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
  51. use OCP\DB\Events\AddMissingColumnsEvent;
  52. use OCP\DB\Events\AddMissingIndicesEvent;
  53. use OCP\DB\Events\AddMissingPrimaryKeyEvent;
  54. use OCP\DB\Types;
  55. use OCP\EventDispatcher\IEventDispatcher;
  56. use OCP\Files\Events\Node\NodeDeletedEvent;
  57. use OCP\Files\Events\Node\NodeWrittenEvent;
  58. use OCP\Files\Events\NodeRemovedFromCache;
  59. use OCP\User\Events\BeforeUserDeletedEvent;
  60. use OCP\User\Events\UserDeletedEvent;
  61. use OCP\Util;
  62. use OCP\IConfig;
  63. /**
  64. * Class Application
  65. *
  66. * @package OC\Core
  67. */
  68. class Application extends App {
  69. public function __construct() {
  70. parent::__construct('core');
  71. $container = $this->getContainer();
  72. $container->registerService('defaultMailAddress', function () {
  73. return Util::getDefaultEmailAddress('lostpassword-noreply');
  74. });
  75. $server = $container->getServer();
  76. /** @var IEventDispatcher $eventDispatcher */
  77. $eventDispatcher = $server->get(IEventDispatcher::class);
  78. $notificationManager = $server->getNotificationManager();
  79. $notificationManager->registerNotifierService(CoreNotifier::class);
  80. $notificationManager->registerNotifierService(AuthenticationNotifier::class);
  81. $eventDispatcher->addListener(AddMissingIndicesEvent::class, function (AddMissingIndicesEvent $event) {
  82. $event->addMissingIndex(
  83. 'share',
  84. 'share_with_index',
  85. ['share_with']
  86. );
  87. $event->addMissingIndex(
  88. 'share',
  89. 'parent_index',
  90. ['parent']
  91. );
  92. $event->addMissingIndex(
  93. 'share',
  94. 'owner_index',
  95. ['uid_owner']
  96. );
  97. $event->addMissingIndex(
  98. 'share',
  99. 'initiator_index',
  100. ['uid_initiator']
  101. );
  102. $event->addMissingIndex(
  103. 'filecache',
  104. 'fs_mtime',
  105. ['mtime']
  106. );
  107. $event->addMissingIndex(
  108. 'filecache',
  109. 'fs_size',
  110. ['size']
  111. );
  112. $event->addMissingIndex(
  113. 'filecache',
  114. 'fs_id_storage_size',
  115. ['fileid', 'storage', 'size']
  116. );
  117. $event->addMissingIndex(
  118. 'filecache',
  119. 'fs_storage_path_prefix',
  120. ['storage', 'path'],
  121. ['lengths' => [null, 64]]
  122. );
  123. $event->addMissingIndex(
  124. 'filecache',
  125. 'fs_parent',
  126. ['parent']
  127. );
  128. $event->addMissingIndex(
  129. 'twofactor_providers',
  130. 'twofactor_providers_uid',
  131. ['uid']
  132. );
  133. $event->addMissingUniqueIndex(
  134. 'login_flow_v2',
  135. 'poll_token',
  136. ['poll_token'],
  137. [],
  138. true
  139. );
  140. $event->addMissingUniqueIndex(
  141. 'login_flow_v2',
  142. 'login_token',
  143. ['login_token'],
  144. [],
  145. true
  146. );
  147. $event->addMissingIndex(
  148. 'login_flow_v2',
  149. 'timestamp',
  150. ['timestamp'],
  151. [],
  152. true
  153. );
  154. $event->addMissingIndex(
  155. 'whats_new',
  156. 'version',
  157. ['version'],
  158. [],
  159. true
  160. );
  161. $event->addMissingIndex(
  162. 'cards',
  163. 'cards_abiduri',
  164. ['addressbookid', 'uri'],
  165. [],
  166. true
  167. );
  168. $event->addMissingIndex(
  169. 'cards',
  170. 'cards_abid',
  171. ['addressbookid'],
  172. [],
  173. true
  174. );
  175. $event->addMissingIndex(
  176. 'cards',
  177. 'cards_abiduri',
  178. ['addressbookid', 'uri'],
  179. [],
  180. true
  181. );
  182. $event->addMissingIndex(
  183. 'cards_properties',
  184. 'cards_prop_abid',
  185. ['addressbookid'],
  186. [],
  187. true
  188. );
  189. $event->addMissingIndex(
  190. 'calendarobjects_props',
  191. 'calendarobject_calid_index',
  192. ['calendarid', 'calendartype']
  193. );
  194. $event->addMissingIndex(
  195. 'schedulingobjects',
  196. 'schedulobj_principuri_index',
  197. ['principaluri']
  198. );
  199. $event->addMissingIndex(
  200. 'properties',
  201. 'properties_path_index',
  202. ['userid', 'propertypath']
  203. );
  204. $event->addMissingIndex(
  205. 'properties',
  206. 'properties_pathonly_index',
  207. ['propertypath']
  208. );
  209. $event->addMissingIndex(
  210. 'jobs',
  211. 'job_lastcheck_reserved',
  212. ['last_checked', 'reserved_at']
  213. );
  214. $event->addMissingIndex(
  215. 'direct_edit',
  216. 'direct_edit_timestamp',
  217. ['timestamp']
  218. );
  219. $event->addMissingIndex(
  220. 'preferences',
  221. 'preferences_app_key',
  222. ['appid', 'configkey']
  223. );
  224. $event->addMissingIndex(
  225. 'mounts',
  226. 'mounts_class_index',
  227. ['mount_provider_class']
  228. );
  229. $event->addMissingIndex(
  230. 'mounts',
  231. 'mounts_user_root_path_index',
  232. ['user_id', 'root_id', 'mount_point'],
  233. ['lengths' => [null, null, 128]]
  234. );
  235. $event->addMissingIndex(
  236. 'systemtag_object_mapping',
  237. 'systag_by_tagid',
  238. ['systemtagid', 'objecttype']
  239. );
  240. });
  241. $eventDispatcher->addListener(AddMissingPrimaryKeyEvent::class, function (AddMissingPrimaryKeyEvent $event) {
  242. $event->addMissingPrimaryKey(
  243. 'federated_reshares',
  244. 'federated_res_pk',
  245. ['share_id'],
  246. 'share_id_index'
  247. );
  248. $event->addMissingPrimaryKey(
  249. 'systemtag_object_mapping',
  250. 'som_pk',
  251. ['objecttype', 'objectid', 'systemtagid'],
  252. 'mapping'
  253. );
  254. $event->addMissingPrimaryKey(
  255. 'comments_read_markers',
  256. 'crm_pk',
  257. ['user_id', 'object_type', 'object_id'],
  258. 'comments_marker_index'
  259. );
  260. $event->addMissingPrimaryKey(
  261. 'collres_resources',
  262. 'crr_pk',
  263. ['collection_id', 'resource_type', 'resource_id'],
  264. 'collres_unique_res'
  265. );
  266. $event->addMissingPrimaryKey(
  267. 'collres_accesscache',
  268. 'cra_pk',
  269. ['user_id', 'collection_id', 'resource_type', 'resource_id'],
  270. 'collres_unique_user'
  271. );
  272. $event->addMissingPrimaryKey(
  273. 'filecache_extended',
  274. 'fce_pk',
  275. ['fileid'],
  276. 'fce_fileid_idx'
  277. );
  278. });
  279. $eventDispatcher->addListener(AddMissingColumnsEvent::class, function (AddMissingColumnsEvent $event) {
  280. $event->addMissingColumn(
  281. 'comments',
  282. 'reference_id',
  283. Types::STRING,
  284. [
  285. 'notnull' => false,
  286. 'length' => 64,
  287. ]
  288. );
  289. });
  290. $eventDispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
  291. $eventDispatcher->addServiceListener(BeforeLoginTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
  292. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  293. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  294. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  295. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  296. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  297. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  298. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
  299. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
  300. $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
  301. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
  302. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
  303. // Metadata
  304. /** @var IConfig $config */
  305. $config = $container->get(IConfig::class);
  306. if ($config->getSystemValueBool('enable_file_metadata', true)) {
  307. /** @psalm-suppress InvalidArgument */
  308. $eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileEventListener::class);
  309. /** @psalm-suppress InvalidArgument */
  310. $eventDispatcher->addServiceListener(NodeRemovedFromCache::class, FileEventListener::class);
  311. /** @psalm-suppress InvalidArgument */
  312. $eventDispatcher->addServiceListener(NodeWrittenEvent::class, FileEventListener::class);
  313. }
  314. // Tags
  315. $eventDispatcher->addServiceListener(UserDeletedEvent::class, TagManager::class);
  316. }
  317. }