Application.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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\CoreNotifier;
  41. use OC\DB\MissingColumnInformation;
  42. use OC\DB\MissingIndexInformation;
  43. use OC\DB\MissingPrimaryKeyInformation;
  44. use OC\DB\SchemaWrapper;
  45. use OCP\AppFramework\App;
  46. use OCP\EventDispatcher\IEventDispatcher;
  47. use OCP\IDBConnection;
  48. use OCP\User\Events\UserDeletedEvent;
  49. use OCP\Util;
  50. use Symfony\Component\EventDispatcher\GenericEvent;
  51. /**
  52. * Class Application
  53. *
  54. * @package OC\Core
  55. */
  56. class Application extends App {
  57. public function __construct() {
  58. parent::__construct('core');
  59. $container = $this->getContainer();
  60. $container->registerService('defaultMailAddress', function () {
  61. return Util::getDefaultEmailAddress('lostpassword-noreply');
  62. });
  63. $server = $container->getServer();
  64. /** @var IEventDispatcher $eventDispatcher */
  65. $eventDispatcher = $server->query(IEventDispatcher::class);
  66. $notificationManager = $server->getNotificationManager();
  67. $notificationManager->registerNotifierService(CoreNotifier::class);
  68. $notificationManager->registerNotifierService(AuthenticationNotifier::class);
  69. $oldEventDispatcher = $server->getEventDispatcher();
  70. $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
  71. function (GenericEvent $event) use ($container) {
  72. /** @var MissingIndexInformation $subject */
  73. $subject = $event->getSubject();
  74. $schema = new SchemaWrapper($container->query(IDBConnection::class));
  75. if ($schema->hasTable('share')) {
  76. $table = $schema->getTable('share');
  77. if (!$table->hasIndex('share_with_index')) {
  78. $subject->addHintForMissingSubject($table->getName(), 'share_with_index');
  79. }
  80. if (!$table->hasIndex('parent_index')) {
  81. $subject->addHintForMissingSubject($table->getName(), 'parent_index');
  82. }
  83. if (!$table->hasIndex('owner_index')) {
  84. $subject->addHintForMissingSubject($table->getName(), 'owner_index');
  85. }
  86. if (!$table->hasIndex('initiator_index')) {
  87. $subject->addHintForMissingSubject($table->getName(), 'initiator_index');
  88. }
  89. }
  90. if ($schema->hasTable('filecache')) {
  91. $table = $schema->getTable('filecache');
  92. if (!$table->hasIndex('fs_mtime')) {
  93. $subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
  94. }
  95. if (!$table->hasIndex('fs_size')) {
  96. $subject->addHintForMissingSubject($table->getName(), 'fs_size');
  97. }
  98. }
  99. if ($schema->hasTable('twofactor_providers')) {
  100. $table = $schema->getTable('twofactor_providers');
  101. if (!$table->hasIndex('twofactor_providers_uid')) {
  102. $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
  103. }
  104. }
  105. if ($schema->hasTable('login_flow_v2')) {
  106. $table = $schema->getTable('login_flow_v2');
  107. if (!$table->hasIndex('poll_token')) {
  108. $subject->addHintForMissingSubject($table->getName(), 'poll_token');
  109. }
  110. if (!$table->hasIndex('login_token')) {
  111. $subject->addHintForMissingSubject($table->getName(), 'login_token');
  112. }
  113. if (!$table->hasIndex('timestamp')) {
  114. $subject->addHintForMissingSubject($table->getName(), 'timestamp');
  115. }
  116. }
  117. if ($schema->hasTable('whats_new')) {
  118. $table = $schema->getTable('whats_new');
  119. if (!$table->hasIndex('version')) {
  120. $subject->addHintForMissingSubject($table->getName(), 'version');
  121. }
  122. }
  123. if ($schema->hasTable('cards')) {
  124. $table = $schema->getTable('cards');
  125. if (!$table->hasIndex('cards_abid')) {
  126. $subject->addHintForMissingSubject($table->getName(), 'cards_abid');
  127. }
  128. }
  129. if ($schema->hasTable('cards_properties')) {
  130. $table = $schema->getTable('cards_properties');
  131. if (!$table->hasIndex('cards_prop_abid')) {
  132. $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
  133. }
  134. }
  135. if ($schema->hasTable('calendarobjects_props')) {
  136. $table = $schema->getTable('calendarobjects_props');
  137. if (!$table->hasIndex('calendarobject_calid_index')) {
  138. $subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index');
  139. }
  140. }
  141. if ($schema->hasTable('schedulingobjects')) {
  142. $table = $schema->getTable('schedulingobjects');
  143. if (!$table->hasIndex('schedulobj_principuri_index')) {
  144. $subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index');
  145. }
  146. }
  147. if ($schema->hasTable('properties')) {
  148. $table = $schema->getTable('properties');
  149. if (!$table->hasIndex('properties_path_index')) {
  150. $subject->addHintForMissingSubject($table->getName(), 'properties_path_index');
  151. }
  152. }
  153. }
  154. );
  155. $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT,
  156. function (GenericEvent $event) use ($container) {
  157. /** @var MissingPrimaryKeyInformation $subject */
  158. $subject = $event->getSubject();
  159. $schema = new SchemaWrapper($container->query(IDBConnection::class));
  160. if ($schema->hasTable('federated_reshares')) {
  161. $table = $schema->getTable('federated_reshares');
  162. if (!$table->hasPrimaryKey()) {
  163. $subject->addHintForMissingSubject($table->getName());
  164. }
  165. }
  166. if ($schema->hasTable('systemtag_object_mapping')) {
  167. $table = $schema->getTable('systemtag_object_mapping');
  168. if (!$table->hasPrimaryKey()) {
  169. $subject->addHintForMissingSubject($table->getName());
  170. }
  171. }
  172. if ($schema->hasTable('comments_read_markers')) {
  173. $table = $schema->getTable('comments_read_markers');
  174. if (!$table->hasPrimaryKey()) {
  175. $subject->addHintForMissingSubject($table->getName());
  176. }
  177. }
  178. if ($schema->hasTable('collres_resources')) {
  179. $table = $schema->getTable('collres_resources');
  180. if (!$table->hasPrimaryKey()) {
  181. $subject->addHintForMissingSubject($table->getName());
  182. }
  183. }
  184. if ($schema->hasTable('collres_accesscache')) {
  185. $table = $schema->getTable('collres_accesscache');
  186. if (!$table->hasPrimaryKey()) {
  187. $subject->addHintForMissingSubject($table->getName());
  188. }
  189. }
  190. if ($schema->hasTable('filecache_extended')) {
  191. $table = $schema->getTable('filecache_extended');
  192. if (!$table->hasPrimaryKey()) {
  193. $subject->addHintForMissingSubject($table->getName());
  194. }
  195. }
  196. }
  197. );
  198. $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
  199. function (GenericEvent $event) use ($container) {
  200. /** @var MissingColumnInformation $subject */
  201. $subject = $event->getSubject();
  202. $schema = new SchemaWrapper($container->query(IDBConnection::class));
  203. if ($schema->hasTable('comments')) {
  204. $table = $schema->getTable('comments');
  205. if (!$table->hasColumn('reference_id')) {
  206. $subject->addHintForMissingColumn($table->getName(), 'reference_id');
  207. }
  208. }
  209. }
  210. );
  211. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  212. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  213. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  214. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  215. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  216. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  217. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
  218. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
  219. }
  220. }