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

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