1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* 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-2022 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\IURLGenerator; |
|
|
|
|
23
|
|
|
use OCP\Util; |
|
|
|
|
24
|
|
|
use OCP\WorkflowEngine\IManager; |
|
|
|
|
25
|
|
|
use OCP\WorkflowEngine\IOperation; |
|
|
|
|
26
|
|
|
use OCP\WorkflowEngine\IRuleMatcher; |
|
|
|
|
27
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
28
|
|
|
use OCP\WorkflowEngine\Events\RegisterOperationsEvent; |
|
|
|
|
29
|
|
|
use Psr\Container\ContainerInterface; |
|
|
|
|
30
|
|
|
|
31
|
|
|
class FlowOperation implements IOperation |
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
/** @var IL10N */ |
35
|
|
|
private $l; |
36
|
|
|
/** @var IURLGenerator */ |
37
|
|
|
private $urlGenerator; |
38
|
|
|
private $logger; |
39
|
|
|
private $DataloadController; |
40
|
|
|
private $eventDispatcher; |
41
|
|
|
private ContainerInterface $container; |
42
|
|
|
|
43
|
|
|
public function __construct( |
44
|
|
|
IL10N $l, |
45
|
|
|
IURLGenerator $urlGenerator, |
46
|
|
|
LoggerInterface $logger, |
47
|
|
|
DataloadController $DataloadController, |
48
|
|
|
IEventDispatcher $eventDispatcher, |
49
|
|
|
ContainerInterface $container |
50
|
|
|
) |
51
|
|
|
{ |
52
|
|
|
$this->l = $l; |
53
|
|
|
$this->urlGenerator = $urlGenerator; |
54
|
|
|
$this->logger = $logger; |
55
|
|
|
$this->DataloadController = $DataloadController; |
56
|
|
|
$this->eventDispatcher = $eventDispatcher; |
57
|
|
|
$this->container = $container; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function handle(Event $event): void { |
61
|
|
|
if (!$event instanceof RegisterOperationsEvent) { |
62
|
|
|
return; |
63
|
|
|
} |
64
|
|
|
$event->registerOperation($this->container->get(FlowOperation::class)); |
65
|
|
|
Util::addScript('analytics', 'flow'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getDisplayName(): string |
69
|
|
|
{ |
70
|
|
|
return $this->l->t('Analytics'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getDescription(): string |
74
|
|
|
{ |
75
|
|
|
return $this->l->t('Read file and add its data to an existing dataset'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getIcon(): string |
79
|
|
|
{ |
80
|
|
|
return $this->urlGenerator->imagePath('analytics', 'app.svg'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function isAvailableForScope(int $scope): bool |
84
|
|
|
{ |
85
|
|
|
return $scope === IManager::SCOPE_USER; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param $name |
90
|
|
|
* @param array $checks |
91
|
|
|
* @param $operation |
92
|
|
|
* @since 9.1 |
93
|
|
|
*/ |
94
|
|
|
public function validateOperation($name, array $checks, $operation): void |
95
|
|
|
{ |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatcher): void |
99
|
|
|
{ |
100
|
|
|
$flow = $ruleMatcher->getFlows(true); |
101
|
|
|
$datasetId = (int)$flow['operation']; |
102
|
|
|
|
103
|
|
|
if ($eventName === '\OCP\Files::postRename') { |
104
|
|
|
/** @var Node $oldNode */ |
105
|
|
|
list(, $node) = $event->getSubject(); |
106
|
|
|
} else { |
107
|
|
|
$node = $event->getSubject(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
list(, , $folder, $file) = explode('/', $node->getPath(), 4); |
111
|
|
|
if ($folder !== 'files' || $node instanceof Folder) { |
112
|
|
|
return; |
113
|
|
|
} |
114
|
|
|
$file = '/' . $file; |
115
|
|
|
|
116
|
|
|
try { |
117
|
|
|
$this->DataloadController->importFile($datasetId, $file, true); |
118
|
|
|
} catch (NotFoundException $e) { |
119
|
|
|
return; |
120
|
|
|
} catch (\Exception $e) { |
121
|
|
|
return; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
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