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 2019-2022 Marcel Scherello |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Analytics\Service; |
13
|
|
|
|
14
|
|
|
use OCA\Analytics\Activity\ActivityManager; |
15
|
|
|
use OCA\Analytics\Controller\DatasourceController; |
16
|
|
|
use OCA\Analytics\Db\PanoramaMapper; |
17
|
|
|
use OCP\AppFramework\Http\DataDownloadResponse; |
|
|
|
|
18
|
|
|
use OCP\DB\Exception; |
|
|
|
|
19
|
|
|
use OCP\Files\IRootFolder; |
|
|
|
|
20
|
|
|
use OCP\ITagManager; |
|
|
|
|
21
|
|
|
use OCP\IConfig; |
|
|
|
|
22
|
|
|
use OCP\PreConditionNotMetException; |
|
|
|
|
23
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
24
|
|
|
use OCP\IL10N; |
|
|
|
|
25
|
|
|
|
26
|
|
|
class PanoramaService |
27
|
|
|
{ |
28
|
|
|
/** @var IConfig */ |
29
|
|
|
protected $config; |
30
|
|
|
private $userId; |
31
|
|
|
private $logger; |
32
|
|
|
private $tagManager; |
33
|
|
|
private $ShareService; |
34
|
|
|
private $DatasetService; |
35
|
|
|
private $StorageMapper; |
|
|
|
|
36
|
|
|
private $PanoramaMapper; |
37
|
|
|
private $ThresholdMapper; |
38
|
|
|
private $DataloadMapper; |
|
|
|
|
39
|
|
|
private $ActivityManager; |
40
|
|
|
private $rootFolder; |
41
|
|
|
private $VariableService; |
42
|
|
|
private $l10n; |
43
|
|
|
|
44
|
|
|
const REPORT_TYPE_GROUP = 0; |
45
|
|
|
|
46
|
|
|
public function __construct( |
47
|
|
|
$userId, |
48
|
|
|
IL10N $l10n, |
49
|
|
|
LoggerInterface $logger, |
50
|
|
|
ITagManager $tagManager, |
51
|
|
|
ShareService $ShareService, |
52
|
|
|
DatasetService $DatasetService, |
53
|
|
|
PanoramaMapper $PanoramaMapper, |
54
|
|
|
ActivityManager $ActivityManager, |
55
|
|
|
IRootFolder $rootFolder, |
56
|
|
|
IConfig $config, |
57
|
|
|
VariableService $VariableService |
58
|
|
|
) |
59
|
|
|
{ |
60
|
|
|
$this->userId = $userId; |
61
|
|
|
$this->logger = $logger; |
62
|
|
|
$this->tagManager = $tagManager; |
63
|
|
|
$this->ShareService = $ShareService; |
64
|
|
|
$this->DatasetService = $DatasetService; |
65
|
|
|
$this->PanoramaMapper = $PanoramaMapper; |
66
|
|
|
$this->ActivityManager = $ActivityManager; |
67
|
|
|
$this->rootFolder = $rootFolder; |
68
|
|
|
$this->VariableService = $VariableService; |
69
|
|
|
$this->config = $config; |
70
|
|
|
$this->l10n = $l10n; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* get all reports |
75
|
|
|
* |
76
|
|
|
* @return array |
77
|
|
|
* @throws PreConditionNotMetException |
78
|
|
|
* @throws Exception |
79
|
|
|
*/ |
80
|
|
|
public function index(): array |
81
|
|
|
{ |
82
|
|
|
$ownReports = $this->PanoramaMapper->index(); |
83
|
|
|
//$sharedReports = $this->ShareService->getSharedReports(); |
84
|
|
|
$sharedReports = null; |
85
|
|
|
$keysToKeep = array('id', 'name', 'dataset', 'favorite', 'parent', 'type', 'isShare', 'shareId'); |
86
|
|
|
|
87
|
|
|
// get shared reports and remove duplicates |
88
|
|
|
foreach ($sharedReports as $sharedReport) { |
|
|
|
|
89
|
|
|
if (!array_search($sharedReport['id'], array_column($ownReports, 'id'))) { |
90
|
|
|
// just keep the necessary fields |
91
|
|
|
$ownReports[] = array_intersect_key($sharedReport, array_flip($keysToKeep));; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
return $ownReports; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* get own report details |
99
|
|
|
* |
100
|
|
|
* @param int $panoramaId |
101
|
|
|
* @return array |
102
|
|
|
* @throws Exception |
103
|
|
|
*/ |
104
|
|
|
public function read(int $panoramaId) |
105
|
|
|
{ |
106
|
|
|
$ownReport = $this->PanoramaMapper->readOwn($panoramaId); |
107
|
|
|
return $ownReport; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* check if own report |
112
|
|
|
* |
113
|
|
|
* @param int $panoramaId |
114
|
|
|
* @return bool |
115
|
|
|
*/ |
116
|
|
|
public function isOwn(int $panoramaId) |
117
|
|
|
{ |
118
|
|
|
$ownReport = $this->PanoramaMapper->readOwn($panoramaId); |
119
|
|
|
if (!empty($ownReport)) { |
120
|
|
|
return true; |
121
|
|
|
} else { |
122
|
|
|
return false; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* create new blank report |
128
|
|
|
* |
129
|
|
|
* @param $name |
130
|
|
|
* @param int $type |
131
|
|
|
* @param int $parent |
132
|
|
|
* @param $pages |
133
|
|
|
* @return int |
134
|
|
|
* @throws Exception |
135
|
|
|
*/ |
136
|
|
|
public function create(int $type, int $parent): int |
137
|
|
|
{ |
138
|
|
|
$reportId = $this->PanoramaMapper->create($this->l10n->t('New'), $type, $parent, '[]'); |
139
|
|
|
//$this->ActivityManager->triggerEvent($reportId, ActivityManager::OBJECT_REPORT, ActivityManager::SUBJECT_REPORT_ADD); |
140
|
|
|
return $reportId; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* update report details |
145
|
|
|
* |
146
|
|
|
* @param int $id |
147
|
|
|
* @param $name |
148
|
|
|
* @param $subheader |
149
|
|
|
* @param int $type |
150
|
|
|
* @param int $parent |
151
|
|
|
* @param $pages |
152
|
|
|
* @return bool |
153
|
|
|
* @throws Exception |
154
|
|
|
*/ |
155
|
|
|
public function update(int $id, $name, int $type, int $parent, $pages) |
156
|
|
|
{ |
157
|
|
|
return $this->PanoramaMapper->update($id, $name, $type, $parent, $pages); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Delete Dataset and all depending objects |
162
|
|
|
* |
163
|
|
|
* @param int $reportId |
164
|
|
|
* @return string |
165
|
|
|
* @throws Exception |
166
|
|
|
*/ |
167
|
|
|
public function delete(int $reportId) |
168
|
|
|
{ |
169
|
|
|
$this->PanoramaMapper->delete($reportId); |
170
|
|
|
return 'true'; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* get dataset by user |
175
|
|
|
* |
176
|
|
|
* @param string $userId |
177
|
|
|
* @return array|bool |
178
|
|
|
* @throws Exception |
179
|
|
|
*/ |
180
|
|
|
public function deleteByUser(string $userId) |
181
|
|
|
{ |
182
|
|
|
$reports = $this->ReportMapper->indexByUser($userId); |
|
|
|
|
183
|
|
|
foreach ($reports as $report) { |
184
|
|
|
$this->ShareService->deleteShareByReport($report['id']); |
185
|
|
|
$this->ThresholdMapper->deleteThresholdByReport($report['id']); |
186
|
|
|
$this->setFavorite($report['id'], 'false'); |
|
|
|
|
187
|
|
|
$this->ReportMapper->delete($report['id']); |
188
|
|
|
} |
189
|
|
|
return true; |
190
|
|
|
} |
191
|
|
|
/** |
192
|
|
|
* search for reports |
193
|
|
|
* |
194
|
|
|
* @param string $searchString |
195
|
|
|
* @return array |
196
|
|
|
*/ |
197
|
|
|
public function search(string $searchString) |
198
|
|
|
{ |
199
|
|
|
return $this->PanoramaMapper->search($searchString); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
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