Application.php 7.1 KB

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