Skip to content

Commit

Permalink
Task: Add backend user resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Lehmann committed Sep 23, 2019
1 parent 0b9ec2b commit c3f68a9
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 4 deletions.
24 changes: 24 additions & 0 deletions Classes/Domain/Model/Dto/ResolverData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* LICENSE.txt file that was distributed with this source code.
*/

use T3Monitor\T3monitoring\Domain\Model\Rule;

class ResolverData
{
/**
Expand All @@ -25,6 +27,11 @@ class ResolverData
*/
protected $responseHeaders;

/**
* @var Rule
*/
protected $rule;

public function __construct(array $client, array $response, array $responseHeaders)
{
$this->client = $client;
Expand Down Expand Up @@ -79,4 +86,21 @@ public function setResponseHeaders(array $responseHeaders)
{
$this->responseHeaders = $responseHeaders;
}

/**
* @return Rule
*/
public function getRule()
{
return $this->rule;
}

/**
* @param Rule $rule
*/
public function setRule(Rule $rule)
{
$this->rule = $rule;
}

}
43 changes: 43 additions & 0 deletions Classes/Resolver/BackendUserResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace T3Monitor\T3monitoring\Resolver;

use TYPO3\CMS\Core\Utility\GeneralUtility;

class BackendUserResolver extends BaseResolver
{
const TITLE = 'Backend user';

public function setValueForComparison()
{
$this->valueForComparison = $this->resolverData->getResponse()['backendUser'];
}

public function getProviderArguments()
{
return GeneralUtility::trimExplode(PHP_EOL, $this->argument, true);
}

protected function isActiveOperator()
{
if (!isset($this->resolverData->getResponse()['backendUser'])) {
return;
}

$unwantedActiveUsers = array_intersect($this->getProviderArguments(),
$this->resolverData->getResponse()['backendUser']);

if (count($unwantedActiveUsers) > 0) {
$this->addRuleData($unwantedActiveUsers);
}
return $unwantedActiveUsers !== 0;
}

protected function addRuleData($backendUsers)
{
$update = $this->resolverData->getResponse();
$messageCategory = $this->resolverData->getRule()->getMessageCategory();
$update['extra'][$messageCategory][$this->resolverData->getRule()->getTitle()] = implode(',',
$backendUsers);
$this->resolverData->setResponse($update);
}
}
7 changes: 6 additions & 1 deletion Classes/Service/CheckResultService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public function getProviderArguments()
foreach ($checks as $check) {
$providerArguments = $this->getResolver($check)->getProviderArguments();
if ($providerArguments) {
$allProviderArguments[$check->getType()][] = $providerArguments;
if (is_array($providerArguments)) {
$allProviderArguments[$check->getType()] = $providerArguments;
} else {
$allProviderArguments[$check->getType()][] = $providerArguments;
}
}
}

Expand All @@ -82,6 +86,7 @@ public function createCheckResult(ResolverData $resolverData)
$checkResult->setClient($resolverData->getClient()['uid']);

foreach ($this->rules as $rule) {
$this->resolverData->setRule($rule);
$checkFailureCriterias = true;
foreach ($rule->getExecutionCriteria() as $executionCriteria) {
$checkFailureCriterias = $this->runCheck($executionCriteria);
Expand Down
6 changes: 4 additions & 2 deletions Classes/Service/Import/ClientImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ protected function importSingleClient(array $row)
'error_count' => 0
];

$checkResultCreationDemand = new ResolverData($row, $json, $responseHeaders);
$checkResult = $this->checkResultService->createCheckResult($checkResultCreationDemand);
$resolverData = new ResolverData($row, $json, $responseHeaders);
$checkResult = $this->checkResultService->createCheckResult($resolverData);
$json = $resolverData->getResponse();

$update['earlier_check_result'] = $row['check_result'];
$update['check_result'] = $checkResult->getUid();

Expand Down
18 changes: 18 additions & 0 deletions Configuration/TCA/tx_t3monitoring_domain_model_check.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@
]
]
],
'backendUser' => [
'showitem' => 'hidden, title, type, argument, operator',
'columnsOverrides' => [
'argument' => [
'label' => 'List of backend users separated by newline',
'config' => [
'type' => 'text'
]
],
'operator' => [
'config' => [
'items' => [
['is active', 'isActive'],
]
]
],
]
],
],
'columns' => [
'hidden' => [
Expand Down
1 change: 1 addition & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function ($extKey) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][$extKey]
= \T3Monitor\T3monitoring\Hooks\DataHandlerHook::class;

$GLOBALS['TYPO3_CONF_VARS']['EXT'][$extKey]['resolver']['backendUser'] = \T3Monitor\T3monitoring\Resolver\BackendUserResolver::class;
$GLOBALS['TYPO3_CONF_VARS']['EXT'][$extKey]['resolver']['configurationValue'] = \T3Monitor\T3monitoring\Resolver\ConfigurationResolver::class;
$GLOBALS['TYPO3_CONF_VARS']['EXT'][$extKey]['resolver']['header'] = \T3Monitor\T3monitoring\Resolver\HeaderResolver::class;
$GLOBALS['TYPO3_CONF_VARS']['EXT'][$extKey]['resolver']['extensionState'] = \T3Monitor\T3monitoring\Resolver\ExtensionStateResolver::class;
Expand Down
2 changes: 1 addition & 1 deletion ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ CREATE TABLE tx_t3monitoring_domain_model_check (

title varchar(255) DEFAULT '' NOT NULL,
type varchar(255) DEFAULT '' NOT NULL,
argument varchar(255) DEFAULT '' NOT NULL,
argument text DEFAULT '' NOT NULL,
operator varchar(255) DEFAULT '' NOT NULL,
value varchar(255) DEFAULT '' NOT NULL,

Expand Down

0 comments on commit c3f68a9

Please sign in to comment.