Skip to content
Open
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
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,14 @@ else
endif
${COMPOSER} config allow-plugins true
ifeq ($(shell [[ $(SYLIUS_VERSION) == *dev ]] && echo true ),true)
${COMPOSER} require sylius/sylius:"${SYLIUS_VERSION}"
${COMPOSER} require --no-update sylius/sylius:"${SYLIUS_VERSION}"
else
${COMPOSER} require sylius/sylius:"~${SYLIUS_VERSION}"
${COMPOSER} require --no-update sylius/sylius:"~${SYLIUS_VERSION}"
endif

update-dependencies:
${COMPOSER} config extra.symfony.require "~${SYMFONY_VERSION}"
${COMPOSER} require symfony/asset:~${SYMFONY_VERSION} --no-scripts --no-update
ifeq ($(shell [[ $(SYLIUS_VERSION) == 1.10.0 ]] && echo true ),true)
${COMPOSER} require php-http/message-factory --no-scripts --no-update
endif
${COMPOSER} update --no-progress -n

install-plugin:
Expand All @@ -72,6 +69,7 @@ install-sylius:
${CONSOLE} sylius:fixtures:load default -n
${YARN} install
${YARN} build
${CONSOLE} assets:install -n

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm wondering if composer req does not already play this command at auto-scripts 🤔

${CONSOLE} cache:clear

phpunit-configure:
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
cp -R vendor/synolia/sylius-scheduler-command-plugin/install/Application/config/packages/* config/packages/
cp -R vendor/synolia/sylius-scheduler-command-plugin/install/Application/config/routes/* config/routes/

6. Installing assets (JS and CSS) fot the plugin

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
6. Installing assets (JS and CSS) fot the plugin
6. Installing assets (JS and CSS) for the plugin


bin/console assets:install

## Usage

* Log into admin panel
Expand Down Expand Up @@ -113,6 +117,12 @@ Execute scheduled commands.

**Run a specific scheduled command :** php bin/console synolia:scheduler-run --id=5

Is it possible to choose the timezone of the command execution by setting the `SYNOLIA_SCHEDULER_PLUGIN_TIMEZONE` environment variable, example:

```
SYNOLIA_SCHEDULER_PLUGIN_TIMEZONE=Europe/Paris
```

### synolia:scheduler:purge-history

Purge scheduled command history greater than {X} days old.
Expand Down
11 changes: 11 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@
* `logFile` field must be renamed to `logFilePrefix` and must not end with the file extension

Also, for old existing schedules in your database, please remove the log file extension in column `logFilePrefix`.

## from 3.8 to 3.9

* The constructors of `Synolia\SyliusSchedulerCommandPlugin\Checker\EveryMinuteIsDueChecker` and `Synolia\SyliusSchedulerCommandPlugin\Checker\SoftLimitThresholdIsDueChecker` has been modified, a new argument has been added :

```php
public function __construct(
// ...
private ?DateTimeProviderInterface $dateTimeProvider = null,
)
```
17 changes: 16 additions & 1 deletion src/Checker/EveryMinuteIsDueChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Synolia\SyliusSchedulerCommandPlugin\Checker;

use Cron\CronExpression;
use Sylius\Calendar\Provider\DateTimeProviderInterface;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use Synolia\SyliusSchedulerCommandPlugin\Components\Exceptions\Checker\IsNotDueException;
use Synolia\SyliusSchedulerCommandPlugin\Entity\CommandInterface;
Expand All @@ -17,6 +18,20 @@ class EveryMinuteIsDueChecker implements IsDueCheckerInterface
{
private const PRIORITY = 0;

public function __construct(
private readonly ?DateTimeProviderInterface $dateTimeProvider = null,
) {
if (!$dateTimeProvider instanceof DateTimeProviderInterface) {
trigger_deprecation(
'synolia/sylius-scheduler-command-plugin',
'3.9',
'Not passing a service that implements "%s" as a 1st argument of "%s" constructor is deprecated and will be prohibited in 4.0.',
DateTimeProviderInterface::class,
self::class,
);
}
}

public static function getDefaultPriority(): int
{
return self::PRIORITY;
Expand All @@ -28,7 +43,7 @@ public static function getDefaultPriority(): int
public function isDue(CommandInterface $command, ?\DateTimeInterface $dateTime = null): bool
{
if (!$dateTime instanceof \DateTimeInterface) {
$dateTime = new \DateTime();
$dateTime = $this->dateTimeProvider?->now() ?? new \DateTime();
}

$cron = new CronExpression($command->getCronExpression());
Expand Down
13 changes: 12 additions & 1 deletion src/Checker/SoftLimitThresholdIsDueChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Synolia\SyliusSchedulerCommandPlugin\Checker;

use Cron\CronExpression;
use Sylius\Calendar\Provider\DateTimeProviderInterface;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use Synolia\SyliusSchedulerCommandPlugin\Components\Exceptions\Checker\IsNotDueException;
use Synolia\SyliusSchedulerCommandPlugin\Entity\CommandInterface;
Expand All @@ -22,11 +23,21 @@ public static function getDefaultPriority(): int

public function __construct(
private readonly ScheduledCommandRepositoryInterface $scheduledCommandRepository,
private readonly ?DateTimeProviderInterface $dateTimeProvider = null,
/**
* Threshold in minutes
*/
private readonly int $threshold = 5,
) {
if (!$dateTimeProvider instanceof DateTimeProviderInterface) {
trigger_deprecation(
'synolia/sylius-scheduler-command-plugin',
'3.9',
'Not passing a service that implements "%s" as a 1st argument of "%s" constructor is deprecated and will be prohibited in 4.0.',
DateTimeProviderInterface::class,
self::class,
);
}
}

