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

[ENG-1024] Prevent false alarm from empty campaigns. #7

Merged
merged 2 commits into from
Aug 26, 2019
Merged
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
6 changes: 0 additions & 6 deletions Command/HealthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
41 changes: 40 additions & 1 deletion Model/HealthModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +62,9 @@ class HealthModel
/** @var CacheStorageHelper */
protected $cache;

/** @var array */
protected $publishedCampaignsWithEvents = [];

/**
* HealthModel constructor.
*
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Copy link

@ghost ghost Aug 26, 2019

Choose a reason for hiding this comment

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

This else statement isn't needed, just my preference though.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed, next time I'm in there I'll clean up. This was copy pasta.

return $this->publishedCampaignsWithEvents;
}
}

/**
* @param null $campaignId
*
Expand Down