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
This commit is contained in:
commit
80e527d21e
2 changed files with 22 additions and 2 deletions
|
@ -30,6 +30,7 @@ use OCP\Files\IRootFolder;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\Files\NotPermittedException;
|
use OCP\Files\NotPermittedException;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
use OCP\IUserManager;
|
||||||
|
|
||||||
class CleanPreviewsBackgroundJob extends QueuedJob {
|
class CleanPreviewsBackgroundJob extends QueuedJob {
|
||||||
/** @var IRootFolder */
|
/** @var IRootFolder */
|
||||||
|
@ -44,6 +45,9 @@ class CleanPreviewsBackgroundJob extends QueuedJob {
|
||||||
/** @var ITimeFactory */
|
/** @var ITimeFactory */
|
||||||
private $timeFactory;
|
private $timeFactory;
|
||||||
|
|
||||||
|
/** @var IUserManager */
|
||||||
|
private $userManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CleanPreviewsBackgroundJob constructor.
|
* CleanPreviewsBackgroundJob constructor.
|
||||||
*
|
*
|
||||||
|
@ -51,19 +55,26 @@ class CleanPreviewsBackgroundJob extends QueuedJob {
|
||||||
* @param ILogger $logger
|
* @param ILogger $logger
|
||||||
* @param IJobList $jobList
|
* @param IJobList $jobList
|
||||||
* @param ITimeFactory $timeFactory
|
* @param ITimeFactory $timeFactory
|
||||||
|
* @param IUserManager $userManager
|
||||||
*/
|
*/
|
||||||
public function __construct(IRootFolder $rootFolder,
|
public function __construct(IRootFolder $rootFolder,
|
||||||
ILogger $logger,
|
ILogger $logger,
|
||||||
IJobList $jobList,
|
IJobList $jobList,
|
||||||
ITimeFactory $timeFactory) {
|
ITimeFactory $timeFactory,
|
||||||
|
IUserManager $userManager) {
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->jobList = $jobList;
|
$this->jobList = $jobList;
|
||||||
$this->timeFactory = $timeFactory;
|
$this->timeFactory = $timeFactory;
|
||||||
|
$this->userManager = $userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run($arguments) {
|
public function run($arguments) {
|
||||||
$uid = $arguments['uid'];
|
$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);
|
$this->logger->info('Started preview cleanup for ' . $uid);
|
||||||
$empty = $this->cleanupPreviews($uid);
|
$empty = $this->cleanupPreviews($uid);
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ use OCP\Files\IRootFolder;
|
||||||
use OCP\Files\NotFoundException;
|
use OCP\Files\NotFoundException;
|
||||||
use OCP\Files\NotPermittedException;
|
use OCP\Files\NotPermittedException;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
|
use OCP\IUserManager;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class CleanPreviewsBackgroundJobTest extends TestCase {
|
class CleanPreviewsBackgroundJobTest extends TestCase {
|
||||||
|
@ -48,6 +49,9 @@ class CleanPreviewsBackgroundJobTest extends TestCase {
|
||||||
/** @var CleanPreviewsBackgroundJob */
|
/** @var CleanPreviewsBackgroundJob */
|
||||||
private $job;
|
private $job;
|
||||||
|
|
||||||
|
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $userManager;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -55,12 +59,17 @@ class CleanPreviewsBackgroundJobTest extends TestCase {
|
||||||
$this->logger = $this->createMock(ILogger::class);
|
$this->logger = $this->createMock(ILogger::class);
|
||||||
$this->jobList = $this->createMock(IJobList::class);
|
$this->jobList = $this->createMock(IJobList::class);
|
||||||
$this->timeFactory = $this->createMock(ITimeFactory::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->job = new CleanPreviewsBackgroundJob(
|
||||||
$this->rootFolder,
|
$this->rootFolder,
|
||||||
$this->logger,
|
$this->logger,
|
||||||
$this->jobList,
|
$this->jobList,
|
||||||
$this->timeFactory);
|
$this->timeFactory,
|
||||||
|
$this->userManager
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCleanupPreviewsUnfinished() {
|
public function testCleanupPreviewsUnfinished() {
|
||||||
|
|
Loading…
Reference in a new issue