Completed
Push — master ( dce9c2...90c6b3 )
by Branko
10s
created

CheckRequirementsTask::do()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 0
cts 15
cp 0
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
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 OCP\IConfig;
27
28
use OCA\FaceRecognition\BackgroundJob\FaceRecognitionBackgroundTask;
29
use OCA\FaceRecognition\BackgroundJob\FaceRecognitionContext;
30
use OCA\FaceRecognition\Helper\Requirements;
31
use OCA\FaceRecognition\Migration\AddDefaultFaceModel;
32
33
/**
34
 * Check all requirements before we start engaging in lengthy background task.
35
 */
36
class CheckRequirementsTask extends FaceRecognitionBackgroundTask {
37
	/** @var IConfig Config */
38
	private $config;
39
40
	/**
41
	 * @param IConfig $config Config
42
	 */
43
	public function __construct(IConfig $config) {
44
		parent::__construct();
45
		$this->config = $config;
46
	}
47
48
	/**
49
	 * @inheritdoc
50
	 */
51
	public function description() {
52
		return "Check all requirements";
53
	}
54
55
	/**
56
	 * @inheritdoc
57
	 */
58
	public function execute(FaceRecognitionContext $context) {
59
		$this->setContext($context);
60
		$model = intval($this->config->getAppValue('facerecognition', 'model', AddDefaultFaceModel::DEFAULT_FACE_MODEL_ID));
61
62
		$req = new Requirements($context->appManager, $model);
63
64
		if (!$req->pdlibLoaded()) {
65
			$error_message = "PDLib is not loaded. Cannot continue";
66
			$this->logInfo($error_message);
67
			return false;
68
		}
69
70
		if (!$req->modelFilesPresent()) {
71
			$error_message =
72
				"Files of model with ID ' . $model . ' are not present in models/ directory.\n" .
73
				"Please contact administrator to change models you are using for face recognition\n" .
74
				"or reinstall application. File an issue here if that doesn\'t help: https://github.com/matiasdelellis/facerecognition/issues";
75
			$this->logInfo($error_message);
76
			return false;
77
		}
78
79
		return true;
80
	}
81
}