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

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