1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- declare(strict_types=1);
- namespace OCA\DAV\Migration;
- use OCA\DAV\BackgroundJob\UploadCleanup;
- use OCP\BackgroundJob\IJobList;
- use OCP\Files\Folder;
- use OCP\Files\IRootFolder;
- use OCP\Files\NotFoundException;
- use OCP\IConfig;
- use OCP\IUser;
- use OCP\IUserManager;
- use OCP\Migration\IOutput;
- use OCP\Migration\IRepairStep;
- class ChunkCleanup implements IRepairStep {
-
- private $config;
-
- private $userManager;
-
- private $rootFolder;
-
- private $jobList;
- public function __construct(IConfig $config,
- IUserManager $userManager,
- IRootFolder $rootFolder,
- IJobList $jobList) {
- $this->config = $config;
- $this->userManager = $userManager;
- $this->rootFolder = $rootFolder;
- $this->jobList = $jobList;
- }
- public function getName(): string {
- return 'Chunk cleanup scheduler';
- }
- public function run(IOutput $output) {
-
- if ($this->config->getAppValue('dav', 'chunks_migrated', '0') === '1') {
- $output->info('Cleanup not required');
- }
- $output->startProgress();
-
- $this->userManager->callForSeenUsers(function (IUser $user) use ($output) {
- try {
- $userFolder = $this->rootFolder->getUserFolder($user->getUID());
- $userRoot = $userFolder->getParent();
-
- $uploadFolder = $userRoot->get('uploads');
- } catch (NotFoundException $e) {
-
- return;
- }
-
- $uploads = $uploadFolder->getDirectoryListing();
- foreach ($uploads as $upload) {
- $this->jobList->add(UploadCleanup::class, ['uid' => $user->getUID(), 'folder' => $upload->getName()]);
- }
- $output->advance();
- });
- $output->finishProgress();
- $this->config->setAppValue('dav', 'chunks_migrated', '1');
- }
- }
|