diff --git a/Command/HealthCommand.php b/Command/HealthCommand.php index 2a6023a..cba9d6f 100644 --- a/Command/HealthCommand.php +++ b/Command/HealthCommand.php @@ -32,12 +32,6 @@ protected function configure() { $this->setName('mautic:health:check') ->setDescription('General all purpose health check.') - // ->addOption( - // 'campaign-rebuild-delay', - // null, - // InputOption::VALUE_OPTIONAL, - // 'The maximum number of contacts waiting to be ingested into a campaign from a segment.' - // ) ->addOption( 'campaign-kickoff-delay', null, diff --git a/Model/HealthModel.php b/Model/HealthModel.php index 57d9f6e..372b72f 100644 --- a/Model/HealthModel.php +++ b/Model/HealthModel.php @@ -15,6 +15,7 @@ use Doctrine\DBAL\Connections\MasterSlaveConnection; use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\ORM\EntityManager; +use Mautic\CampaignBundle\Event\CampaignEvent; use Mautic\CampaignBundle\Model\CampaignModel; use Mautic\CampaignBundle\Model\EventModel; use Mautic\CoreBundle\Helper\CacheStorageHelper; @@ -61,6 +62,9 @@ class HealthModel /** @var CacheStorageHelper */ protected $cache; + /** @var array */ + protected $publishedCampaignsWithEvents = []; + /** * HealthModel constructor. * @@ -100,7 +104,7 @@ public function setSettings($settings) */ public function campaignKickoffCheck(OutputInterface $output = null) { - $campaignIds = array_keys($this->getPublishedCampaigns()); + $campaignIds = array_keys($this->getPublishedCampaignsWithEvents()); if (!$campaignIds) { return; } @@ -140,6 +144,41 @@ public function campaignKickoffCheck(OutputInterface $output = null) } } + /** + * @param null $campaignId + * + * @return array|bool + */ + private function getPublishedCampaignsWithEvents($campaignId = null) + { + if (!$this->publishedCampaignsWithEvents) { + $campaignIds = array_keys($this->getPublishedCampaigns()); + if ($campaignIds) { + /** @var CampaignEvent $event */ + foreach ($this->eventModel->getRepository()->getEntities( + [ + 'filter' => [ + 'force' => [ + [ + 'column' => 'IDENTITY(e.campaign)', + 'expr' => 'in', + 'value' => $campaignIds, + ], + ], + ], + ] + ) as $event) { + $this->publishedCampaignsWithEvents[$event->getCampaign()->getId()] = $event->getCampaign()->getName(); + } + } + } + if ($campaignId) { + return isset($this->publishedCampaignsWithEvents[$campaignId]) ? $this->publishedCampaignsWithEvents[$campaignId] : null; + } else { + return $this->publishedCampaignsWithEvents; + } + } + /** * @param null $campaignId *