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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 Doctrine\DBAL\Platforms\PostgreSQL94Platform;
  34. use OC\Authentication\Events\RemoteWipeFinished;
  35. use OC\Authentication\Events\RemoteWipeStarted;
  36. use OC\Authentication\Listeners\RemoteWipeActivityListener;
  37. use OC\Authentication\Listeners\RemoteWipeEmailListener;
  38. use OC\Authentication\Listeners\RemoteWipeNotificationsListener;
  39. use OC\Authentication\Listeners\UserDeletedFilesCleanupListener;
  40. use OC\Authentication\Listeners\UserDeletedStoreCleanupListener;
  41. use OC\Authentication\Listeners\UserDeletedTokenCleanupListener;
  42. use OC\Authentication\Listeners\UserDeletedWebAuthnCleanupListener;
  43. use OC\Authentication\Notifications\Notifier as AuthenticationNotifier;
  44. use OC\Core\Notification\CoreNotifier;
  45. use OC\DB\Connection;
  46. use OC\DB\MissingColumnInformation;
  47. use OC\DB\MissingIndexInformation;
  48. use OC\DB\MissingPrimaryKeyInformation;
  49. use OC\DB\SchemaWrapper;
  50. use OC\Metadata\FileEventListener;
  51. use OC\TagManager;
  52. use OCP\AppFramework\App;
  53. use OCP\EventDispatcher\IEventDispatcher;
  54. use OCP\Files\Events\Node\NodeDeletedEvent;
  55. use OCP\Files\Events\Node\NodeWrittenEvent;
  56. use OCP\Files\Events\NodeRemovedFromCache;
  57. use OCP\IDBConnection;
  58. use OCP\User\Events\BeforeUserDeletedEvent;
  59. use OCP\User\Events\UserDeletedEvent;
  60. use OCP\Util;
  61. use OCP\IConfig;
  62. use Symfony\Component\EventDispatcher\GenericEvent;
  63. /**
  64. * Class Application
  65. *
  66. * @package OC\Core
  67. */
  68. class Application extends App {
  69. public function __construct() {
  70. parent::__construct('core');
  71. $container = $this->getContainer();
  72. $container->registerService('defaultMailAddress', function () {
  73. return Util::getDefaultEmailAddress('lostpassword-noreply');
  74. });
  75. $server = $container->getServer();
  76. /** @var IEventDispatcher $eventDispatcher */
  77. $eventDispatcher = $server->get(IEventDispatcher::class);
  78. $notificationManager = $server->getNotificationManager();
  79. $notificationManager->registerNotifierService(CoreNotifier::class);
  80. $notificationManager->registerNotifierService(AuthenticationNotifier::class);
  81. $oldEventDispatcher = $server->getEventDispatcher();
  82. $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_INDEXES_EVENT,
  83. function (GenericEvent $event) use ($container) {
  84. /** @var MissingIndexInformation $subject */
  85. $subject = $event->getSubject();
  86. $schema = new SchemaWrapper($container->query(Connection::class));
  87. if ($schema->hasTable('share')) {
  88. $table = $schema->getTable('share');
  89. if (!$table->hasIndex('share_with_index')) {
  90. $subject->addHintForMissingSubject($table->getName(), 'share_with_index');
  91. }
  92. if (!$table->hasIndex('parent_index')) {
  93. $subject->addHintForMissingSubject($table->getName(), 'parent_index');
  94. }
  95. if (!$table->hasIndex('owner_index')) {
  96. $subject->addHintForMissingSubject($table->getName(), 'owner_index');
  97. }
  98. if (!$table->hasIndex('initiator_index')) {
  99. $subject->addHintForMissingSubject($table->getName(), 'initiator_index');
  100. }
  101. }
  102. if ($schema->hasTable('filecache')) {
  103. $table = $schema->getTable('filecache');
  104. if (!$table->hasIndex('fs_mtime')) {
  105. $subject->addHintForMissingSubject($table->getName(), 'fs_mtime');
  106. }
  107. if (!$table->hasIndex('fs_size')) {
  108. $subject->addHintForMissingSubject($table->getName(), 'fs_size');
  109. }
  110. if (!$table->hasIndex('fs_id_storage_size')) {
  111. $subject->addHintForMissingSubject($table->getName(), 'fs_id_storage_size');
  112. }
  113. if (!$table->hasIndex('fs_storage_path_prefix') && !$schema->getDatabasePlatform() instanceof PostgreSQL94Platform) {
  114. $subject->addHintForMissingSubject($table->getName(), 'fs_storage_path_prefix');
  115. }
  116. }
  117. if ($schema->hasTable('twofactor_providers')) {
  118. $table = $schema->getTable('twofactor_providers');
  119. if (!$table->hasIndex('twofactor_providers_uid')) {
  120. $subject->addHintForMissingSubject($table->getName(), 'twofactor_providers_uid');
  121. }
  122. }
  123. if ($schema->hasTable('login_flow_v2')) {
  124. $table = $schema->getTable('login_flow_v2');
  125. if (!$table->hasIndex('poll_token')) {
  126. $subject->addHintForMissingSubject($table->getName(), 'poll_token');
  127. }
  128. if (!$table->hasIndex('login_token')) {
  129. $subject->addHintForMissingSubject($table->getName(), 'login_token');
  130. }
  131. if (!$table->hasIndex('timestamp')) {
  132. $subject->addHintForMissingSubject($table->getName(), 'timestamp');
  133. }
  134. }
  135. if ($schema->hasTable('whats_new')) {
  136. $table = $schema->getTable('whats_new');
  137. if (!$table->hasIndex('version')) {
  138. $subject->addHintForMissingSubject($table->getName(), 'version');
  139. }
  140. }
  141. if ($schema->hasTable('cards')) {
  142. $table = $schema->getTable('cards');
  143. if (!$table->hasIndex('cards_abid')) {
  144. $subject->addHintForMissingSubject($table->getName(), 'cards_abid');
  145. }
  146. if (!$table->hasIndex('cards_abiduri')) {
  147. $subject->addHintForMissingSubject($table->getName(), 'cards_abiduri');
  148. }
  149. }
  150. if ($schema->hasTable('cards_properties')) {
  151. $table = $schema->getTable('cards_properties');
  152. if (!$table->hasIndex('cards_prop_abid')) {
  153. $subject->addHintForMissingSubject($table->getName(), 'cards_prop_abid');
  154. }
  155. }
  156. if ($schema->hasTable('calendarobjects_props')) {
  157. $table = $schema->getTable('calendarobjects_props');
  158. if (!$table->hasIndex('calendarobject_calid_index')) {
  159. $subject->addHintForMissingSubject($table->getName(), 'calendarobject_calid_index');
  160. }
  161. }
  162. if ($schema->hasTable('schedulingobjects')) {
  163. $table = $schema->getTable('schedulingobjects');
  164. if (!$table->hasIndex('schedulobj_principuri_index')) {
  165. $subject->addHintForMissingSubject($table->getName(), 'schedulobj_principuri_index');
  166. }
  167. }
  168. if ($schema->hasTable('properties')) {
  169. $table = $schema->getTable('properties');
  170. if (!$table->hasIndex('properties_path_index')) {
  171. $subject->addHintForMissingSubject($table->getName(), 'properties_path_index');
  172. }
  173. if (!$table->hasIndex('properties_pathonly_index')) {
  174. $subject->addHintForMissingSubject($table->getName(), 'properties_pathonly_index');
  175. }
  176. }
  177. if ($schema->hasTable('jobs')) {
  178. $table = $schema->getTable('jobs');
  179. if (!$table->hasIndex('job_lastcheck_reserved')) {
  180. $subject->addHintForMissingSubject($table->getName(), 'job_lastcheck_reserved');
  181. }
  182. }
  183. if ($schema->hasTable('direct_edit')) {
  184. $table = $schema->getTable('direct_edit');
  185. if (!$table->hasIndex('direct_edit_timestamp')) {
  186. $subject->addHintForMissingSubject($table->getName(), 'direct_edit_timestamp');
  187. }
  188. }
  189. if ($schema->hasTable('preferences')) {
  190. $table = $schema->getTable('preferences');
  191. if (!$table->hasIndex('preferences_app_key')) {
  192. $subject->addHintForMissingSubject($table->getName(), 'preferences_app_key');
  193. }
  194. }
  195. if ($schema->hasTable('mounts')) {
  196. $table = $schema->getTable('mounts');
  197. if (!$table->hasIndex('mounts_class_index')) {
  198. $subject->addHintForMissingSubject($table->getName(), 'mounts_class_index');
  199. }
  200. }
  201. }
  202. );
  203. $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_PRIMARY_KEYS_EVENT,
  204. function (GenericEvent $event) use ($container) {
  205. /** @var MissingPrimaryKeyInformation $subject */
  206. $subject = $event->getSubject();
  207. $schema = new SchemaWrapper($container->query(Connection::class));
  208. if ($schema->hasTable('federated_reshares')) {
  209. $table = $schema->getTable('federated_reshares');
  210. if (!$table->hasPrimaryKey()) {
  211. $subject->addHintForMissingSubject($table->getName());
  212. }
  213. }
  214. if ($schema->hasTable('systemtag_object_mapping')) {
  215. $table = $schema->getTable('systemtag_object_mapping');
  216. if (!$table->hasPrimaryKey()) {
  217. $subject->addHintForMissingSubject($table->getName());
  218. }
  219. }
  220. if ($schema->hasTable('comments_read_markers')) {
  221. $table = $schema->getTable('comments_read_markers');
  222. if (!$table->hasPrimaryKey()) {
  223. $subject->addHintForMissingSubject($table->getName());
  224. }
  225. }
  226. if ($schema->hasTable('collres_resources')) {
  227. $table = $schema->getTable('collres_resources');
  228. if (!$table->hasPrimaryKey()) {
  229. $subject->addHintForMissingSubject($table->getName());
  230. }
  231. }
  232. if ($schema->hasTable('collres_accesscache')) {
  233. $table = $schema->getTable('collres_accesscache');
  234. if (!$table->hasPrimaryKey()) {
  235. $subject->addHintForMissingSubject($table->getName());
  236. }
  237. }
  238. if ($schema->hasTable('filecache_extended')) {
  239. $table = $schema->getTable('filecache_extended');
  240. if (!$table->hasPrimaryKey()) {
  241. $subject->addHintForMissingSubject($table->getName());
  242. }
  243. }
  244. }
  245. );
  246. $oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
  247. function (GenericEvent $event) use ($container) {
  248. /** @var MissingColumnInformation $subject */
  249. $subject = $event->getSubject();
  250. $schema = new SchemaWrapper($container->query(Connection::class));
  251. if ($schema->hasTable('comments')) {
  252. $table = $schema->getTable('comments');
  253. if (!$table->hasColumn('reference_id')) {
  254. $subject->addHintForMissingColumn($table->getName(), 'reference_id');
  255. }
  256. }
  257. }
  258. );
  259. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
  260. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeNotificationsListener::class);
  261. $eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeEmailListener::class);
  262. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeActivityListener::class);
  263. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeNotificationsListener::class);
  264. $eventDispatcher->addServiceListener(RemoteWipeFinished::class, RemoteWipeEmailListener::class);
  265. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedStoreCleanupListener::class);
  266. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedTokenCleanupListener::class);
  267. $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
  268. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedFilesCleanupListener::class);
  269. $eventDispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedWebAuthnCleanupListener::class);
  270. // Metadata
  271. /** @var IConfig $config */
  272. $config = $container->get(IConfig::class);
  273. if ($config->getSystemValueBool('enable_file_metadata', true)) {
  274. /** @psalm-suppress InvalidArgument */
  275. $eventDispatcher->addServiceListener(NodeDeletedEvent::class, FileEventListener::class);
  276. /** @psalm-suppress InvalidArgument */
  277. $eventDispatcher->addServiceListener(NodeRemovedFromCache::class, FileEventListener::class);
  278. /** @psalm-suppress InvalidArgument */
  279. $eventDispatcher->addServiceListener(NodeWrittenEvent::class, FileEventListener::class);
  280. }
  281. // Tags
  282. $eventDispatcher->addServiceListener(UserDeletedEvent::class, TagManager::class);
  283. }
  284. }