Application.php 9.3 KB

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