Application.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
  5. *
  6. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  7. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. * @author Thomas Citharel <tcit@tcit.fr>
  14. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  15. *
  16. * @license AGPL-3.0
  17. *
  18. * This code is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License, version 3,
  20. * as published by the Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License, version 3,
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>
  29. *
  30. */
  31. namespace OC\Core;
  32. use OC\Authentication\Events\RemoteWipeFinished;
  33. use OC\Authentication\Events\RemoteWipeStarted;
  34. use OC\Authentication\Listeners\RemoteWipeActivityListener;
  35. use OC\Authentication\Listeners\RemoteWipeEmailListener;
  36. use OC\Authentication\Listeners\RemoteWipeNotificationsListener;
  37. use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
  38. use OC\Authentication\Listeners\UserDeletedTokenCleanupListener;
  39. use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
  40. use OC\Core\Notification\RemoveLinkSharesNotifier;
  41. use OC\DB\MissingIndexInformation;
  42. use OC\DB\SchemaWrapper;
  43. use OCP\AppFramework\App;
  44. use OCP\EventDispatcher\IEventDispatcher;
  45. use OCP\IDBConnection;
  46. use OCP\IServerContainer;
  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. }
  143. );
  144. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  145. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  146. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  147. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  148. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  149. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  150. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
  151. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
  152. }
  153. }