Application.php 9.4 KB

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