1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Analytics |
4
|
|
|
* |
5
|
|
|
* SPDX-FileCopyrightText: 2024 Marcel Scherello |
6
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace OCA\Analytics\ContextChat; |
10
|
|
|
|
11
|
|
|
use OCP\DB\Exception; |
|
|
|
|
12
|
|
|
use OCP\IL10N; |
|
|
|
|
13
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
14
|
|
|
use OCA\ContextChat\Public\ContentItem; |
|
|
|
|
15
|
|
|
use OCA\Analytics\Service\StorageService; |
16
|
|
|
use OCA\Analytics\Service\DatasetService; |
17
|
|
|
|
18
|
|
|
class ContentManager { |
19
|
|
|
private $userId; |
20
|
|
|
private $logger; |
21
|
|
|
private $l10n; |
22
|
|
|
private $StorageService; |
23
|
|
|
private $DatasetService; |
24
|
|
|
|
25
|
|
|
public function __construct( |
26
|
|
|
$userId, |
27
|
|
|
IL10N $l10n, |
28
|
|
|
LoggerInterface $logger, |
29
|
|
|
StorageService $StorageService, |
30
|
|
|
DatasetService $DatasetService |
31
|
|
|
) { |
32
|
|
|
$this->userId = $userId; |
33
|
|
|
$this->l10n = $l10n; |
34
|
|
|
$this->logger = $logger; |
35
|
|
|
$this->StorageService = $StorageService; |
36
|
|
|
$this->DatasetService = $DatasetService; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Providers can use this to submit content for indexing in context chat |
41
|
|
|
* |
42
|
|
|
* @param int $datasetId |
43
|
|
|
* @return void |
44
|
|
|
* @throws Exception |
45
|
|
|
*/ |
46
|
|
|
public function submitContent(int $datasetId): void { |
47
|
|
|
$storageData = $this->StorageService->read($datasetId, null); |
48
|
|
|
$datasetMetadata = $this->DatasetService->read($datasetId); |
49
|
|
|
|
50
|
|
|
$columns = $datasetMetadata['dimension1'] .', '.$datasetMetadata['dimension2'].', '.$datasetMetadata['value']; |
51
|
|
|
|
52
|
|
|
$data = array_map(function ($subArray) { |
53
|
|
|
return implode(",", $subArray); |
54
|
|
|
}, $storageData['data']); |
55
|
|
|
$dataString = implode("\n", $data); |
56
|
|
|
|
57
|
|
|
$content = 'This is a report of statistical data. ' . $datasetMetadata['subheader'] . '. '; |
58
|
|
|
$content .= 'The data comes in multiple rows which 3 columns separated by a comma. '; |
59
|
|
|
$content .= 'The columns are ' . $columns . '. '; |
60
|
|
|
$content .= 'The data is: ' . $dataString; |
61
|
|
|
|
62
|
|
|
$contentItem = new ContentItem($datasetId, 'report', $datasetMetadata['name'], $content, 'Report', new \DateTime(), ['admin']); |
63
|
|
|
|
64
|
|
|
$contentItems = [$contentItem]; |
65
|
|
|
//$this->ContentManager->removeContentForUsers('analytics', 'report', $dataset, ['admin']); |
66
|
|
|
$this->logger->debug('adding item: ' . json_encode($contentItem)); |
67
|
|
|
$this->ContentManager->submitContent('analytics', $contentItems); |
|
|
|
|
68
|
|
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* return true if the data set has indexing activated |
73
|
|
|
* |
74
|
|
|
* @param int $datasetId |
75
|
|
|
* @return bool |
76
|
|
|
* @throws Exception |
77
|
|
|
*/ |
78
|
|
|
public function isActiveForDataset(int $datasetId) { |
79
|
|
|
$datasetMetadata = $this->DatasetService->read($datasetId); |
80
|
|
|
return $datasetMetadata['ai_index'] === 1; |
81
|
|
|
} |
82
|
|
|
} |
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