1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Data Analytics |
5
|
|
|
* |
6
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
7
|
|
|
* later. See the LICENSE.md file. |
8
|
|
|
* |
9
|
|
|
* @author Marcel Scherello <[email protected]> |
10
|
|
|
* @copyright 2019 Marcel Scherello |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace OCA\Analytics\Flow; |
14
|
|
|
|
15
|
|
|
use OCA\Analytics\Controller\DataloadController; |
16
|
|
|
use OCP\EventDispatcher\Event; |
17
|
|
|
use OCP\EventDispatcher\IEventDispatcher; |
18
|
|
|
use OCP\Files\Folder; |
19
|
|
|
use OCP\Files\Node; |
20
|
|
|
use OCP\Files\NotFoundException; |
21
|
|
|
use OCP\IL10N; |
22
|
|
|
use OCP\ILogger; |
23
|
|
|
use OCP\IURLGenerator; |
24
|
|
|
use OCP\Util; |
25
|
|
|
use OCP\WorkflowEngine\IManager; |
26
|
|
|
use OCP\WorkflowEngine\IOperation; |
27
|
|
|
use OCP\WorkflowEngine\IRuleMatcher; |
|
|
|
|
28
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
29
|
|
|
|
30
|
|
|
class Operation implements IOperation |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** @var IL10N */ |
34
|
|
|
private $l; |
35
|
|
|
/** @var IURLGenerator */ |
36
|
|
|
private $urlGenerator; |
37
|
|
|
private $logger; |
38
|
|
|
private $DataloadController; |
39
|
|
|
|
40
|
|
|
public function __construct( |
41
|
|
|
IL10N $l, |
42
|
|
|
IURLGenerator $urlGenerator, |
43
|
|
|
ILogger $logger, |
44
|
|
|
DataloadController $DataloadController |
45
|
|
|
) |
46
|
|
|
{ |
47
|
|
|
$this->l = $l; |
48
|
|
|
$this->urlGenerator = $urlGenerator; |
49
|
|
|
$this->logger = $logger; |
50
|
|
|
$this->DataloadController = $DataloadController; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public static function register(IEventDispatcher $dispatcher): void |
54
|
|
|
{ |
55
|
|
|
$dispatcher->addListener(IManager::EVENT_NAME_REG_OPERATION, function (GenericEvent $event) { |
|
|
|
|
56
|
|
|
$operation = \OC::$server->query(Operation::class); |
57
|
|
|
$event->getSubject()->registerOperation($operation); |
58
|
|
|
Util::addScript('analytics', 'flow'); |
59
|
|
|
}); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getDisplayName(): string |
63
|
|
|
{ |
64
|
|
|
return $this->l->t('Data Analytics'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getDescription(): string |
68
|
|
|
{ |
69
|
|
|
return $this->l->t('Read file and add its data to an existing report'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getIcon(): string |
73
|
|
|
{ |
74
|
|
|
return $this->urlGenerator->imagePath('analytics', 'app.svg'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function isAvailableForScope(int $scope): bool |
78
|
|
|
{ |
79
|
|
|
return $scope === IManager::SCOPE_USER; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param $name |
84
|
|
|
* @param array $checks |
85
|
|
|
* @param $operation |
86
|
|
|
* @since 9.1 |
87
|
|
|
*/ |
88
|
|
|
public function validateOperation($name, array $checks, $operation): void |
89
|
|
|
{ |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatcher): void |
93
|
|
|
{ |
94
|
|
|
$flow = $ruleMatcher->getFlows(true); |
95
|
|
|
$datasetId = (int)$flow['operation']; |
96
|
|
|
|
97
|
|
|
if ($eventName === '\OCP\Files::postRename') { |
98
|
|
|
/** @var Node $oldNode */ |
99
|
|
|
list(, $node) = $event->getSubject(); |
100
|
|
|
} else { |
101
|
|
|
$node = $event->getSubject(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
list(, , $folder, $file) = explode('/', $node->getPath(), 4); |
105
|
|
|
if ($folder !== 'files' || $node instanceof Folder) { |
106
|
|
|
return; |
107
|
|
|
} |
108
|
|
|
$file = '/' . $file; |
109
|
|
|
|
110
|
|
|
$this->logger->debug("Analytics Flow Operation 115: storing file '" . $file . "' in report " . $datasetId); |
111
|
|
|
try { |
112
|
|
|
$this->DataloadController->importFile($datasetId, $file); |
113
|
|
|
} catch (NotFoundException $e) { |
114
|
|
|
return; |
115
|
|
|
} catch (\Exception $e) { |
116
|
|
|
return; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
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