diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-11-14 23:29:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-14 23:29:28 +0100 |
commit | 80e527d21ea6cf408418710f9007e32980a5b4a8 (patch) | |
tree | 236461308efd42ebf168bbbafc4e26781c1d9e83 | |
parent | d906e16617de5abc0d48b0b7cbabe54f10cbed0b (diff) | |
parent | a923e755e67e0e14dee824877afa9e6425b38379 (diff) | |
download | nextcloud-server-80e527d21ea6cf408418710f9007e32980a5b4a8.tar.gz nextcloud-server-80e527d21ea6cf408418710f9007e32980a5b4a8.zip |
Merge pull request #7172 from nextcloud/improve-error-handling-on-preview-cleanup
check if the user still exists before we try to cleanup the previews
-rw-r--r-- | lib/private/Repair/NC11/CleanPreviewsBackgroundJob.php | 13 | ||||
-rw-r--r-- | tests/lib/Repair/NC11/CleanPreviewsBackgroundJobTest.php | 11 |
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/private/Repair/NC11/CleanPreviewsBackgroundJob.php b/lib/private/Repair/NC11/CleanPreviewsBackgroundJob.php index 9efe01508a6..e713f4dc63a 100644 --- a/lib/private/Repair/NC11/CleanPreviewsBackgroundJob.php +++ b/lib/private/Repair/NC11/CleanPreviewsBackgroundJob.php @@ -30,6 +30,7 @@ use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\ILogger; +use OCP\IUserManager; class CleanPreviewsBackgroundJob extends QueuedJob { /** @var IRootFolder */ @@ -44,6 +45,9 @@ class CleanPreviewsBackgroundJob extends QueuedJob { /** @var ITimeFactory */ private $timeFactory; + /** @var IUserManager */ + private $userManager; + /** * CleanPreviewsBackgroundJob constructor. * @@ -51,19 +55,26 @@ class CleanPreviewsBackgroundJob extends QueuedJob { * @param ILogger $logger * @param IJobList $jobList * @param ITimeFactory $timeFactory + * @param IUserManager $userManager */ public function __construct(IRootFolder $rootFolder, ILogger $logger, IJobList $jobList, - ITimeFactory $timeFactory) { + ITimeFactory $timeFactory, + IUserManager $userManager) { $this->rootFolder = $rootFolder; $this->logger = $logger; $this->jobList = $jobList; $this->timeFactory = $timeFactory; + $this->userManager = $userManager; } public function run($arguments) { $uid = $arguments['uid']; + if (!$this->userManager->userExists($uid)) { + $this->logger->info('User no longer exists, skip user ' . $uid); + return; + } $this->logger->info('Started preview cleanup for ' . $uid); $empty = $this->cleanupPreviews($uid); diff --git a/tests/lib/Repair/NC11/CleanPreviewsBackgroundJobTest.php b/tests/lib/Repair/NC11/CleanPreviewsBackgroundJobTest.php index e3fb22f0825..c0e2f0ce1b5 100644 --- a/tests/lib/Repair/NC11/CleanPreviewsBackgroundJobTest.php +++ b/tests/lib/Repair/NC11/CleanPreviewsBackgroundJobTest.php @@ -30,6 +30,7 @@ use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\ILogger; +use OCP\IUserManager; use Test\TestCase; class CleanPreviewsBackgroundJobTest extends TestCase { @@ -48,6 +49,9 @@ class CleanPreviewsBackgroundJobTest extends TestCase { /** @var CleanPreviewsBackgroundJob */ private $job; + /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */ + private $userManager; + public function setUp() { parent::setUp(); @@ -55,12 +59,17 @@ class CleanPreviewsBackgroundJobTest extends TestCase { $this->logger = $this->createMock(ILogger::class); $this->jobList = $this->createMock(IJobList::class); $this->timeFactory = $this->createMock(ITimeFactory::class); + $this->userManager = $this->createMock(IUserManager::class); + + $this->userManager->expects($this->any())->method('userExists')->willReturn(true); $this->job = new CleanPreviewsBackgroundJob( $this->rootFolder, $this->logger, $this->jobList, - $this->timeFactory); + $this->timeFactory, + $this->userManager + ); } public function testCleanupPreviewsUnfinished() { |