2 Commits

Author SHA1 Message Date
Jérémy
2274bbf5e5 Changelog for 3.2.0 2023-04-11 09:47:36 +02:00
jeremycr
4a0070dc04 Improvements on datetime handling + #38 + #39 (#41) 2023-04-11 09:39:57 +02:00
29 changed files with 183 additions and 57 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ composer.lock
.phpunit.result.cache
.php_cs.cache
.php_cs
.php-cs-fixer.cache

View File

@@ -2,7 +2,7 @@
$finder = PhpCsFixer\Finder::create()->in(__DIR__.'/src');
return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'declare_strict_types' => true,

View File

@@ -1,3 +1,9 @@
# Version 3.2.0
* Fixed History page pagination is hidden by footer on Ibexa 3.3 #38
* Added filter on history page to filter out jobs with 0 items
* Date and times will now be displayed using the user defined timezone, and stored using php timezone
# Version 3.1.0
* Allow `LocationCreateStruct` objects inside the `$locations` argument of `ContentCreateStructure` to have more control over the created locations.

View File

@@ -53,7 +53,10 @@
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
},
"extra": {
"branch-alias": {

View File

@@ -12,7 +12,6 @@ use CodeRhapsodie\EzDataflowBundle\Gateway\JobGateway;
use CodeRhapsodie\EzDataflowBundle\Gateway\ScheduledDataflowGateway;
use Doctrine\DBAL\Query\QueryBuilder;
use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute;
use EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface;
use EzSystems\EzPlatformAdminUiBundle\Controller\Controller;
use Pagerfanta\Adapter\DoctrineDbalAdapter;
use Pagerfanta\Pagerfanta;
@@ -27,15 +26,12 @@ class DashboardController extends Controller
{
/** @var JobGateway */
private $jobGateway;
/** @var NotificationHandlerInterface */
private $notificationHandler;
/** @var ScheduledDataflowGateway */
private $scheduledDataflowGateway;
public function __construct(JobGateway $jobGateway, NotificationHandlerInterface $notificationHandler, ScheduledDataflowGateway $scheduledDataflowGateway)
public function __construct(JobGateway $jobGateway, ScheduledDataflowGateway $scheduledDataflowGateway)
{
$this->jobGateway = $jobGateway;
$this->notificationHandler = $notificationHandler;
$this->scheduledDataflowGateway = $scheduledDataflowGateway;
}
@@ -108,9 +104,11 @@ class DashboardController extends Controller
public function history(Request $request): Response
{
$this->denyAccessUnlessGranted(new Attribute('ezdataflow', 'view'));
$filter = (int) $request->query->get('filter', JobGateway::FILTER_NONE);
return $this->render('@ezdesign/ezdataflow/Dashboard/history.html.twig', [
'pager' => $this->getPager($this->jobGateway->getListQueryForAdmin(), $request),
'pager' => $this->getPager($this->jobGateway->getListQueryForAdmin($filter), $request),
'filter' => $filter,
]);
}
@@ -120,9 +118,11 @@ class DashboardController extends Controller
public function getHistoryPage(Request $request): Response
{
$this->denyAccessUnlessGranted(new Attribute('ezdataflow', 'view'));
$filter = (int) $request->query->get('filter', JobGateway::FILTER_NONE);
return $this->render('@ezdesign/ezdataflow/Dashboard/history.html.twig', [
'pager' => $this->getPager($this->jobGateway->getListQueryForAdmin(), $request),
'pager' => $this->getPager($this->jobGateway->getListQueryForAdmin($filter), $request),
'filter' => $filter,
]);
}
@@ -143,6 +143,7 @@ class DashboardController extends Controller
{
$pager = new Pagerfanta(new DoctrineDbalAdapter($query, function ($queryBuilder) {
return $queryBuilder->select('COUNT(DISTINCT id) AS total_results')
->resetQueryPart('orderBy')
->setMaxResults(1);
}));
$pager->setMaxPerPage(20);

View File

@@ -53,10 +53,6 @@ class JobController extends Controller
/**
* @Route("/details/log/{id}", name="coderhapsodie.ezdataflow.job.log")
*
* @param int $id
*
* @return Response
*/
public function displayLog(int $id): Response
{

View File

@@ -58,7 +58,6 @@ class ScheduledDataflowController extends Controller
if ($form->isSubmitted() && $form->isValid()) {
/** @var ScheduledDataflow $newWorkflow */
$newWorkflow = $form->getData();
try {
$this->scheduledDataflowGateway->save($newWorkflow);
$this->notificationHandler->success($this->translator->trans('coderhapsodie.ezdataflow.workflow.create.success'));

View File

@@ -26,7 +26,7 @@ abstract class AbstractFieldComparator implements FieldComparatorInterface
}
/**
* Returns true if values are equals, false otherwise
* Returns true if values are equals, false otherwise.
*/
abstract protected function compareValues(Value $currentValue, Value $newValue): bool;
}

View File

@@ -9,8 +9,6 @@ class InvalidArgumentTypeException extends \Exception
/**
* @param string|array $expectedTypes
* @param mixed $received
*
* @return InvalidArgumentTypeException
*/
public static function create($expectedTypes, $received): self
{

View File

@@ -6,9 +6,6 @@ namespace CodeRhapsodie\EzDataflowBundle\Exception;
class UnknownFieldException extends \Exception
{
/**
* @return UnknownFieldException
*/
public static function create(string $fieldIdentifier, string $contentTypeIdentifier): self
{
return new self(sprintf(

View File

@@ -22,7 +22,6 @@ class NotModifiedContentFilter
/** @var FieldComparatorInterface */
private $comparator;
public function __construct(ContentService $contentService, FieldComparatorInterface $comparator)
{
$this->contentService = $contentService;
@@ -43,7 +42,7 @@ class NotModifiedContentFilter
foreach ($data->getFields() as $identifier => $hash) {
$field = $content->getField($identifier, $data->getLanguageCode());
if ($field === null || !$this->comparator->compare($field, $hash)) {
if (null === $field || !$this->comparator->compare($field, $hash)) {
// At least one field is different, continue the dataflow.
return $data;
}
@@ -51,12 +50,13 @@ class NotModifiedContentFilter
// All fields are identical, filter this item out.
$this->log('info', 'Not modified content skipped', ['id' => $data->getId(), 'remote_id' => $data->getRemoteId()]);
return false;
}
private function log(string $level, string $message, array $context = [])
{
if ($this->logger === null) {
if (null === $this->logger) {
return;
}
$this->logger->log($level, $message, $context);

View File

@@ -6,7 +6,6 @@ namespace CodeRhapsodie\EzDataflowBundle\Form;
use CodeRhapsodie\DataflowBundle\Entity\Job;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -30,7 +29,7 @@ class CreateOneshotType extends AbstractType
'placeholder' => 'coderhapsodie.dataflow.options.placeholder',
],
])
->add('requestedDate', DateTimeType::class, [
->add('requestedDate', UserTimezoneAwareDateTimeType::class, [
'label' => 'coderhapsodie.dataflow.requestedDate',
'years' => range(date('Y'), date('Y') + 5),
])

View File

@@ -7,7 +7,6 @@ namespace CodeRhapsodie\EzDataflowBundle\Form;
use CodeRhapsodie\DataflowBundle\Entity\ScheduledDataflow;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -38,7 +37,7 @@ class CreateScheduledType extends AbstractType
],
'label' => 'coderhapsodie.dataflow.frequency',
])
->add('next', DateTimeType::class, [
->add('next', UserTimezoneAwareDateTimeType::class, [
'years' => range(date('Y'), date('Y') + 5),
'label' => 'coderhapsodie.dataflow.create.next',
])

View File

@@ -6,7 +6,6 @@ namespace CodeRhapsodie\EzDataflowBundle\Form;
use CodeRhapsodie\DataflowBundle\Entity\ScheduledDataflow;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -32,7 +31,7 @@ class UpdateScheduledType extends AbstractType
],
'label' => 'coderhapsodie.dataflow.frequency',
])
->add('next', DateTimeType::class, [
->add('next', UserTimezoneAwareDateTimeType::class, [
'years' => range(date('Y'), date('Y') + 5),
'label' => 'coderhapsodie.dataflow.update.next',
])

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
namespace CodeRhapsodie\EzDataflowBundle\Form;
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
use eZ\Publish\API\Repository\UserPreferenceService;
use Symfony\Component\Form\DataTransformerInterface;
class UserTimezoneAwareDateTimeTransformer implements DataTransformerInterface
{
/** @var UserPreferenceService */
private $userPreferenceService;
public function __construct(UserPreferenceService $userPreferenceService)
{
$this->userPreferenceService = $userPreferenceService;
}
public function transform($value)
{
if (!$value instanceof \DateTimeInterface) {
return $value;
}
return (new \DateTime('now', $this->userTimezone()))->setTimestamp($value->getTimestamp());
}
public function reverseTransform($value)
{
if (!$value instanceof \DateTimeInterface) {
return $value;
}
$dateTimeWithUserTimeZone = new \DateTime($value->format('Y-m-d H:i:s'), $this->userTimezone());
return (new \DateTime())->setTimestamp($dateTimeWithUserTimeZone->getTimestamp());
}
private function userTimezone(): \DateTimeZone
{
try {
$tz = $this->userPreferenceService->getUserPreference('timezone')->value ?? 'UTC';
} catch (NotFoundException $e) {
$tz = 'UTC';
}
return new \DateTimeZone($tz);
}
}

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace CodeRhapsodie\EzDataflowBundle\Form;
use eZ\Publish\API\Repository\UserPreferenceService;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\FormBuilderInterface;
class UserTimezoneAwareDateTimeType extends AbstractType
{
/** @var UserPreferenceService */
private $userPreferenceService;
public function __construct(UserPreferenceService $userPreferenceService)
{
$this->userPreferenceService = $userPreferenceService;
}
public function getParent()
{
return DateTimeType::class;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addModelTransformer(new UserTimezoneAwareDateTimeTransformer($this->userPreferenceService));
}
}

View File

@@ -10,6 +10,9 @@ use Doctrine\DBAL\Query\QueryBuilder;
final class JobGateway
{
public const FILTER_NONE = 0;
public const FILTER_NON_EMPTY = 1;
/** @var JobRepository */
private $jobRepository;
@@ -30,10 +33,17 @@ final class JobGateway
->addOrderBy('i.requested_date', 'DESC');
}
public function getListQueryForAdmin(): QueryBuilder
public function getListQueryForAdmin(int $filter): QueryBuilder
{
return $this->jobRepository->createQueryBuilder('w')
->addOrderBy('w.requested_date', 'DESC');
$qb = $this->jobRepository->createQueryBuilder('w')
->addOrderBy('w.requested_date', 'DESC')
;
if (self::FILTER_NON_EMPTY === $filter) {
$qb->andWhere('w.count > 0');
}
return $qb;
}
public function getListQueryForScheduleAdmin(int $id): QueryBuilder

View File

@@ -15,9 +15,6 @@ class ContentUpdateStructure extends ContentStructure
$this->fields = $fields;
}
/**
* @return ContentUpdateStructure
*/
public static function createForContentId(int $id, string $languageCode, array $fields): self
{
$struct = new self($languageCode, $fields);
@@ -26,9 +23,6 @@ class ContentUpdateStructure extends ContentStructure
return $struct;
}
/**
* @return ContentUpdateStructure
*/
public static function createForContentRemoteId(string $remoteId, string $languageCode, array $fields): self
{
$struct = new self($languageCode, $fields);

View File

@@ -13,7 +13,6 @@ services:
- { name: controller.service_arguments }
arguments:
$jobGateway: '@CodeRhapsodie\EzDataflowBundle\Gateway\JobGateway'
$notificationHandler: '@EzSystems\EzPlatformAdminUi\Notification\NotificationHandlerInterface'
$scheduledDataflowGateway: '@CodeRhapsodie\EzDataflowBundle\Gateway\ScheduledDataflowGateway'
calls:
- ['setContainer', ['@service_container']]
@@ -117,6 +116,11 @@ services:
CodeRhapsodie\EzDataflowBundle\Form\CreateOneshotType:
tags: ['form.type']
CodeRhapsodie\EzDataflowBundle\Form\UserTimezoneAwareDateTimeType:
arguments:
$userPreferenceService: '@eZ\Publish\API\Repository\UserPreferenceService'
tags: ['form.type']
CodeRhapsodie\EzDataflowBundle\Gateway\ScheduledDataflowGateway:
arguments:
$scheduledDataflowRepository: '@CodeRhapsodie\DataflowBundle\Repository\ScheduledDataflowRepository'

View File

@@ -21,10 +21,15 @@ coderhapsodie.ezdataflow.history.list.title: 'Executions list'
coderhapsodie.ezdataflow.history.list.name: Name
coderhapsodie.ezdataflow.history.list.request: 'Requested on'
coderhapsodie.ezdataflow.history.list.count: 'Items count'
coderhapsodie.ezdataflow.history.list.error_count: 'Errors count'
coderhapsodie.ezdataflow.history.list.start: 'Started on'
coderhapsodie.ezdataflow.history.list.end: 'Finished on'
coderhapsodie.ezdataflow.history.list.view: 'View details'
coderhapsodie.ezdataflow.history.list.status: Status
coderhapsodie.ezdataflow.history.filter.label: Filter results
coderhapsodie.ezdataflow.history.filter.none: All results
coderhapsodie.ezdataflow.history.filter.non_empty_only: Only non empty
coderhapsodie.ezdataflow.history.filter.with_error_only: Only with errors
coderhapsodie.ezdataflow.job.status.pending: Pending
coderhapsodie.ezdataflow.job.status.running: Running
coderhapsodie.ezdataflow.job.status.complete: Completed

View File

@@ -2,6 +2,34 @@
<div class="ez-table-header">
<div class="ez-table-header__headline">{{ 'coderhapsodie.ezdataflow.history.list.title'|trans }}</div>
<div class="ez-table-header__tools">
<label for="ezdataflow_history_filter">{{ 'coderhapsodie.ezdataflow.history.filter.label'|trans }}</label>
<select id="ezdataflow_history_filter" name="filter">
<option value="0" {{ filter == 0 ? 'selected="selected"' }}>{{ 'coderhapsodie.ezdataflow.history.filter.none'|trans }}</option>
<option value="1" {{ filter == 1 ? 'selected="selected"' }}>{{ 'coderhapsodie.ezdataflow.history.filter.non_empty_only'|trans }}</option>
</select>
</div>
</div>
{% include '@ezdesign/ezdataflow/parts/tab/job_list.html.twig' with {identifier: 'ezdataflow_history_results', paginate_route: 'coderhapsodie.ezdataflow.history'} %}
{% include '@ezdesign/ezdataflow/parts/tab/job_list.html.twig' with {
identifier: 'ezdataflow_history_results',
paginate_route: 'coderhapsodie.ezdataflow.history',
paginate_params: {'filter': filter}
} %}
<script>
(function ($) {
$(document).ready(function ($) {
// Manage ajax pagination
$('#ezdataflow_history_filter').change(function (e) {
e.preventDefault();
$('#loading_ezdataflow_history_results').removeClass('d-none');
$('#ezdataflow_history_results')
.html('')
.load('{{ path('coderhapsodie.ezdataflow.history') }}?filter=' + this.value + ' #ezdataflow_history_results>*', null, function () {
$('#loading_ezdataflow_history_results').addClass('d-none');
});
});
});
})(jQuery);
</script>

View File

@@ -1,5 +1,7 @@
{% extends ["@ezdesign/layout.html.twig", "@ezdesign/ui/layout.html.twig"] %}
{% block body_class %}ez-has-full-width-footer{% endblock %}
{% block breadcrumbs %}
{% include ['@ezdesign/parts/breadcrumbs.html.twig', '@ezdesign/ui/breadcrumbs.html.twig'] with { items: [
{ value: 'breadcrumb.admin'|trans(domain='messages')|desc('Admin') },
@@ -15,7 +17,7 @@
{% endblock %}
{% block content %}
{{ ez_render_component_group('coderhapsodie-ezdataflow', {}, '@ezdesign/ezdataflow/parts/tab/ezdataflow.html.twig') }}
{{ ez_render_component_group('coderhapsodie-ezdataflow', {'filter': app.request.query.get('filter', 0)}, '@ezdesign/ezdataflow/parts/tab/ezdataflow.html.twig') }}
<div class="modal fade ez-modal show" id="ez-modal--history-details" tabindex="-1" role="dialog" aria-modal="true">
<div class="modal-dialog" role="document" style="max-width: 90%">

View File

@@ -40,9 +40,10 @@
success: function (result) {
if (result.redirect) {
if (window.location.href === result.redirect) {
document.location.reload();
window.location.reload();
}
window.location = result.redirect;
window.location.reload();
return;
}

View File

@@ -125,9 +125,10 @@
success: function (result) {
if (result.redirect) {
if (window.location.href === result.redirect) {
document.location.reload();
window.location.reload();
}
window.location = result.redirect;
window.location.reload();
return;
}

View File

@@ -20,7 +20,7 @@
</tr>
<tr>
<td>{{ 'coderhapsodie.ezdataflow.history.details.request'|trans }}</td>
<td>{{ item.requestedDate|date('d/m/Y H:i:s') }}</td>
<td>{{ date(item.requestedDate)|ez_short_datetime }}</td>
</tr>
<tr>
<td>{{ 'coderhapsodie.ezdataflow.history.details.status'|trans }}</td>
@@ -28,11 +28,11 @@
</tr>
<tr>
<td>{{ 'coderhapsodie.ezdataflow.history.details.start'|trans }}</td>
<td>{{ item.startTime|date('d/m/Y H:i:s') }}</td>
<td>{{ item.startTime ? date(item.startTime)|ez_short_datetime : '—' }}</td>
</tr>
<tr>
<td>{{ 'coderhapsodie.ezdataflow.history.details.end'|trans }}</td>
<td>{{ item.endTime|date('d/m/Y H:i:s') }}</td>
<td>{{ item.endTime ? date(item.endTime)|ez_short_datetime : '—' }}</td>
</tr>
<tr>
<td>{{ 'coderhapsodie.ezdataflow.history.details.count'|trans }}</td>

View File

@@ -27,10 +27,10 @@
{% for job in pager.currentPageResults %}
<tr>
<td>{{ job.label }}</td>
<td>{{ job.requested_date|date('d/m/Y H:i:s') }}</td>
<td>{{ job.count|default('-') }}</td>
<td>{{ job.start_time ? job.start_time|date('d/m/Y H:i:s') : '-' }}</td>
<td>{{ job.end_time ? job.end_time|date('d/m/Y H:i:s') : '-' }}</td>
<td>{{ date(job.requested_date)|ez_short_datetime }}</td>
<td>{{ job.count|default('') }}</td>
<td>{{ job.start_time ? date(job.start_time)|ez_short_datetime : '' }}</td>
<td>{{ job.end_time ? date(job.end_time)|ez_short_datetime : '' }}</td>
<td>{{ macros.translateStatus(job.status) }}</td>
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
<a href="{{ path('coderhapsodie.ezdataflow.job.details', {id: job.id}) }}"
@@ -66,7 +66,6 @@
</div>
<script>
(function ($) {
$(document).ready(function ($) {
// Manage ajax pagination

View File

@@ -24,7 +24,7 @@
<tr>
<td>{{ item.label }}</td>
<td>{{ item.frequency }}</td>
<td>{{ item.next|date('d/m/Y H:i:s') }}</td>
<td>{{ date(item.next)|ez_short_datetime }}</td>
<td>{{ ('coderhapsodie.ezdataflow.' ~ (item.enabled ? 'yes' : 'no'))|trans }}</td>
<td class="ez-table__cell ez-table__cell--has-action-btns text-right">
<a href="{{ path('coderhapsodie.ezdataflow.history.workflow', {id: item.id}) }}"

View File

@@ -16,7 +16,7 @@ class HistoryTab extends AbstractControllerBasedTab implements OrderedTabInterfa
*/
public function getControllerReference(array $parameters): ControllerReference
{
return new ControllerReference(DashboardController::class.'::history');
return new ControllerReference(DashboardController::class.'::history', [], $parameters);
}
/**

View File

@@ -10,7 +10,6 @@ use CodeRhapsodie\EzDataflowBundle\Core\Content\ContentUpdaterInterface;
use CodeRhapsodie\EzDataflowBundle\Model\ContentCreateStructure;
use CodeRhapsodie\EzDataflowBundle\Model\ContentStructure;
use CodeRhapsodie\EzDataflowBundle\Model\ContentUpdateStructure;
use Psr\Log\LoggerAwareTrait;
class ContentWriter extends RepositoryWriter implements DelegateWriterInterface
@@ -35,20 +34,23 @@ class ContentWriter extends RepositoryWriter implements DelegateWriterInterface
public function write($item)
{
if (!$item instanceof ContentStructure) {
$this->log('warning', "Data is not a ContentStucture");
$this->log('warning', 'Data is not a ContentStucture');
return;
}
if ($item instanceof ContentCreateStructure) {
$this->log('info', 'Save content', [
'content_type' => $item->getContentTypeIdentifier(),
'content_location' => $item->getLocations()
'content_location' => $item->getLocations(),
]);
return $this->creator->createFromStructure($item);
}
if ($item instanceof ContentUpdateStructure) {
$this->log('info', 'Update content', ['id' => $item->getId(), 'remote_id' => $item->getRemoteId()]);
return $this->updater->updateFromStructure($item);
}
}
@@ -63,7 +65,7 @@ class ContentWriter extends RepositoryWriter implements DelegateWriterInterface
private function log(string $level, string $message, array $context = [])
{
if ($this->logger === null) {
if (null === $this->logger) {
return;
}
$this->logger->log($level, $message, $context);