CheckForUserCertificates.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Core\BackgroundJobs;
  8. use OCP\AppFramework\Utility\ITimeFactory;
  9. use OCP\BackgroundJob\QueuedJob;
  10. use OCP\Files\Folder;
  11. use OCP\Files\IRootFolder;
  12. use OCP\Files\NotFoundException;
  13. use OCP\IConfig;
  14. use OCP\IUser;
  15. use OCP\IUserManager;
  16. class CheckForUserCertificates extends QueuedJob {
  17. public function __construct(
  18. protected IConfig $config,
  19. private IUserManager $userManager,
  20. private IRootFolder $rootFolder,
  21. ITimeFactory $time,
  22. ) {
  23. parent::__construct($time);
  24. }
  25. /**
  26. * Checks all user directories for old user uploaded certificates
  27. */
  28. public function run($arguments): void {
  29. $uploadList = [];
  30. $this->userManager->callForSeenUsers(function (IUser $user) use (&$uploadList) {
  31. $userId = $user->getUID();
  32. try {
  33. \OC_Util::setupFS($userId);
  34. $filesExternalUploadsFolder = $this->rootFolder->get($userId . '/files_external/uploads');
  35. } catch (NotFoundException $e) {
  36. \OC_Util::tearDownFS();
  37. return;
  38. }
  39. if ($filesExternalUploadsFolder instanceof Folder) {
  40. $files = $filesExternalUploadsFolder->getDirectoryListing();
  41. foreach ($files as $file) {
  42. $filename = $file->getName();
  43. $uploadList[] = "$userId/files_external/uploads/$filename";
  44. }
  45. }
  46. \OC_Util::tearDownFS();
  47. });
  48. if (empty($uploadList)) {
  49. $this->config->deleteAppValue('files_external', 'user_certificate_scan');
  50. } else {
  51. $this->config->setAppValue('files_external', 'user_certificate_scan', json_encode($uploadList));
  52. }
  53. }
  54. }