Rello /
analytics
| 1 | <?php |
||
| 2 | declare(strict_types=1); |
||
| 3 | /** |
||
| 4 | * Analytics |
||
| 5 | * |
||
| 6 | * SPDX-FileCopyrightText: 2019-2022 Marcel Scherello |
||
| 7 | * SPDX-License-Identifier: AGPL-3.0-or-later |
||
| 8 | */ |
||
| 9 | |||
| 10 | namespace OCA\Analytics\Flow; |
||
| 11 | |||
| 12 | use OCA\Analytics\Controller\DataloadController; |
||
| 13 | use OCP\EventDispatcher\Event; |
||
|
0 ignored issues
–
show
|
|||
| 14 | use OCP\EventDispatcher\IEventDispatcher; |
||
|
0 ignored issues
–
show
The type
OCP\EventDispatcher\IEventDispatcher was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 15 | use OCP\Files\Folder; |
||
|
0 ignored issues
–
show
The type
OCP\Files\Folder was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 16 | use OCP\Files\Node; |
||
|
0 ignored issues
–
show
The type
OCP\Files\Node was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 17 | use OCP\Files\NotFoundException; |
||
|
0 ignored issues
–
show
The type
OCP\Files\NotFoundException was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 18 | use OCP\IL10N; |
||
|
0 ignored issues
–
show
The type
OCP\IL10N was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 19 | use OCP\IURLGenerator; |
||
|
0 ignored issues
–
show
The type
OCP\IURLGenerator was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 20 | use OCP\Util; |
||
|
0 ignored issues
–
show
The type
OCP\Util was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 21 | use OCP\WorkflowEngine\IManager; |
||
|
0 ignored issues
–
show
The type
OCP\WorkflowEngine\IManager was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 22 | use OCP\WorkflowEngine\IOperation; |
||
|
0 ignored issues
–
show
The type
OCP\WorkflowEngine\IOperation was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 23 | use OCP\WorkflowEngine\IRuleMatcher; |
||
|
0 ignored issues
–
show
The type
OCP\WorkflowEngine\IRuleMatcher was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 24 | use Psr\Log\LoggerInterface; |
||
|
0 ignored issues
–
show
The type
Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 25 | use OCP\WorkflowEngine\Events\RegisterOperationsEvent; |
||
|
0 ignored issues
–
show
The type
OCP\WorkflowEngine\Events\RegisterOperationsEvent was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 26 | use Psr\Container\ContainerInterface; |
||
|
0 ignored issues
–
show
The type
Psr\Container\ContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 27 | |||
| 28 | class FlowOperation implements IOperation |
||
| 29 | { |
||
| 30 | |||
| 31 | /** @var IL10N */ |
||
| 32 | private $l; |
||
| 33 | /** @var IURLGenerator */ |
||
| 34 | private $urlGenerator; |
||
| 35 | private $logger; |
||
| 36 | private $DataloadController; |
||
| 37 | private $eventDispatcher; |
||
| 38 | private ContainerInterface $container; |
||
| 39 | |||
| 40 | public function __construct( |
||
| 41 | IL10N $l, |
||
| 42 | IURLGenerator $urlGenerator, |
||
| 43 | LoggerInterface $logger, |
||
| 44 | DataloadController $DataloadController, |
||
| 45 | IEventDispatcher $eventDispatcher, |
||
| 46 | ContainerInterface $container |
||
| 47 | ) |
||
| 48 | { |
||
| 49 | $this->l = $l; |
||
| 50 | $this->urlGenerator = $urlGenerator; |
||
| 51 | $this->logger = $logger; |
||
| 52 | $this->DataloadController = $DataloadController; |
||
| 53 | $this->eventDispatcher = $eventDispatcher; |
||
| 54 | $this->container = $container; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function handle(Event $event): void { |
||
| 58 | if (!$event instanceof RegisterOperationsEvent) { |
||
| 59 | return; |
||
| 60 | } |
||
| 61 | $event->registerOperation($this->container->get(FlowOperation::class)); |
||
| 62 | Util::addScript('analytics', 'flow'); |
||
| 63 | } |
||
| 64 | |||
| 65 | public function getDisplayName(): string |
||
| 66 | { |
||
| 67 | return $this->l->t('Analytics'); |
||
| 68 | } |
||
| 69 | |||
| 70 | public function getDescription(): string |
||
| 71 | { |
||
| 72 | return $this->l->t('Read file and add its data to an existing dataset'); |
||
| 73 | } |
||
| 74 | |||
| 75 | public function getIcon(): string |
||
| 76 | { |
||
| 77 | return $this->urlGenerator->imagePath('analytics', 'app.svg'); |
||
| 78 | } |
||
| 79 | |||
| 80 | public function isAvailableForScope(int $scope): bool |
||
| 81 | { |
||
| 82 | return $scope === IManager::SCOPE_USER; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param $name |
||
| 87 | * @param array $checks |
||
| 88 | * @param $operation |
||
| 89 | * @since 9.1 |
||
| 90 | */ |
||
| 91 | public function validateOperation($name, array $checks, $operation): void |
||
| 92 | { |
||
| 93 | } |
||
| 94 | |||
| 95 | public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatcher): void |
||
| 96 | { |
||
| 97 | $flow = $ruleMatcher->getFlows(true); |
||
| 98 | $datasetId = (int)$flow['operation']; |
||
| 99 | |||
| 100 | if ($eventName === '\OCP\Files::postRename') { |
||
| 101 | /** @var Node $oldNode */ |
||
| 102 | list(, $node) = $event->getSubject(); |
||
| 103 | } else { |
||
| 104 | $node = $event->getSubject(); |
||
| 105 | } |
||
| 106 | |||
| 107 | list(, , $folder, $file) = explode('/', $node->getPath(), 4); |
||
| 108 | if ($folder !== 'files' || $node instanceof Folder) { |
||
| 109 | return; |
||
| 110 | } |
||
| 111 | $file = '/' . $file; |
||
| 112 | |||
| 113 | try { |
||
| 114 | $this->DataloadController->importFile($datasetId, $file, true); |
||
| 115 | } catch (NotFoundException $e) { |
||
| 116 | return; |
||
| 117 | } catch (\Exception $e) { |
||
| 118 | return; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 |
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