Merge pull request #7027 from nextcloud/purge-deleted-lists

fix: update DeleteCron to remove deleted lists
This commit is contained in:
Luka Trovic
2025-05-28 17:58:59 +02:00
committed by GitHub
3 changed files with 48 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ namespace OCA\Deck\Cron;
use OCA\Deck\Db\AttachmentMapper; use OCA\Deck\Db\AttachmentMapper;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\InvalidAttachmentType; use OCA\Deck\InvalidAttachmentType;
use OCA\Deck\Service\AttachmentService; use OCA\Deck\Service\AttachmentService;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
@@ -27,13 +28,16 @@ class DeleteCron extends TimedJob {
private $attachmentService; private $attachmentService;
/** @var AttachmentMapper */ /** @var AttachmentMapper */
private $attachmentMapper; private $attachmentMapper;
/** @var StackMapper */
private $stackMapper;
public function __construct(ITimeFactory $time, BoardMapper $boardMapper, CardMapper $cardMapper, AttachmentService $attachmentService, AttachmentMapper $attachmentMapper) { public function __construct(ITimeFactory $time, BoardMapper $boardMapper, CardMapper $cardMapper, AttachmentService $attachmentService, AttachmentMapper $attachmentMapper, StackMapper $stackMapper) {
parent::__construct($time); parent::__construct($time);
$this->boardMapper = $boardMapper; $this->boardMapper = $boardMapper;
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
$this->attachmentService = $attachmentService; $this->attachmentService = $attachmentService;
$this->attachmentMapper = $attachmentMapper; $this->attachmentMapper = $attachmentMapper;
$this->stackMapper = $stackMapper;
$this->setInterval(60 * 60 * 24); $this->setInterval(60 * 60 * 24);
$this->setTimeSensitivity(IJob::TIME_INSENSITIVE); $this->setTimeSensitivity(IJob::TIME_INSENSITIVE);
@@ -65,5 +69,10 @@ class DeleteCron extends TimedJob {
} }
$this->attachmentMapper->delete($attachment); $this->attachmentMapper->delete($attachment);
} }
$stacks = $this->stackMapper->findToDelete();
foreach ($stacks as $stack) {
$this->stackMapper->delete($stack);
}
} }
} }

View File

@@ -164,4 +164,15 @@ class StackMapper extends DeckMapper implements IPermissionMapper {
return $result !== false ? $result : null; return $result !== false ? $result : null;
} }
public function findToDelete(): array {
// add buffer of 5 min
$timeLimit = time() - (60 * 5);
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where($qb->expr()->neq('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)))
->andWhere($qb->expr()->lt('deleted_at', $qb->createNamedParameter($timeLimit, IQueryBuilder::PARAM_INT)));
return $this->findEntities($qb);
}
} }

View File

@@ -30,6 +30,8 @@ use OCA\Deck\Db\Board;
use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\BoardMapper;
use OCA\Deck\Db\Card; use OCA\Deck\Db\Card;
use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\InvalidAttachmentType; use OCA\Deck\InvalidAttachmentType;
use OCA\Deck\Service\AttachmentService; use OCA\Deck\Service\AttachmentService;
use OCA\Deck\Service\IAttachmentService; use OCA\Deck\Service\IAttachmentService;
@@ -49,6 +51,8 @@ class DeleteCronTest extends TestCase {
private $attachmentService; private $attachmentService;
/** @var AttachmentMapper|MockObject */ /** @var AttachmentMapper|MockObject */
private $attachmentMapper; private $attachmentMapper;
/** @var StackMapper|MockObject */
private $stackMapper;
/** @var DeleteCron */ /** @var DeleteCron */
protected $deleteCron; protected $deleteCron;
@@ -59,7 +63,8 @@ class DeleteCronTest extends TestCase {
$this->cardMapper = $this->createMock(CardMapper::class); $this->cardMapper = $this->createMock(CardMapper::class);
$this->attachmentService = $this->createMock(AttachmentService::class); $this->attachmentService = $this->createMock(AttachmentService::class);
$this->attachmentMapper = $this->createMock(AttachmentMapper::class); $this->attachmentMapper = $this->createMock(AttachmentMapper::class);
$this->deleteCron = new DeleteCron($this->timeFactory, $this->boardMapper, $this->cardMapper, $this->attachmentService, $this->attachmentMapper); $this->stackMapper = $this->createMock(StackMapper::class);
$this->deleteCron = new DeleteCron($this->timeFactory, $this->boardMapper, $this->cardMapper, $this->attachmentService, $this->attachmentMapper, $this->stackMapper);
} }
protected function getBoard($id) { protected function getBoard($id) {
@@ -74,6 +79,12 @@ class DeleteCronTest extends TestCase {
return $card; return $card;
} }
protected function getStack($id) {
$stack = new Stack();
$stack->setId($id);
return $stack;
}
public function testDeleteCron() { public function testDeleteCron() {
$boards = [ $boards = [
$this->getBoard(1), $this->getBoard(1),
@@ -118,6 +129,21 @@ class DeleteCronTest extends TestCase {
$this->attachmentMapper->expects($this->once()) $this->attachmentMapper->expects($this->once())
->method('delete') ->method('delete')
->with($attachment); ->with($attachment);
$stacks = [
$this->getStack(100),
$this->getStack(101),
];
$this->stackMapper->expects($this->once())
->method('findToDelete')
->willReturn($stacks);
$this->stackMapper->expects($this->exactly(count($stacks)))
->method('delete')
->withConsecutive(
[$stacks[0]],
[$stacks[1]]
);
$this->invokePrivate($this->deleteCron, 'run', [null]); $this->invokePrivate($this->deleteCron, 'run', [null]);
} }