Application.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 Julius Härtl <jus@bitgrid.net>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Mario Danic <mario@lovelyhq.com>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin Appelman <robin@icewind.nl>
  13. * @author Roeland Jago Douma <roeland@famdouma.nl>
  14. * @author Thomas Citharel <nextcloud@tcit.fr>
  15. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  16. *
  17. * @license AGPL-3.0
  18. *
  19. * This code is free software: you can redistribute it and/or modify
  20. * it under the terms of the GNU Affero General Public License, version 3,
  21. * as published by the Free Software Foundation.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU Affero General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Affero General Public License, version 3,
  29. * along with this program. If not, see <http://www.gnu.org/licenses/>
  30. *
  31. */
  32. namespace OC\Core;
  33. use OC\Authentication\Events\RemoteWipeFinished;
  34. use OC\Authentication\Events\RemoteWipeStarted;
  35. use OC\Authentication\Listeners\RemoteWipeActivityListener;
  36. use OC\Authentication\Listeners\RemoteWipeEmailListener;
  37. use OC\Authentication\Listeners\RemoteWipeNotificationsListener;
  38. use OC\Authentication\Listeners\UserDeletedFilesCleanupListener;
  39. use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
  40. use OC\Authentication\Listeners\UserDeletedTokenCleanupListener;
  41. use OC\Authentication\Listeners\UserDeletedWebAuthnCleanupListener;
  42. use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
  43. use OC\Core\Notification\CoreNotifier;
  44. use OC\DB\Connection;
  45. use OC\DB\MissingColumnInformation;
  46. use OC\DB\MissingIndexInformation;
  47. use OC\DB\MissingPrimaryKeyInformation;
  48. use OC\DB\SchemaWrapper;
  49. use OCP\AppFramework\App;
  50. use OCP\EventDispatcher\IEventDispatcher;
  51. use OCP\IDBConnection;
  52. use OCP\User\Events\BeforeUserDeletedEvent;
  53. use OCP\User\Events\UserDeletedEvent;
  54. use OCP\Util;
  55. use Symfony\Component\EventDispatcher\GenericEvent;
  56. /**
  57. * Class Application
  58. *
  59. * @package OC\Core
  60. */
  61. class Application extends App {
  62. public function __construct() {
  63. parent::__construct('core');
  64. $container = $this->getContainer();
  65. $container->registerService('defaultMailAddress', function () {
  66. return Util::getDefaultEmailAddress('lostpassword-noreply');
  67. });
  68. $server = $container->getServer();
  69. /** @var IEventDispatcher $eventDispatcher */
  70. $eventDispatcher = $server->query(IEventDispatcher::class);
  71. $notificationManager = $server->getNotificationManager();
  72. $notificationManager->registerNotifierService(CoreNotifier::class);
  73. $notificationManager->registerNotifierService(AuthenticationNotifier::class);
  74. $oldEventDispatcher = $server->getEventDispatcher();
  75. $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
  76. function (GenericEvent $event) use ($container) {
  77. /** @var MissingIndexInformation $subject */
  78. $subject = $event->getSubject();
  79. $schema = new SchemaWrapper($container->query(Connection::class));
  80. if ($schema->hasTable('share')) {
  81. $table = $schema->getTable('share');
  82. if (!$table->hasIndex('share_with_index')) {
  83. $subject->addHintForMissingSubject($table->getName(), 'share_with_index');
  84. }
  85. if (!$table->hasIndex('parent_index')) {
  86. $subject->addHintForMissingSubject($table->getName(), 'parent_index');
  87. }
  88. if (!$table->hasIndex('owner_index')) {
  89. $subject->addHintForMissingSubject($table->getName(), 'owner_index');
  90. }
  91. if (!$table->hasIndex('initiator_index')) {
  92. $subject->addHintForMissingSubject($table->getName(), 'initiator_index');
  93. }
  94. }
  95. if ($schema->hasTable('filecache')) {
  96. $table = $schema->getTable('filecache');
  97. if (!$table->hasIndex('fs_mtime')) {
  98. $subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
  99. }
  100. if (!$table->hasIndex('fs_size')) {
  101. $subject->addHintForMissingSubject($table->getName(), 'fs_size');
  102. }
  103. }
  104. if ($schema->hasTable('twofactor_providers')) {
  105. $table = $schema->getTable('twofactor_providers');
  106. if (!$table->hasIndex('twofactor_providers_uid')) {
  107. $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
  108. }
  109. }
  110. if ($schema->hasTable('login_flow_v2')) {
  111. $table = $schema->getTable('login_flow_v2');
  112. if (!$table->hasIndex('poll_token')) {
  113. $subject->addHintForMissingSubject($table->getName(), 'poll_token');
  114. }
  115. if (!$table->hasIndex('login_token')) {
  116. $subject->addHintForMissingSubject($table->getName(), 'login_token');
  117. }
  118. if (!$table->hasIndex('timestamp')) {
  119. $subject->addHintForMissingSubject($table->getName(), 'timestamp');
  120. }
  121. }
  122. if ($schema->hasTable('whats_new')) {
  123. $table = $schema->getTable('whats_new');
  124. if (!$table->hasIndex('version')) {
  125. $subject->addHintForMissingSubject($table->getName(), 'version');
  126. }
  127. }
  128. if ($schema->hasTable('cards')) {
  129. $table = $schema->getTable('cards');
  130. if (!$table->hasIndex('cards_abid')) {
  131. $subject->addHintForMissingSubject($table->getName(), 'cards_abid');
  132. }
  133. if (!$table->hasIndex('cards_abiduri')) {
  134. $subject->addHintForMissingSubject($table->getName(), 'cards_abiduri');
  135. }
  136. }
  137. if ($schema->hasTable('cards_properties')) {
  138. $table = $schema->getTable('cards_properties');
  139. if (!$table->hasIndex('cards_prop_abid')) {
  140. $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
  141. }
  142. }
  143. if ($schema->hasTable('calendarobjects_props')) {
  144. $table = $schema->getTable('calendarobjects_props');
  145. if (!$table->hasIndex('calendarobject_calid_index')) {
  146. $subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index');
  147. }
  148. }
  149. if ($schema->hasTable('schedulingobjects')) {
  150. $table = $schema->getTable('schedulingobjects');
  151. if (!$table->hasIndex('schedulobj_principuri_index')) {
  152. $subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index');
  153. }
  154. }
  155. if ($schema->hasTable('properties')) {
  156. $table = $schema->getTable('properties');
  157. if (!$table->hasIndex('properties_path_index')) {
  158. $subject->addHintForMissingSubject($table->getName(), 'properties_path_index');
  159. }
  160. }
  161. }
  162. );
  163. $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT,
  164. function (GenericEvent $event) use ($container) {
  165. /** @var MissingPrimaryKeyInformation $subject */
  166. $subject = $event->getSubject();
  167. $schema = new SchemaWrapper($container->query(Connection::class));
  168. if ($schema->hasTable('federated_reshares')) {
  169. $table = $schema->getTable('federated_reshares');
  170. if (!$table->hasPrimaryKey()) {
  171. $subject->addHintForMissingSubject($table->getName());
  172. }
  173. }
  174. if ($schema->hasTable('systemtag_object_mapping')) {
  175. $table = $schema->getTable('systemtag_object_mapping');
  176. if (!$table->hasPrimaryKey()) {
  177. $subject->addHintForMissingSubject($table->getName());
  178. }
  179. }
  180. if ($schema->hasTable('comments_read_markers')) {
  181. $table = $schema->getTable('comments_read_markers');
  182. if (!$table->hasPrimaryKey()) {
  183. $subject->addHintForMissingSubject($table->getName());
  184. }
  185. }
  186. if ($schema->hasTable('collres_resources')) {
  187. $table = $schema->getTable('collres_resources');
  188. if (!$table->hasPrimaryKey()) {
  189. $subject->addHintForMissingSubject($table->getName());
  190. }
  191. }
  192. if ($schema->hasTable('collres_accesscache')) {
  193. $table = $schema->getTable('collres_accesscache');
  194. if (!$table->hasPrimaryKey()) {
  195. $subject->addHintForMissingSubject($table->getName());
  196. }
  197. }
  198. if ($schema->hasTable('filecache_extended')) {
  199. $table = $schema->getTable('filecache_extended');
  200. if (!$table->hasPrimaryKey()) {
  201. $subject->addHintForMissingSubject($table->getName());
  202. }
  203. }
  204. }
  205. );
  206. $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
  207. function (GenericEvent $event) use ($container) {
  208. /** @var MissingColumnInformation $subject */
  209. $subject = $event->getSubject();
  210. $schema = new SchemaWrapper($container->query(Connection::class));
  211. if ($schema->hasTable('comments')) {
  212. $table = $schema->getTable('comments');
  213. if (!$table->hasColumn('reference_id')) {
  214. $subject->addHintForMissingColumn($table->getName(), 'reference_id');
  215. }
  216. }
  217. }
  218. );
  219. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  220. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  221. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  222. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  223. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  224. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  225. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
  226. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
  227. $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
  228. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
  229. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
  230. }
  231. }