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 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 <nextcloud@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\Notifications\Notifier as AuthenticationNotifier;
  39. use OC\Core\Notification\RemoveLinkSharesNotifier;
  40. use OC\DB\MissingColumnInformation;
  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\User\Events\UserDeletedEvent;
  47. use OCP\Util;
  48. use Symfony\Component\EventDispatcher\GenericEvent;
  49. /**
  50. * Class Application
  51. *
  52. * @package OC\Core
  53. */
  54. class Application extends App {
  55. public function __construct() {
  56. parent::__construct('core');
  57. $container = $this->getContainer();
  58. $container->registerService('defaultMailAddress', function () {
  59. return Util::getDefaultEmailAddress('lostpassword-noreply');
  60. });
  61. $server = $container->getServer();
  62. /** @var IEventDispatcher $eventDispatcher */
  63. $eventDispatcher = $server->query(IEventDispatcher::class);
  64. $notificationManager = $server->getNotificationManager();
  65. $notificationManager->registerNotifierService(RemoveLinkSharesNotifier::class);
  66. $notificationManager->registerNotifierService(AuthenticationNotifier::class);
  67. $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
  68. function (GenericEvent $event) use ($container) {
  69. /** @var MissingIndexInformation $subject */
  70. $subject = $event->getSubject();
  71. $schema = new SchemaWrapper($container->query(IDBConnection::class));
  72. if ($schema->hasTable('share')) {
  73. $table = $schema->getTable('share');
  74. if (!$table->hasIndex('share_with_index')) {
  75. $subject->addHintForMissingSubject($table->getName(), 'share_with_index');
  76. }
  77. if (!$table->hasIndex('parent_index')) {
  78. $subject->addHintForMissingSubject($table->getName(), 'parent_index');
  79. }
  80. if (!$table->hasIndex('owner_index')) {
  81. $subject->addHintForMissingSubject($table->getName(), 'owner_index');
  82. }
  83. if (!$table->hasIndex('initiator_index')) {
  84. $subject->addHintForMissingSubject($table->getName(), 'initiator_index');
  85. }
  86. }
  87. if ($schema->hasTable('filecache')) {
  88. $table = $schema->getTable('filecache');
  89. if (!$table->hasIndex('fs_mtime')) {
  90. $subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
  91. }
  92. }
  93. if ($schema->hasTable('twofactor_providers')) {
  94. $table = $schema->getTable('twofactor_providers');
  95. if (!$table->hasIndex('twofactor_providers_uid')) {
  96. $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
  97. }
  98. }
  99. if ($schema->hasTable('login_flow_v2')) {
  100. $table = $schema->getTable('login_flow_v2');
  101. if (!$table->hasIndex('poll_token')) {
  102. $subject->addHintForMissingSubject($table->getName(), 'poll_token');
  103. }
  104. if (!$table->hasIndex('login_token')) {
  105. $subject->addHintForMissingSubject($table->getName(), 'login_token');
  106. }
  107. if (!$table->hasIndex('timestamp')) {
  108. $subject->addHintForMissingSubject($table->getName(), 'timestamp');
  109. }
  110. }
  111. if ($schema->hasTable('whats_new')) {
  112. $table = $schema->getTable('whats_new');
  113. if (!$table->hasIndex('version')) {
  114. $subject->addHintForMissingSubject($table->getName(), 'version');
  115. }
  116. }
  117. if ($schema->hasTable('cards')) {
  118. $table = $schema->getTable('cards');
  119. if (!$table->hasIndex('cards_abid')) {
  120. $subject->addHintForMissingSubject($table->getName(), 'cards_abid');
  121. }
  122. }
  123. if ($schema->hasTable('cards_properties')) {
  124. $table = $schema->getTable('cards_properties');
  125. if (!$table->hasIndex('cards_prop_abid')) {
  126. $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
  127. }
  128. }
  129. if ($schema->hasTable('calendarobjects_props')) {
  130. $table = $schema->getTable('calendarobjects_props');
  131. if (!$table->hasIndex('calendarobject_calid_index')) {
  132. $subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index');
  133. }
  134. }
  135. if ($schema->hasTable('schedulingobjects')) {
  136. $table = $schema->getTable('schedulingobjects');
  137. if (!$table->hasIndex('schedulobj_principuri_index')) {
  138. $subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index');
  139. }
  140. }
  141. }
  142. );
  143. $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
  144. function (GenericEvent $event) use ($container) {
  145. /** @var MissingColumnInformation $subject */
  146. $subject = $event->getSubject();
  147. $schema = new SchemaWrapper($container->query(IDBConnection::class));
  148. if ($schema->hasTable('comments')) {
  149. $table = $schema->getTable('comments');
  150. if (!$table->hasColumn('reference_id')) {
  151. $subject->addHintForMissingColumn($table->getName(), 'reference_id');
  152. }
  153. }
  154. }
  155. );
  156. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  157. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  158. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  159. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  160. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  161. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  162. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
  163. }
  164. }