DeleteCron::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 3
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
25
namespace OCA\Deck\Cron;
26
27
use OC\BackgroundJob\Job;
28
use OCA\Deck\Db\AttachmentMapper;
29
use OCA\Deck\Db\BoardMapper;
30
use OCA\Deck\InvalidAttachmentType;
31
use OCA\Deck\Service\AttachmentService;
32
33
class DeleteCron extends Job {
34
35
	/** @var BoardMapper */
36
	private $boardMapper;
37
	/** @var AttachmentService */
38
	private $attachmentService;
39
	/** @var AttachmentMapper */
40
	private $attachmentMapper;
41
42
	public function __construct(BoardMapper $boardMapper, AttachmentService $attachmentService, AttachmentMapper $attachmentMapper) {
43
		$this->boardMapper = $boardMapper;
44
		$this->attachmentService = $attachmentService;
45
		$this->attachmentMapper = $attachmentMapper;
46
	}
47
48
	/**
49
	 * @param $argument
50
	 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
51
	 */
52
	protected function run($argument) {
53
		$boards = $this->boardMapper->findToDelete();
54
		foreach ($boards as $board) {
55
			$this->boardMapper->delete($board);
56
		}
57
58
		$attachments = $this->attachmentMapper->findToDelete();
59
		foreach ($attachments as $attachment) {
60
			try {
61
				$service = $this->attachmentService->getService($attachment->getType());
62
				$service->delete($attachment);
63
			} catch (InvalidAttachmentType $e) {
64
				// Just delete the attachment if no service is available
65
			}
66
			$this->attachmentMapper->delete($attachment);
0 ignored issues
show
Deprecated Code introduced by
The method OCP\AppFramework\Db\Mapper::delete() has been deprecated with message: 14.0.0 Move over to QBMapper

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
67
		}
68
69
	}
70
71
}