Passed
Pull Request — master (#709)
by Julius
02:29
created

CardDescriptionActivity::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2018 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\Activity\ActivityManager;
29
use OCA\Deck\Activity\ChangeSet;
30
use OCA\Deck\Db\AttachmentMapper;
31
use OCA\Deck\Db\BoardMapper;
32
use OCA\Deck\Db\Card;
33
use OCA\Deck\Db\CardMapper;
34
use OCA\Deck\InvalidAttachmentType;
35
use OCA\Deck\Service\AttachmentService;
36
use OCA\Deck\Service\CardService;
37
38
class CardDescriptionActivity extends Job {
39
40
	/** @var ActivityManager */
41
	private $activityManager;
42
	/** @var CardMapper */
43
	private $cardMapper;
44
45
	public function __construct(ActivityManager $activityManager, CardMapper $cardMapper) {
46
		$this->activityManager  = $activityManager;
47
		$this->cardMapper = $cardMapper;
48
	}
49
50
	/**
51
	 * @param $argument
52
	 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
53
	 */
54
	public function run($argument) {
55
		$cards = $this->cardMapper->findUnexposedDescriptionChances();
56
		foreach ($cards as $card) {
57
			$this->activityManager->triggerEvent(
58
				ActivityManager::DECK_OBJECT_CARD,
59
				$card,
60
				ActivityManager::SUBJECT_CARD_UPDATE_DESCRIPTION,
61
				[
62
					'before' => $card->getDescriptionPrev(),
63
					'after' => $card->getDescription()
64
				],
65
				$card->getLastEditor()
66
			);
67
68
			$card->setDescriptionPrev(null);
69
			$card->setLastEditor(null);
70
			$this->cardMapper->update($card, false);
71
		}
72
	}
73
74
}
75