1
0

CheckForUserCertificates.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2020 Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @author J0WI <J0WI@users.noreply.github.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OC\Core\BackgroundJobs;
  26. use OCP\AppFramework\Utility\ITimeFactory;
  27. use OCP\BackgroundJob\QueuedJob;
  28. use OCP\Files\Folder;
  29. use OCP\Files\IRootFolder;
  30. use OCP\Files\NotFoundException;
  31. use OCP\IConfig;
  32. use OCP\IUser;
  33. use OCP\IUserManager;
  34. class CheckForUserCertificates extends QueuedJob {
  35. public function __construct(
  36. protected IConfig $config,
  37. private IUserManager $userManager,
  38. private IRootFolder $rootFolder,
  39. ITimeFactory $time,
  40. ) {
  41. parent::__construct($time);
  42. }
  43. /**
  44. * Checks all user directories for old user uploaded certificates
  45. */
  46. public function run($arguments): void {
  47. $uploadList = [];
  48. $this->userManager->callForSeenUsers(function (IUser $user) use (&$uploadList) {
  49. $userId = $user->getUID();
  50. try {
  51. \OC_Util::setupFS($userId);
  52. $filesExternalUploadsFolder = $this->rootFolder->get($userId . '/files_external/uploads');
  53. } catch (NotFoundException $e) {
  54. \OC_Util::tearDownFS();
  55. return;
  56. }
  57. if ($filesExternalUploadsFolder instanceof Folder) {
  58. $files = $filesExternalUploadsFolder->getDirectoryListing();
  59. foreach ($files as $file) {
  60. $filename = $file->getName();
  61. $uploadList[] = "$userId/files_external/uploads/$filename";
  62. }
  63. }
  64. \OC_Util::tearDownFS();
  65. });
  66. if (empty($uploadList)) {
  67. $this->config->deleteAppValue('files_external', 'user_certificate_scan');
  68. } else {
  69. $this->config->setAppValue('files_external', 'user_certificate_scan', json_encode($uploadList));
  70. }
  71. }
  72. }