Application.php 5.5 KB

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