Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/workflowengine/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<nextcloud min-version="18" max-version="18"/>
</dependencies>

<background-jobs>
<job>OCA\WorkflowEngine\BackgroundJobs\Rotate</job>
</background-jobs>

<repair-steps>
<post-migration>
<step>OCA\WorkflowEngine\Migration\PopulateNewlyIntroducedDatabaseFields</step>
Expand Down
3 changes: 3 additions & 0 deletions apps/workflowengine/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

return array(
'OCA\\WorkflowEngine\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\WorkflowEngine\\BackgroundJobs\\Rotate' => $baseDir . '/../lib/BackgroundJobs/Rotate.php',
'OCA\\WorkflowEngine\\Check\\AbstractStringCheck' => $baseDir . '/../lib/Check/AbstractStringCheck.php',
'OCA\\WorkflowEngine\\Check\\FileMimeType' => $baseDir . '/../lib/Check/FileMimeType.php',
'OCA\\WorkflowEngine\\Check\\FileName' => $baseDir . '/../lib/Check/FileName.php',
Expand All @@ -24,10 +25,12 @@
'OCA\\WorkflowEngine\\Controller\\RequestTime' => $baseDir . '/../lib/Controller/RequestTime.php',
'OCA\\WorkflowEngine\\Controller\\UserWorkflowsController' => $baseDir . '/../lib/Controller/UserWorkflowsController.php',
'OCA\\WorkflowEngine\\Entity\\File' => $baseDir . '/../lib/Entity/File.php',
'OCA\\WorkflowEngine\\Helper\\LogContext' => $baseDir . '/../lib/Helper/LogContext.php',
'OCA\\WorkflowEngine\\Helper\\ScopeContext' => $baseDir . '/../lib/Helper/ScopeContext.php',
'OCA\\WorkflowEngine\\Manager' => $baseDir . '/../lib/Manager.php',
'OCA\\WorkflowEngine\\Migration\\PopulateNewlyIntroducedDatabaseFields' => $baseDir . '/../lib/Migration/PopulateNewlyIntroducedDatabaseFields.php',
'OCA\\WorkflowEngine\\Migration\\Version2000Date20190808074233' => $baseDir . '/../lib/Migration/Version2000Date20190808074233.php',
'OCA\\WorkflowEngine\\Service\\Logger' => $baseDir . '/../lib/Service/Logger.php',
'OCA\\WorkflowEngine\\Service\\RuleMatcher' => $baseDir . '/../lib/Service/RuleMatcher.php',
'OCA\\WorkflowEngine\\Settings\\ASettings' => $baseDir . '/../lib/Settings/ASettings.php',
'OCA\\WorkflowEngine\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
Expand Down
3 changes: 3 additions & 0 deletions apps/workflowengine/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ComposerStaticInitWorkflowEngine

public static $classMap = array (
'OCA\\WorkflowEngine\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\WorkflowEngine\\BackgroundJobs\\Rotate' => __DIR__ . '/..' . '/../lib/BackgroundJobs/Rotate.php',
'OCA\\WorkflowEngine\\Check\\AbstractStringCheck' => __DIR__ . '/..' . '/../lib/Check/AbstractStringCheck.php',
'OCA\\WorkflowEngine\\Check\\FileMimeType' => __DIR__ . '/..' . '/../lib/Check/FileMimeType.php',
'OCA\\WorkflowEngine\\Check\\FileName' => __DIR__ . '/..' . '/../lib/Check/FileName.php',
Expand All @@ -39,10 +40,12 @@ class ComposerStaticInitWorkflowEngine
'OCA\\WorkflowEngine\\Controller\\RequestTime' => __DIR__ . '/..' . '/../lib/Controller/RequestTime.php',
'OCA\\WorkflowEngine\\Controller\\UserWorkflowsController' => __DIR__ . '/..' . '/../lib/Controller/UserWorkflowsController.php',
'OCA\\WorkflowEngine\\Entity\\File' => __DIR__ . '/..' . '/../lib/Entity/File.php',
'OCA\\WorkflowEngine\\Helper\\LogContext' => __DIR__ . '/..' . '/../lib/Helper/LogContext.php',
'OCA\\WorkflowEngine\\Helper\\ScopeContext' => __DIR__ . '/..' . '/../lib/Helper/ScopeContext.php',
'OCA\\WorkflowEngine\\Manager' => __DIR__ . '/..' . '/../lib/Manager.php',
'OCA\\WorkflowEngine\\Migration\\PopulateNewlyIntroducedDatabaseFields' => __DIR__ . '/..' . '/../lib/Migration/PopulateNewlyIntroducedDatabaseFields.php',
'OCA\\WorkflowEngine\\Migration\\Version2000Date20190808074233' => __DIR__ . '/..' . '/../lib/Migration/Version2000Date20190808074233.php',
'OCA\\WorkflowEngine\\Service\\Logger' => __DIR__ . '/..' . '/../lib/Service/Logger.php',
'OCA\\WorkflowEngine\\Service\\RuleMatcher' => __DIR__ . '/..' . '/../lib/Service/RuleMatcher.php',
'OCA\\WorkflowEngine\\Settings\\ASettings' => __DIR__ . '/..' . '/../lib/Settings/ASettings.php',
'OCA\\WorkflowEngine\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
Expand Down
15 changes: 15 additions & 0 deletions apps/workflowengine/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
namespace OCA\WorkflowEngine\AppInfo;

use OCA\WorkflowEngine\Controller\RequestTime;
use OCA\WorkflowEngine\Helper\LogContext;
use OCA\WorkflowEngine\Manager;
use OCA\WorkflowEngine\Service\Logger;
use OCP\AppFramework\QueryException;
use OCP\EventDispatcher\Event;
use OCP\Template;
Expand Down Expand Up @@ -97,6 +99,16 @@ function ($event) use ($eventName, $operationClass, $entityClass) {
$ruleMatcher->setEntity($entity);
$ruleMatcher->setOperation($operation);

$ctx = new LogContext();
$ctx
->setOperation($operation)
->setEntity($entity)
->setEventName($eventName);

/** @var Logger $flowLogger */
$flowLogger = $this->getContainer()->query(Logger::class);
$flowLogger->logEventInit($ctx);

if ($event instanceof Event) {
$entity->prepareRuleMatcher($ruleMatcher, $eventName, $event);
$operation->onEvent($eventName, $event, $ruleMatcher);
Expand All @@ -117,6 +129,7 @@ function ($event) use ($eventName, $operationClass, $entityClass) {
]
);
}
$flowLogger->logEventDone($ctx);

} catch (QueryException $e) {
// Ignore query exceptions since they might occur when an entity/operation were setup before by an app that is disabled now
Expand All @@ -126,5 +139,7 @@ function ($event) use ($eventName, $operationClass, $entityClass) {
}, $eventNames ?? []);
}
}


}
}
53 changes: 53 additions & 0 deletions apps/workflowengine/lib/BackgroundJobs/Rotate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* @copyright Copyright (c) 2018 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\WorkflowEngine\BackgroundJobs;

