Skip to content

Commit

Permalink
add removeQueued
Browse files Browse the repository at this point in the history
  • Loading branch information
noodle69 authored and Emmanuel committed Jun 21, 2018
1 parent 72ea670 commit f602473
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
31 changes: 29 additions & 2 deletions src/bundle/Controller/CronController.php
Expand Up @@ -91,11 +91,11 @@ public function listAction(): Response
* Update cron informations.
*
* @param Request $request
* @param $alias
* @param string $alias
*
* @return Response
*/
public function updateAction(Request $request, $alias): Response
public function updateAction(Request $request, string $alias): Response
{
$this->permissionAccess('uicron', 'update');

Expand Down Expand Up @@ -146,6 +146,33 @@ public function updateAction(Request $request, $alias): Response
]);
}

/**
* @param Request $request
* @param string $alias
* @return Response
*/
public function resetAction(Request $request, string $alias): Response
{
$this->permissionAccess('uicron', 'reset');

$cron = $this->cronService->getCron($alias);
if (!$cron) {
return $this->redirect('ezplatform.dashboard');
}

$this->cronService->removeQueud($alias);

$this->notificationHandler->info(
$this->translator->trans(
'edgar.ezuicron.reset.info',
[],
'edgarezuicron'
)
);

return $this->redirect('ezplatform.dashboard');
}

/**
* Check if user has permissions to access cron functions.
*
Expand Down
1 change: 1 addition & 0 deletions src/bundle/Resources/config/policies.yml
@@ -1,4 +1,5 @@
uicron:
list: ~
update: ~
reset: ~
dashboard: ~
10 changes: 7 additions & 3 deletions src/bundle/Resources/config/routing.yml
@@ -1,10 +1,14 @@
edgar.ezuicron.list:
path: /cron/list
path: /list
defaults:
_controller: 'EdgarEzUICronBundle:Cron:list'

edgar.ezuicron.update:
path: /cron/update/{alias}
path: /update/{alias}
defaults:
alias: null
_controller: 'EdgarEzUICronBundle:Cron:update'

edgar.ezuicron.reset:
path: /reset/{alias}
defaults:
_controller: 'EdgarEzUICronBundle:Cron:reset'
6 changes: 6 additions & 0 deletions src/bundle/Resources/views/dashboard/tab/cron.html.twig
Expand Up @@ -8,6 +8,7 @@
<th>{{ 'edgarezcron.status.th.started'|trans|desc('Started') }}</th>
<th>{{ 'edgarezcron.status.th.ended'|trans|desc('Ended') }}</th>
<th>{{ 'edgarezcron.status.th.status'|trans|desc('Status') }}</th>
<th></th>
</tr>
</thead>
<tbody>
Expand All @@ -25,6 +26,11 @@
<td>{{ cron.started|localizeddate('short', 'short', app.request.locale) }}</td>
<td>{{ cron.ended|localizeddate('short', 'short', app.request.locale) }}</td>
<td>{{ cron.status }}</td>
<td>
{% if cron.reset %}
<a href="{{ path('edgar.ezuicron.reset', {'alias': cron.alias}) }}">{{ 'edgarezcron.status.td.reset'|trans|desc('Reset') }}</a>
{% endif %}
</td>
</tr>
{% endfor %}
{% endif %}
Expand Down
8 changes: 8 additions & 0 deletions src/bundle/Service/EzCronService.php
Expand Up @@ -176,6 +176,14 @@ public function addQueued(string $alias)
$this->cronService->addQueued($alias);
}

/**
* @param string $alias
*/
public function removeQueud(string $alias)
{
$this->cronService->removeQueued($alias);
}

/**
* Run crons in queue.
*
Expand Down
9 changes: 6 additions & 3 deletions src/lib/Tab/Dashboard/CronTab.php
Expand Up @@ -76,12 +76,11 @@ public function getOrder(): int

/**
* @param array $parameters
*
* @return string
*
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
public function renderView(array $parameters): string
{
Expand All @@ -96,16 +95,19 @@ public function renderView(array $parameters): string
$cronRows = [];
foreach ($crons as $cron) {
$cronStatus = '';
$cronReset = false;
if ($cron instanceof EdgarCron) {
switch ($cron->getStatus()) {
case EdgarCronRepository::STATUS_INIT:
$cronStatus = $this->translator->trans('Init', [], 'edgarezcron');
$cronReset = true;
break;
case EdgarCronRepository::STATUS_OK:
$cronStatus = $this->translator->trans('OK', [], 'edgarezcron');
break;
case EdgarCronRepository::STATUS_ERROR:
$cronStatus = $this->translator->trans('Error', [], 'edgarezcron');
$cronReset = true;
break;
default:
$cronStatus = '';
Expand All @@ -125,6 +127,7 @@ public function renderView(array $parameters): string
? $cron->getEnded() : false)
: false,
'status' => $cronStatus,
'reset' => $cronReset,
];
}

Expand All @@ -136,8 +139,8 @@ public function renderView(array $parameters): string
/**
* @param string $module
* @param string $function
*
* @return bool
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
*/
protected function permissionAccess(string $module, string $function): bool
{
Expand Down

0 comments on commit f602473

Please sign in to comment.