Application.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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\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. if ($schema->hasTable('properties')) {
  142. $table = $schema->getTable('properties');
  143. if (!$table->hasIndex('properties_path_index')) {
  144. $subject->addHintForMissingSubject($table->getName(), 'properties_path_index');
  145. }
  146. }
  147. }
  148. );
  149. $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
  150. function (GenericEvent $event) use ($container) {
  151. /** @var MissingColumnInformation $subject */
  152. $subject = $event->getSubject();
  153. $schema = new SchemaWrapper($container->query(IDBConnection::class));
  154. if ($schema->hasTable('comments')) {
  155. $table = $schema->getTable('comments');
  156. if (!$table->hasColumn('reference_id')) {
  157. $subject->addHintForMissingColumn($table->getName(), 'reference_id');
  158. }
  159. }
  160. }
  161. );
  162. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  163. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  164. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  165. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  166. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  167. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  168. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
  169. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
  170. }
  171. }