use OC\BackgroundJob\TimedJob;
use OCA\WorkflowEngine\AppInfo\Application;
use OCP\Log\RotationTrait;

class Rotate extends TimedJob {
use RotationTrait;

public function __construct() {
$this->setInterval(60*60*3);
}

protected function run($argument) {
$config = \OC::$server->getConfig();
$default = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/flow.log';
$this->filePath = trim((string)$config->getAppValue(Application::APP_ID, 'logfile', $default));

if($this->filePath === '') {
// disabled, nothing to do
return;
}

$this->maxSize = $config->getSystemValue('log_rotate_size', 100 * 1024 * 1024);

if($this->shouldRotateBySize()) {
$this->rotate();
}
}
}
95 changes: 95 additions & 0 deletions apps/workflowengine/lib/Helper/LogContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\WorkflowEngine\Helper;

use OCP\WorkflowEngine\IEntity;
use OCP\WorkflowEngine\IManager;
use OCP\WorkflowEngine\IOperation;

class LogContext {
/** @var array */
protected $details;

public function setDescription(string $description): LogContext {
$this->details['message'] = $description;
return $this;
}

public function setScopes(array $scopes): LogContext {
$this->details['scopes'] = [];
foreach ($scopes as $scope) {
if($scope instanceof ScopeContext) {
switch($scope->getScope()) {
case IManager::SCOPE_ADMIN:
$this->details['scopes'][] = ['scope' => 'admin'];
break;
case IManager::SCOPE_USER:
$this->details['scopes'][] = [
'scope' => 'user',
'uid' => $scope->getScopeId(),
];
break;
default:
continue;
}
}
}
return $this;
}

public function setOperation(?IOperation $operation): LogContext {
if($operation instanceof IOperation) {
$this->details['operation'] = [
'class' => get_class($operation),
'name' => $operation->getDisplayName(),
];
}
return $this;
}

public function setEntity(?IEntity $entity): LogContext {
if($entity instanceof IEntity) {
$this->details['entity'] = [
'class' => get_class($entity),
'name' => $entity->getName(),
];
}
return $this;
}

public function setConfiguration(array $configuration): LogContext {
$this->details['configuration'] = $configuration;
return $this;
}

public function setEventName(string $eventName): LogContext {
$this->details['eventName'] = $eventName;
return $this;
}

public function getDetails(): array {
return $this->details;
}
}
9 changes: 8 additions & 1 deletion apps/workflowengine/lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\WorkflowEngine\Check\UserGroupMembership;
use OCA\WorkflowEngine\Entity\File;
use OCA\WorkflowEngine\Helper\ScopeContext;
use OCA\WorkflowEngine\Service\Logger;
use OCA\WorkflowEngine\Service\RuleMatcher;
use OCP\AppFramework\QueryException;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -127,7 +128,13 @@ public function __construct(
}

public function getRuleMatcher(): IRuleMatcher {
return new RuleMatcher($this->session, $this->container, $this->l, $this);
return new RuleMatcher(
$this->session,
$this->container,
$this->l,
$this,
$this->container->query(Logger::class)
);
}

public function getAllConfiguredEvents() {
Expand Down
Loading