Skip to content

Commit

Permalink
NC 18 Workflow integration #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Rello committed Jan 9, 2020
1 parent dd544ed commit 5f54962
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions lib/Flow/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@

namespace OCA\Analytics\Flow;

use OCA\Analytics\Controller\DataloadController;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IURLGenerator;
Expand All @@ -22,7 +26,6 @@
use OCP\WorkflowEngine\IOperation;
use OCP\WorkflowEngine\IRuleMatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
use UnexpectedValueException;

class Operation implements IOperation
{
Expand All @@ -32,16 +35,19 @@ class Operation implements IOperation
/** @var IURLGenerator */
private $urlGenerator;
private $logger;
private $DataloadController;

public function __construct(
IL10N $l,
IURLGenerator $urlGenerator,
ILogger $logger
ILogger $logger,
DataloadController $DataloadController
)
{
$this->l = $l;
$this->urlGenerator = $urlGenerator;
$this->logger = $logger;
$this->DataloadController = $DataloadController;
}

public static function register(IEventDispatcher $dispatcher): void
Expand All @@ -55,12 +61,12 @@ public static function register(IEventDispatcher $dispatcher): void

public function getDisplayName(): string
{
return $this->l->t('Write to Analytics');
return $this->l->t('Add to Analytics');
}

public function getDescription(): string
{
return $this->l->t('Writes data to report');
return $this->l->t('Read a file and add its data to an existing report');
}

public function getIcon(): string
Expand All @@ -70,22 +76,49 @@ public function getIcon(): string

public function isAvailableForScope(int $scope): bool
{
return true;
return $scope === IManager::SCOPE_USER;
}

/**
* Validates whether a configured workflow rule is valid. If it is not,
* an `\UnexpectedValueException` is supposed to be thrown.
*
* @throws UnexpectedValueException
* @param $name
* @param array $checks
* @param $operation
* @since 9.1
*/
public function validateOperation($name, array $checks, $operation): void
{
$this->logger->debug("validateOperation");
}

public function onEvent(string $eventName, Event $event, IRuleMatcher $ruleMatcher): void
{
$this->logger->debug("Test Flow Operation");
$flow = $ruleMatcher->getFlows(true);
$datasetId = (int)$flow['operation'];

try {
if ($eventName === '\OCP\Files::postRename') {
/** @var Node $oldNode */
list(, $node) = $event->getSubject();
} else {
$node = $event->getSubject();
}

list(, , $folder, $file) = explode('/', $node->getPath(), 4);
if ($folder !== 'files' || $node instanceof Folder) {
return;
}
$file = '/' . $file;

$this->logger->debug("Flow Operation 119: storing file '" . $file . "' in report " . $datasetId);
try {
$this->DataloadController->importFile($datasetId, $file);
} catch (NotFoundException $e) {
} catch (\Exception $e) {
}
} catch (\OCP\Files\NotFoundException $e) {
}
}
}
Binary file added screenshots/flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5f54962

Please sign in to comment.