|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Analytics |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the LICENSE.md file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Marcel Scherello <[email protected]> |
|
9
|
|
|
* @copyright 2020 Marcel Scherello |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace OCA\Analytics\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use OCA\Analytics\Datasource\DatasourceEvent; |
|
15
|
|
|
use OCA\Analytics\Datasource\ExternalFileService; |
|
16
|
|
|
use OCA\Analytics\Datasource\FileService; |
|
17
|
|
|
use OCA\Analytics\Datasource\GithubService; |
|
18
|
|
|
use OCA\Analytics\Datasource\JsonService; |
|
19
|
|
|
use OCA\Analytics\Datasource\RegexService; |
|
20
|
|
|
use OCA\Analytics\Datasource\SurveyService; |
|
|
|
|
|
|
21
|
|
|
use OCP\AppFramework\Controller; |
|
22
|
|
|
use OCP\Files\NotFoundException; |
|
23
|
|
|
use OCP\ILogger; |
|
24
|
|
|
use OCP\IRequest; |
|
25
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
26
|
|
|
|
|
27
|
|
|
class DataSourceController extends Controller |
|
28
|
|
|
{ |
|
29
|
|
|
private $logger; |
|
30
|
|
|
private $GithubService; |
|
31
|
|
|
private $FileService; |
|
32
|
|
|
private $ExternalFileService; |
|
33
|
|
|
private $RegexService; |
|
34
|
|
|
private $JsonService; |
|
35
|
|
|
private $SurveyService; |
|
36
|
|
|
private $userId; |
|
37
|
|
|
/** @var EventDispatcherInterface */ |
|
38
|
|
|
protected $dispatcher; |
|
39
|
|
|
|
|
40
|
|
|
const DATASET_TYPE_GROUP = 0; |
|
41
|
|
|
const DATASET_TYPE_INTERNAL_FILE = 1; |
|
42
|
|
|
const DATASET_TYPE_INTERNAL_DB = 2; |
|
43
|
|
|
const DATASET_TYPE_GIT = 3; |
|
44
|
|
|
const DATASET_TYPE_EXTERNAL_FILE = 4; |
|
45
|
|
|
const DATASET_TYPE_REGEX = 5; |
|
46
|
|
|
const DATASET_TYPE_JSON = 6; |
|
47
|
|
|
const DATASET_TYPE_SURVEY = 7; |
|
48
|
|
|
|
|
49
|
|
|
public function __construct( |
|
50
|
|
|
string $AppName, |
|
51
|
|
|
IRequest $request, |
|
52
|
|
|
$userId, |
|
53
|
|
|
ILogger $logger, |
|
54
|
|
|
GithubService $GithubService, |
|
55
|
|
|
FileService $FileService, |
|
56
|
|
|
RegexService $RegexService, |
|
57
|
|
|
JsonService $JsonService, |
|
58
|
|
|
SurveyService $SurveyService, |
|
59
|
|
|
ExternalFileService $ExternalFileService, |
|
60
|
|
|
EventDispatcherInterface $dispatcher |
|
61
|
|
|
) |
|
62
|
|
|
{ |
|
63
|
|
|
parent::__construct($AppName, $request); |
|
64
|
|
|
$this->userId = $userId; |
|
65
|
|
|
$this->logger = $logger; |
|
66
|
|
|
$this->ExternalFileService = $ExternalFileService; |
|
67
|
|
|
$this->GithubService = $GithubService; |
|
68
|
|
|
$this->RegexService = $RegexService; |
|
69
|
|
|
$this->FileService = $FileService; |
|
70
|
|
|
$this->JsonService = $JsonService; |
|
71
|
|
|
$this->SurveyService = $SurveyService; |
|
72
|
|
|
$this->dispatcher = $dispatcher; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get the data from a datasource; |
|
77
|
|
|
* |
|
78
|
|
|
* @NoAdminRequired |
|
79
|
|
|
* @param int $datasource |
|
80
|
|
|
* @param $option |
|
81
|
|
|
* @return array|NotFoundException |
|
82
|
|
|
* @throws NotFoundException |
|
83
|
|
|
*/ |
|
84
|
|
|
public function read(int $datasource, $option) |
|
85
|
|
|
{ |
|
86
|
|
|
//$this->logger->debug('DataSourceController 66: Datasource Id: ' . $datasource . ', Option: ' . json_encode($option)); |
|
87
|
|
|
if ($datasource === self::DATASET_TYPE_INTERNAL_FILE) $result = $this->FileService->read($option); |
|
88
|
|
|
elseif ($datasource === self::DATASET_TYPE_GIT) $result = $this->GithubService->read($option); |
|
89
|
|
|
elseif ($datasource === self::DATASET_TYPE_EXTERNAL_FILE) $result = $this->ExternalFileService->read($option); |
|
90
|
|
|
elseif ($datasource === self::DATASET_TYPE_REGEX) $result = $this->RegexService->read($option); |
|
91
|
|
|
elseif ($datasource === self::DATASET_TYPE_JSON) $result = $this->JsonService->read($option); |
|
92
|
|
|
elseif ($datasource === self::DATASET_TYPE_SURVEY) $result = $this->SurveyService->read($option); |
|
93
|
|
|
else $result = new NotFoundException(); |
|
94
|
|
|
|
|
95
|
|
|
return $result; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* template for options & settings |
|
100
|
|
|
* |
|
101
|
|
|
* @NoAdminRequired |
|
102
|
|
|
* @param int $datasource |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getTemplates() |
|
106
|
|
|
{ |
|
107
|
|
|
$result[self::DATASET_TYPE_INTERNAL_FILE] = $this->FileService->getTemplate(); |
|
|
|
|
|
|
108
|
|
|
$result[self::DATASET_TYPE_GIT] = $this->GithubService->getTemplate(); |
|
109
|
|
|
$result[self::DATASET_TYPE_EXTERNAL_FILE] = $this->ExternalFileService->getTemplate(); |
|
110
|
|
|
$result[self::DATASET_TYPE_REGEX] = $this->RegexService->getTemplate(); |
|
111
|
|
|
$result[self::DATASET_TYPE_JSON] = $this->JsonService->getTemplate(); |
|
112
|
|
|
$result[self::DATASET_TYPE_SURVEY] = $this->SurveyService->getTemplate(); |
|
113
|
|
|
return $result; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function EventTest() |
|
117
|
|
|
{ |
|
118
|
|
|
$event = new DatasourceEvent(DatasourceEvent::class); |
|
119
|
|
|
$this->dispatcher->dispatch(DatasourceEvent::class, $event); |
|
|
|
|
|
|
120
|
|
|
|
|
121
|
|
|
$datasources = []; |
|
|
|
|
|
|
122
|
|
|
foreach ($event->getDataSources() as $datasource) { |
|
123
|
|
|
$datasource->getName(); |
|
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
} |
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