EnumerateImagesMissingFacesTask::description()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017, Matias De lellis <[email protected]>
4
 * @copyright Copyright (c) 2018, Branko Kokanovic <[email protected]>
5
 *
6
 * @author Branko Kokanovic <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
namespace OCA\FaceRecognition\BackgroundJob\Tasks;
25
26
use OCA\FaceRecognition\Db\Image;
27
use OCA\FaceRecognition\Db\ImageMapper;
28
use OCA\FaceRecognition\Service\SettingsService;
29
30
use OCA\FaceRecognition\BackgroundJob\FaceRecognitionBackgroundTask;
31
use OCA\FaceRecognition\BackgroundJob\FaceRecognitionContext;
32
33
/**
34
 * Task that gets all images (from database) that don't yet have faces found (e.g. they are not processed).
35
 * Shuffles found images and outputs them to context->propertyBag.
36
 */
37
class EnumerateImagesMissingFacesTask extends FaceRecognitionBackgroundTask {
38
39
	/** @var SettingsService Settings service */
40
	private $settingsService;
41
42
	/** @var ImageMapper Image mapper*/
43
	protected $imageMapper;
44
45
	/**
46
	 * @param SettingsService $settingsService Settings service
47
	 * @param ImageMapper $imageMapper Image mapper
48
	 */
49
	public function __construct(SettingsService $settingsService,
50
	                            ImageMapper     $imageMapper)
51
	{
52
		parent::__construct();
53
		$this->settingsService = $settingsService;
54
		$this->imageMapper     = $imageMapper;
55
	}
56
57
	/**
58
	 * @inheritdoc
59
	 */
60
	public function description() {
61
		return "Find all images which don't have faces generated for them";
62
	}
63
64
	/**
65
	 * @inheritdoc
66
	 */
67
	public function execute(FaceRecognitionContext $context) {
68
		$this->setContext($context);
69
70
		$modelId = $this->settingsService->getCurrentFaceModel();
71
72
		$images = $this->imageMapper->findImagesWithoutFaces($this->context->user, $modelId);
73
		yield;
74
75
		shuffle($images);
76
		$this->context->propertyBag['images'] = $images;
77
78
		return true;
79
	}
80
}