/**
Expand All @@ -35,7 +46,7 @@ public function __construct(
public function isDue(CommandInterface $command, ?\DateTimeInterface $dateTime = null): bool
{
if (!$dateTime instanceof \DateTimeInterface) {
$dateTime = new \DateTime();
$dateTime = $this->dateTimeProvider?->now() ?? new \DateTime();
}

$cron = new CronExpression($command->getCronExpression());
Expand Down
69 changes: 69 additions & 0 deletions src/EventSubscriber/ConsoleSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace Synolia\SyliusSchedulerCommandPlugin\EventSubscriber;

use Doctrine\DBAL\Exception;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleSignalEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Synolia\SyliusSchedulerCommandPlugin\Entity\ScheduledCommand;
use Synolia\SyliusSchedulerCommandPlugin\Enum\ScheduledCommandStateEnum;
use Synolia\SyliusSchedulerCommandPlugin\Repository\ScheduledCommandRepository;

final class ConsoleSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly ScheduledCommandRepository $scheduledCommandRepository,
) {
}

public static function getSubscribedEvents(): array
{
return [
ConsoleEvents::TERMINATE => 'onConsoleTerminate',
ConsoleEvents::SIGNAL => 'onConsoleSignal',
];
}

public function onConsoleTerminate(ConsoleTerminateEvent $event): void
{
$this->updateCommand($event);
}

public function onConsoleSignal(ConsoleSignalEvent $event): void
{
$this->updateCommand($event);
}

private function updateCommand(ConsoleSignalEvent|ConsoleTerminateEvent $event): void
{
try {
$commandCode = $event->getCommand()?->getName() ?? 'no_command';
/** @var ScheduledCommand|null $schedulerCommand */
$schedulerCommand = $this->scheduledCommandRepository->findOneBy(['command' => $commandCode], ['id' => 'DESC']);
} catch (Exception) {
return;
}

if (null === $schedulerCommand) {
return;
}

if ($schedulerCommand->getState() !== ScheduledCommandStateEnum::IN_PROGRESS) {
return;
}

$exitCode = $event->getExitCode();
if (false === $exitCode) {
$exitCode = -1;
}

