Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lock to mautic:custom_items:scheduled_export #306

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions Command/CustomItemsScheduledExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

namespace MauticPlugin\CustomObjectsBundle\Command;

use Mautic\CoreBundle\Command\ModeratedCommand;
use Mautic\CoreBundle\Helper\ExitCode;
use Mautic\CoreBundle\Templating\Helper\FormatterHelper;
use MauticPlugin\CustomObjectsBundle\CustomItemEvents;
use MauticPlugin\CustomObjectsBundle\Event\CustomItemExportSchedulerEvent;
use MauticPlugin\CustomObjectsBundle\Model\CustomItemExportSchedulerModel;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class CustomItemsScheduledExportCommand extends Command
class CustomItemsScheduledExportCommand extends ModeratedCommand
{
public const COMMAND_NAME = 'mautic:custom_items:scheduled_export';

Expand Down Expand Up @@ -54,8 +54,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
{
$ids = $this->formatterHelper->simpleCsvToArray($input->getOption('ids'), 'int');
$customItemExportSchedulers = $this->customItemExportSchedulerModel->getRepository()->findBy(['id' => $ids]);
$count = 0;
$moderationKey = sprintf('%s%s', self::COMMAND_NAME, implode('-', $ids ?? []));

if (!$this->checkRunStatus($input, $output, $moderationKey)) {
return ExitCode::SUCCESS;
}

$count = 0;
foreach ($customItemExportSchedulers as $customItemExportScheduler) {
$customItemExportSchedulerEvent = new CustomItemExportSchedulerEvent($customItemExportScheduler);
$this->eventDispatcher->dispatch(CustomItemEvents::CUSTOM_ITEM_PREPARE_EXPORT_FILE, $customItemExportSchedulerEvent);
Expand All @@ -66,6 +71,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$output->writeln('CustomItem export email(s) sent: '.$count);

$this->completeRun();

return ExitCode::SUCCESS;
}
}