1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Data 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 Marcel Scherello |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OCA\Analytics\Datasource; |
13
|
|
|
|
14
|
|
|
use OCA\Analytics\Controller\DbController; |
15
|
|
|
use OCA\Analytics\Service\DataService; |
16
|
|
|
use OCP\Files\IRootFolder; |
17
|
|
|
use OCP\Files\NotFoundException; |
18
|
|
|
use OCP\ILogger; |
19
|
|
|
|
20
|
|
|
class FileService |
21
|
|
|
{ |
22
|
|
|
private $logger; |
23
|
|
|
private $DBController; |
24
|
|
|
private $rootFolder; |
25
|
|
|
private $DataService; |
26
|
|
|
private $userId; |
27
|
|
|
|
28
|
|
|
public function __construct( |
29
|
|
|
$userId, |
30
|
|
|
ILogger $logger, |
31
|
|
|
IRootFolder $rootFolder, |
32
|
|
|
DbController $DBController, |
33
|
|
|
DataService $DataService |
34
|
|
|
) |
35
|
|
|
{ |
36
|
|
|
$this->userId = $userId; |
37
|
|
|
$this->DataService = $DataService; |
38
|
|
|
$this->logger = $logger; |
39
|
|
|
$this->DBController = $DBController; |
40
|
|
|
$this->rootFolder = $rootFolder; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the items for the selected category |
45
|
|
|
* |
46
|
|
|
* @NoAdminRequired |
47
|
|
|
* @param $datasetMetadata |
48
|
|
|
* @return array |
49
|
|
|
* @throws NotFoundException |
50
|
|
|
*/ |
51
|
|
|
public function read($datasetMetadata) |
52
|
|
|
{ |
53
|
|
|
//$this->logger->error('dataset path: ' . $datasetMetadata['link']); |
54
|
|
|
$file = $this->rootFolder->getUserFolder($datasetMetadata['user_id'])->get($datasetMetadata['link']); |
55
|
|
|
$data = $file->getContent(); |
|
|
|
|
56
|
|
|
return ['header' => '', 'data' => $data]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get the items for the selected category |
61
|
|
|
* |
62
|
|
|
* @NoAdminRequired |
63
|
|
|
* @param int $datasetId |
64
|
|
|
* @param $path |
65
|
|
|
* @return array |
66
|
|
|
* @throws NotFoundException |
67
|
|
|
*/ |
68
|
|
|
public function import(int $datasetId, $path) |
69
|
|
|
{ |
70
|
|
|
$file = $this->rootFolder->getUserFolder($this->userId)->get($path); |
71
|
|
|
$import = $file->getContent(); |
72
|
|
|
return $this->DataService->import($datasetId, $import); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
} |