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

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