Application.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 Lukas Reschke <lukas@statuscode.ch>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Citharel <nextcloud@tcit.fr>
  13. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OC\Core;
  31. use OC\Authentication\Events\RemoteWipeFinished;
  32. use OC\Authentication\Events\RemoteWipeStarted;
  33. use OC\Authentication\Listeners\RemoteWipeActivityListener;
  34. use OC\Authentication\Listeners\RemoteWipeEmailListener;
  35. use OC\Authentication\Listeners\RemoteWipeNotificationsListener;
  36. use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
  37. use OC\Authentication\Listeners\UserDeletedTokenCleanupListener;
  38. use OC\Authentication\Listeners\UserDeletedWebAuthnCleanupListener;
  39. use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
  40. use OC\Core\Notification\RemoveLinkSharesNotifier;
  41. use OC\DB\MissingColumnInformation;
  42. use OC\DB\MissingIndexInformation;
  43. use OC\DB\SchemaWrapper;
  44. use OCP\AppFramework\App;
  45. use OCP\EventDispatcher\IEventDispatcher;
  46. use OCP\IDBConnection;
  47. use OCP\User\Events\UserDeletedEvent;
  48. use OCP\Util;
  49. use Symfony\Component\EventDispatcher\GenericEvent;
  50. /**
  51. * Class Application
  52. *
  53. * @package OC\Core
  54. */
  55. class Application extends App {
  56. public function __construct() {
  57. parent::__construct('core');
  58. $container = $this->getContainer();
  59. $container->registerService('defaultMailAddress', function () {
  60. return Util::getDefaultEmailAddress('lostpassword-noreply');
  61. });
  62. $server = $container->getServer();
  63. /** @var IEventDispatcher $eventDispatcher */
  64. $eventDispatcher = $server->query(IEventDispatcher::class);
  65. $notificationManager = $server->getNotificationManager();
  66. $notificationManager->registerNotifierService(RemoveLinkSharesNotifier::class);
  67. $notificationManager->registerNotifierService(AuthenticationNotifier::class);
  68. $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
  69. function (GenericEvent $event) use ($container) {
  70. /** @var MissingIndexInformation $subject */
  71. $subject = $event->getSubject();
  72. $schema = new SchemaWrapper($container->query(IDBConnection::class));
  73. if ($schema->hasTable('share')) {
  74. $table = $schema->getTable('share');
  75. if (!$table->hasIndex('share_with_index')) {
  76. $subject->addHintForMissingSubject($table->getName(), 'share_with_index');
  77. }
  78. if (!$table->hasIndex('parent_index')) {
  79. $subject->addHintForMissingSubject($table->getName(), 'parent_index');
  80. }
  81. if (!$table->hasIndex('owner_index')) {
  82. $subject->addHintForMissingSubject($table->getName(), 'owner_index');
  83. }
  84. if (!$table->hasIndex('initiator_index')) {
  85. $subject->addHintForMissingSubject($table->getName(), 'initiator_index');
  86. }
  87. }
  88. if ($schema->hasTable('filecache')) {
  89. $table = $schema->getTable('filecache');
  90. if (!$table->hasIndex('fs_mtime')) {
  91. $subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
  92. }
  93. }
  94. if ($schema->hasTable('twofactor_providers')) {
  95. $table = $schema->getTable('twofactor_providers');
  96. if (!$table->hasIndex('twofactor_providers_uid')) {
  97. $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
  98. }
  99. }
  100. if ($schema->hasTable('login_flow_v2')) {
  101. $table = $schema->getTable('login_flow_v2');
  102. if (!$table->hasIndex('poll_token')) {
  103. $subject->addHintForMissingSubject($table->getName(), 'poll_token');
  104. }
  105. if (!$table->hasIndex('login_token')) {
  106. $subject->addHintForMissingSubject($table->getName(), 'login_token');
  107. }
  108. if (!$table->hasIndex('timestamp')) {
  109. $subject->addHintForMissingSubject($table->getName(), 'timestamp');
  110. }
  111. }
  112. if ($schema->hasTable('whats_new')) {
  113. $table = $schema->getTable('whats_new');
  114. if (!$table->hasIndex('version')) {
  115. $subject->addHintForMissingSubject($table->getName(), 'version');
  116. }
  117. }
  118. if ($schema->hasTable('cards')) {
  119. $table = $schema->getTable('cards');
  120. if (!$table->hasIndex('cards_abid')) {
  121. $subject->addHintForMissingSubject($table->getName(), 'cards_abid');
  122. }
  123. }
  124. if ($schema->hasTable('cards_properties')) {
  125. $table = $schema->getTable('cards_properties');
  126. if (!$table->hasIndex('cards_prop_abid')) {
  127. $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
  128. }
  129. }
  130. if ($schema->hasTable('calendarobjects_props')) {
  131. $table = $schema->getTable('calendarobjects_props');
  132. if (!$table->hasIndex('calendarobject_calid_index')) {
  133. $subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index');
  134. }
  135. }
  136. if ($schema->hasTable('schedulingobjects')) {
  137. $table = $schema->getTable('schedulingobjects');
  138. if (!$table->hasIndex('schedulobj_principuri_index')) {
  139. $subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index');
  140. }
  141. }
  142. if ($schema->hasTable('properties')) {
  143. $table = $schema->getTable('properties');
  144. if (!$table->hasIndex('properties_path_index')) {
  145. $subject->addHintForMissingSubject($table->getName(), 'properties_path_index');
  146. }
  147. }
  148. }
  149. );
  150. $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
  151. function (GenericEvent $event) use ($container) {
  152. /** @var MissingColumnInformation $subject */
  153. $subject = $event->getSubject();
  154. $schema = new SchemaWrapper($container->query(IDBConnection::class));
  155. if ($schema->hasTable('comments')) {
  156. $table = $schema->getTable('comments');
  157. if (!$table->hasColumn('reference_id')) {
  158. $subject->addHintForMissingColumn($table->getName(), 'reference_id');
  159. }
  160. }
  161. }
  162. );
  163. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  164. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  165. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  166. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  167. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  168. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  169. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
  170. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
  171. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
  172. }
  173. }