You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Application.php 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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->registerNotifier(function () use ($server) {
  61. return new RemoveLinkSharesNotifier(
  62. $server->getL10NFactory()
  63. );
  64. }, function () {
  65. return [
  66. 'id' => 'core',
  67. 'name' => 'core',
  68. ];
  69. });
  70. $notificationManager->registerNotifier(function () use ($server) {
  71. return $server->query(AuthenticationNotifier::class);
  72. }, function () {
  73. return [
  74. 'id' => 'auth',
  75. 'name' => 'authentication notifier',
  76. ];
  77. });
  78. $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
  79. function (GenericEvent $event) use ($container) {
  80. /** @var MissingIndexInformation $subject */
  81. $subject = $event->getSubject();
  82. $schema = new SchemaWrapper($container->query(IDBConnection::class));
  83. if ($schema->hasTable('share')) {
  84. $table = $schema->getTable('share');
  85. if (!$table->hasIndex('share_with_index')) {
  86. $subject->addHintForMissingSubject($table->getName(), 'share_with_index');
  87. }
  88. if (!$table->hasIndex('parent_index')) {
  89. $subject->addHintForMissingSubject($table->getName(), 'parent_index');
  90. }
  91. if (!$table->hasIndex('owner_index')) {
  92. $subject->addHintForMissingSubject($table->getName(), 'owner_index');
  93. }
  94. if (!$table->hasIndex('initiator_index')) {
  95. $subject->addHintForMissingSubject($table->getName(), 'initiator_index');
  96. }
  97. }
  98. if ($schema->hasTable('filecache')) {
  99. $table = $schema->getTable('filecache');
  100. if (!$table->hasIndex('fs_mtime')) {
  101. $subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
  102. }
  103. }
  104. if ($schema->hasTable('twofactor_providers')) {
  105. $table = $schema->getTable('twofactor_providers');
  106. if (!$table->hasIndex('twofactor_providers_uid')) {
  107. $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
  108. }
  109. }
  110. if ($schema->hasTable('login_flow_v2')) {
  111. $table = $schema->getTable('login_flow_v2');
  112. if (!$table->hasIndex('poll_token')) {
  113. $subject->addHintForMissingSubject($table->getName(), 'poll_token');
  114. }
  115. if (!$table->hasIndex('login_token')) {
  116. $subject->addHintForMissingSubject($table->getName(), 'login_token');
  117. }
  118. if (!$table->hasIndex('timestamp')) {
  119. $subject->addHintForMissingSubject($table->getName(), 'timestamp');
  120. }
  121. }
  122. if ($schema->hasTable('whats_new')) {
  123. $table = $schema->getTable('whats_new');
  124. if (!$table->hasIndex('version')) {
  125. $subject->addHintForMissingSubject($table->getName(), 'version');
  126. }
  127. }
  128. if ($schema->hasTable('cards')) {
  129. $table = $schema->getTable('cards');
  130. if (!$table->hasIndex('cards_abid')) {
  131. $subject->addHintForMissingSubject($table->getName(), 'cards_abid');
  132. }
  133. }
  134. if ($schema->hasTable('cards_properties')) {
  135. $table = $schema->getTable('cards_properties');
  136. if (!$table->hasIndex('cards_prop_abid')) {
  137. $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
  138. }
  139. }
  140. }
  141. );
  142. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  143. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  144. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  145. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  146. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  147. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  148. }
  149. }