Allow to undo file deletions

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2018-06-12 15:33:06 +02:00
parent 0c711b2b0b
commit ee5a54a575
12 changed files with 152 additions and 20 deletions

View File

@@ -21,25 +21,28 @@
*
*/
/**
* Created by PhpStorm.
* User: jus
* Date: 16.05.17
* Time: 12:34
*/
namespace OCA\Deck\Cron;
use OC\BackgroundJob\Job;
use OCA\Deck\Db\AttachmentMapper;
use OCA\Deck\Db\BoardMapper;
use OCA\Deck\InvalidAttachmentType;
use OCA\Deck\Service\AttachmentService;
class DeleteCron extends Job {
/** @var BoardMapper */
private $boardMapper;
/** @var AttachmentService */
private $attachmentService;
/** @var AttachmentMapper */
private $attachmentMapper;
public function __construct(BoardMapper $boardMapper) {
public function __construct(BoardMapper $boardMapper, AttachmentService $attachmentService, AttachmentMapper $attachmentMapper) {
$this->boardMapper = $boardMapper;
$this->attachmentService = $attachmentService;
$this->attachmentMapper = $attachmentMapper;
}
/**
@@ -51,6 +54,18 @@ class DeleteCron extends Job {
foreach ($boards as $board) {
$this->boardMapper->delete($board);
}
$attachments = $this->attachmentMapper->findToDelete();
foreach ($attachments as $attachment) {
try {
$service = $this->attachmentService->getService($attachment->getType());
$service->delete($attachment);
} catch (InvalidAttachmentType $e) {
// Just delete the attachment if no service is available
}
$this->attachmentMapper->delete($attachment);
}
}
}