Spaces:
No application file
No application file
File size: 2,179 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
<?php
declare(strict_types=1);
namespace Mautic\CampaignBundle\Command;
use Mautic\CampaignBundle\Entity\LeadEventLogRepository;
use Mautic\CampaignBundle\Model\CampaignModel;
use Mautic\CampaignBundle\Model\EventModel;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class CampaignDeleteEventLogsCommand extends Command
{
/**
* @var string
*/
public const COMMAND_NAME = 'mautic:campaign:delete-event-logs';
public function __construct(private LeadEventLogRepository $leadEventLogRepository, private CampaignModel $campaignModel, private EventModel $eventModel)
{
parent::__construct();
}
protected function configure(): void
{
$this->setName(self::COMMAND_NAME)
->setDescription('Delete campaign event logs')
->addArgument(
'campaign_event_ids',
InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
'Campaign event ids to delete event logs.'
)
->addOption(
'--campaign-id',
'-i',
InputOption::VALUE_OPTIONAL,
'Delete campaign also otherwise will delete event and event log only.'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$eventIds = $input->getArgument('campaign_event_ids');
$campaignId = (int) $input->getOption('campaign-id');
if (!empty($campaignId)) {
$this->leadEventLogRepository->removeEventLogsByCampaignId($campaignId);
$this->eventModel->deleteEventsByCampaignId($campaignId);
$campaign = $this->campaignModel->getEntity($campaignId);
$this->campaignModel->deleteCampaign($campaign);
} elseif (!empty($eventIds)) {
$this->leadEventLogRepository->removeEventLogs($eventIds);
$this->eventModel->deleteEventsByEventIds($eventIds);
}
return 0;
}
}
|