1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2019, Matias De lellis <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @author Matias De lellis <[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
|
|
|
namespace OCA\FaceRecognition\Service; |
25
|
|
|
|
26
|
|
|
use OCP\IConfig; |
27
|
|
|
use OCP\Files\IAppData; |
28
|
|
|
use OCP\Files\IRootFolder; |
29
|
|
|
use OCP\Files\NotFoundException; |
30
|
|
|
|
31
|
|
|
class ModelService { |
32
|
|
|
|
33
|
|
|
/** @var IConfig */ |
34
|
|
|
private $config; |
35
|
|
|
|
36
|
|
|
/** @var IAppData */ |
37
|
|
|
private $appData; |
38
|
|
|
|
39
|
|
|
/** @var IRootFolder */ |
40
|
|
|
private $rootFolder; |
41
|
|
|
|
42
|
|
|
/** @var string */ |
43
|
|
|
private $modelsFolder; |
44
|
|
|
|
45
|
1 |
|
public function __construct(IConfig $config, |
46
|
|
|
IAppData $appData, |
47
|
|
|
IRootFolder $rootFolder) { |
48
|
1 |
|
$this->config = $config; |
49
|
1 |
|
$this->appData = $appData; |
50
|
1 |
|
$this->rootFolder = $rootFolder; |
51
|
|
|
|
52
|
1 |
|
$this->prepareAppDataFolders(); |
53
|
1 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return none |
|
|
|
|
57
|
|
|
*/ |
58
|
4 |
|
public function useModelVersion (int $version) { |
59
|
|
|
try { |
60
|
4 |
|
$this->appData->getFolder('/models/' . $version); |
61
|
1 |
|
} catch (NotFoundException $e) { |
62
|
1 |
|
$this->appData->newFolder('/models/' . $version); |
63
|
|
|
} |
64
|
|
|
|
65
|
4 |
|
$instanceId = $this->config->getSystemValue('instanceid', null); |
66
|
4 |
|
$appData = $this->rootFolder->get('appdata_'.$instanceId)->getPath(); |
67
|
4 |
|
$dataDir = $this->config->getSystemValue('datadirectory', null); |
68
|
|
|
|
69
|
4 |
|
$this->modelsFolder = $dataDir . $appData . '/facerecognition/models/' . $version . '/'; |
70
|
4 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return String |
74
|
|
|
*/ |
75
|
4 |
|
public function getModelPath(string $file): string { |
76
|
4 |
|
return $this->modelsFolder . $file; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return none |
81
|
|
|
*/ |
82
|
1 |
|
private function prepareAppDataFolders() { |
83
|
|
|
try { |
84
|
1 |
|
$this->appData->getFolder('/models'); |
85
|
1 |
|
} catch (NotFoundException $e) { |
86
|
1 |
|
$this->appData->newFolder('/models'); |
87
|
|
|
} |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths