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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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\Core\Notification\RemoveLinkSharesNotifier;
  30. use OC\DB\MissingIndexInformation;
  31. use OC\DB\SchemaWrapper;
  32. use OCP\AppFramework\App;
  33. use OCP\IDBConnection;
  34. use OCP\Util;
  35. use Symfony\Component\EventDispatcher\GenericEvent;
  36. /**
  37. * Class Application
  38. *
  39. * @package OC\Core
  40. */
  41. class Application extends App {
  42. public function __construct() {
  43. parent::__construct('core');
  44. $container = $this->getContainer();
  45. $container->registerService('defaultMailAddress', function () {
  46. return Util::getDefaultEmailAddress('lostpassword-noreply');
  47. });
  48. $server = $container->getServer();
  49. $eventDispatcher = $server->getEventDispatcher();
  50. $notificationManager = $server->getNotificationManager();
  51. $notificationManager->registerNotifier(function() use ($server) {
  52. return new RemoveLinkSharesNotifier(
  53. $server->getL10NFactory()
  54. );
  55. }, function() use ($server) {
  56. return [
  57. 'id' => 'core',
  58. 'name' => 'core',
  59. ];
  60. });
  61. $eventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
  62. function(GenericEvent $event) use ($container) {
  63. /** @var MissingIndexInformation $subject */
  64. $subject = $event->getSubject();
  65. $schema = new SchemaWrapper($container->query(IDBConnection::class));
  66. if ($schema->hasTable('share')) {
  67. $table = $schema->getTable('share');
  68. if (!$table->hasIndex('share_with_index')) {
  69. $subject->addHintForMissingSubject($table->getName(), 'share_with_index');
  70. }
  71. if (!$table->hasIndex('parent_index')) {
  72. $subject->addHintForMissingSubject($table->getName(), 'parent_index');
  73. }
  74. if (!$table->hasIndex('owner_index')) {
  75. $subject->addHintForMissingSubject($table->getName(), 'owner_index');
  76. }
  77. if (!$table->hasIndex('initiator_index')) {
  78. $subject->addHintForMissingSubject($table->getName(), 'initiator_index');
  79. }
  80. }
  81. if ($schema->hasTable('filecache')) {
  82. $table = $schema->getTable('filecache');
  83. if (!$table->hasIndex('fs_mtime')) {
  84. $subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
  85. }
  86. }
  87. if ($schema->hasTable('twofactor_providers')) {
  88. $table = $schema->getTable('twofactor_providers');
  89. if (!$table->hasIndex('twofactor_providers_uid')) {
  90. $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
  91. }
  92. }
  93. if ($schema->hasTable('login_flow_v2')) {
  94. $table = $schema->getTable('login_flow_v2');
  95. if (!$table->hasIndex('poll_token')) {
  96. $subject->addHintForMissingSubject($table->getName(), 'poll_token');
  97. }
  98. if (!$table->hasIndex('login_token')) {
  99. $subject->addHintForMissingSubject($table->getName(), 'login_token');
  100. }
  101. if (!$table->hasIndex('timestamp')) {
  102. $subject->addHintForMissingSubject($table->getName(), 'timestamp');
  103. }
  104. }
  105. if ($schema->hasTable('whats_new')) {
  106. $table = $schema->getTable('whats_new');
  107. if (!$table->hasIndex('version')) {
  108. $subject->addHintForMissingSubject($table->getName(), 'version');
  109. }
  110. }
  111. if ($schema->hasTable('cards')) {
  112. $table = $schema->getTable('cards');
  113. if (!$table->hasIndex('cards_abid')) {
  114. $subject->addHintForMissingSubject($table->getName(), 'cards_abid');
  115. }
  116. }
  117. if ($schema->hasTable('cards_properties')) {
  118. $table = $schema->getTable('cards_properties');
  119. if (!$table->hasIndex('cards_prop_abid')) {
  120. $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
  121. }
  122. }
  123. }
  124. );
  125. }
  126. }