$schedulerCommand->setCommandEndTime(new \DateTime());
$schedulerCommand->setState(ScheduledCommandStateEnum::TERMINATION);
$schedulerCommand->setLastReturnCode($exitCode);
$this->scheduledCommandRepository->add($schedulerCommand);
}
}
10 changes: 7 additions & 3 deletions src/Humanizer/CronExpressionHumanizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
use Lorisleiva\CronTranslator\CronTranslator;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Sylius\Component\Locale\Context\LocaleNotFoundException;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class CronExpressionHumanizer implements HumanizerInterface
{
public function __construct(private readonly LocaleContextInterface $localeContext)
{
public function __construct(
private readonly LocaleContextInterface $localeContext,
#[Autowire(param: 'env(bool:SYNOLIA_SCHEDULER_PLUGIN_TIMEFORMAT_24H)')]
private readonly bool $timeFormat24Hours = false,
) {
}

public function humanize(string $expression): string
Expand All @@ -23,7 +27,7 @@ public function humanize(string $expression): string
$locale = $this->getLocale();

try {
return CronTranslator::translate($expression, $locale);
return CronTranslator::translate($expression, $locale, $this->timeFormat24Hours);
} catch (\Throwable) {
return $expression;
}
Expand Down
32 changes: 32 additions & 0 deletions src/Provider/CalendarWithTimezone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Synolia\SyliusSchedulerCommandPlugin\Provider;

use DateTimeImmutable;
use DateTimeZone;
use Exception;
use Sylius\Calendar\Provider\DateTimeProviderInterface;
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

#[AsAlias(DateTimeProviderInterface::class)]
final class CalendarWithTimezone implements DateTimeProviderInterface
{
public function __construct(
#[Autowire(param: 'env(SYNOLIA_SCHEDULER_PLUGIN_TIMEZONE)')]
private ?string $timezone = null,
) {
}

/**
* @throws Exception
*/
public function now(): \DateTimeInterface
{
$timezone = $this->timezone ?? date_default_timezone_get();

return new DateTimeImmutable(timezone: new DateTimeZone($timezone));
}
}
4 changes: 3 additions & 1 deletion src/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ parameters:
env(SYNOLIA_SCHEDULER_PLUGIN_PING_INTERVAL): 300
env(SYNOLIA_SCHEDULER_PLUGIN_KEEP_ALIVE): true
env(SYNOLIA_SCHEDULER_PLUGIN_LOGS_DIR): '%kernel.logs_dir%'
env(SYNOLIA_SCHEDULER_PLUGIN_TIMEFORMAT_24H): false
env(SYNOLIA_SCHEDULER_PLUGIN_TIMEZONE): ~

services:
_defaults:
Expand All @@ -10,4 +12,4 @@ services:

Synolia\SyliusSchedulerCommandPlugin\:
resource: '../../*'
exclude: '../../{Entity,Migrations,SynoliaSyliusSchedulerCommandPlugin.php}'
exclude: '../../{Entity,Migrations,SynoliaSyliusSchedulerCommandPlugin.php}'
2 changes: 1 addition & 1 deletion src/Resources/public/column/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function fireLog(e) {
e.preventDefault();
var url = $(e.currentTarget).data('href');
$.get(url, function (data) {
$('#log-modal .description').html($(data).find('#content'));
$('#log-content').html($(data));
}).done(function () {
$('#log-modal').modal('show');
})
Expand Down
24 changes: 14 additions & 10 deletions src/Resources/public/controller/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@ pre {

#results {
border: solid 1px;
padding: 5px;
padding: 10px;
overflow-y: scroll;
height: calc(100% - 150px);
height: calc(100% - 80px);
}

#log-modal {
width: calc(100% - 100px);
height: calc(100% - 100px);
}

#log-modal .description,
#log-modal > .content,
#log-modal #content {
height: 100%;
width: calc(100% - 120px);
height: calc(100% - 120px);
overflow-y: hidden;
}

#results .loader:before {
Expand All @@ -31,3 +26,12 @@ pre {
#results .loader:after {
border-color: #767676 transparent transparent;
}

#log-content {
padding: 10px;
height: calc(100% - 20px);
}

#log-results {
height: calc(100% - 20px);
}
3 changes: 1 addition & 2 deletions src/Resources/views/Controller/modal.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<i class="close icon"></i>
</a>
</div>
<div class="content">
<div class="description"></div>
<div id="log-content">
</div>
</div>
40 changes: 17 additions & 23 deletions src/Resources/views/Controller/show.html.twig
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
{% extends '@SyliusAdmin/layout.html.twig' %}

{% import '@SyliusUi/Macro/headers.html.twig' as headers %}

{% block title %}{{ 'synolia.ui.live_view_of_scheduled_command'|trans({'%scheduledCommandName%': scheduledCommand.name|e}) }} {{ parent() }}{% endblock %}

{% block content %}
{{ headers.default('synolia.ui.live_view_of_scheduled_command'|trans({'%scheduledCommandName%': scheduledCommand.name|e}), 'cogs') }}

<div class="ui input">
<input id="grep" type="text" placeholder="Search...">
</div>
<div class="ui icon input">
<input id="grep" type="text" placeholder="Search...">
<i class="search icon"></i>
</div>

<div id="log-results">
<pre id="results">
<div class="ui active centered inline loader"></div>
</pre>
</div>

{{ sylius_template_event('synolia.admin.command.logs.stylesheets') }}

{{ sylius_template_event('synolia.admin.command.logs.stylesheets') }}
<script type="text/javascript">
{% autoescape 'js' %}
/* <![CDATA[ */
var sy_updateTime = {{ updateTime }};
var sy_route = "{{ route }}";
/* ]]> */
{% endautoescape %}
</script>

<script type="text/javascript">
{% autoescape 'js' %}
/* <![CDATA[ */
var sy_updateTime = {{ updateTime }};
var sy_route = "{{ route }}";
/* ]]> */
{% endautoescape %}
</script>
{{ sylius_template_event('synolia.admin.command.logs.javascripts') }}

{{ sylius_template_event('synolia.admin.command.logs.javascripts') }}
{% endblock %}
Loading
Loading