Transform log data for response
[MAILPOET-5091]
This commit is contained in:
@@ -4,19 +4,27 @@ namespace MailPoet\Automation\Integrations\MailPoet\Analytics\Controller;
|
|||||||
|
|
||||||
use MailPoet\Automation\Engine\Data\Automation;
|
use MailPoet\Automation\Engine\Data\Automation;
|
||||||
use MailPoet\Automation\Engine\Data\AutomationRun;
|
use MailPoet\Automation\Engine\Data\AutomationRun;
|
||||||
|
use MailPoet\Automation\Engine\Data\AutomationRunLog;
|
||||||
use MailPoet\Automation\Engine\Data\NextStep;
|
use MailPoet\Automation\Engine\Data\NextStep;
|
||||||
|
use MailPoet\Automation\Engine\Data\Step;
|
||||||
|
use MailPoet\Automation\Engine\Storage\AutomationRunLogStorage;
|
||||||
use MailPoet\Automation\Engine\Storage\AutomationRunStorage;
|
use MailPoet\Automation\Engine\Storage\AutomationRunStorage;
|
||||||
use MailPoet\Automation\Integrations\MailPoet\Analytics\Entities\Query;
|
use MailPoet\Automation\Integrations\MailPoet\Analytics\Entities\Query;
|
||||||
|
|
||||||
class StepStatisticController {
|
class StepStatisticController {
|
||||||
|
|
||||||
|
/** @var AutomationRunStorage */
|
||||||
private $automationRunStorage;
|
private $automationRunStorage;
|
||||||
|
|
||||||
|
/** @var AutomationRunLogStorage */
|
||||||
|
private $automationRunLogStorage;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
AutomationRunStorage $automationRunStorage
|
AutomationRunStorage $automationRunStorage,
|
||||||
|
AutomationRunLogStorage $automationRunLogStorage
|
||||||
) {
|
) {
|
||||||
$this->automationRunStorage = $automationRunStorage;
|
$this->automationRunStorage = $automationRunStorage;
|
||||||
|
$this->automationRunLogStorage = $automationRunLogStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getWaitingStatistics(Automation $automation, Query $query): array {
|
public function getWaitingStatistics(Automation $automation, Query $query): array {
|
||||||
@@ -47,4 +55,29 @@ class StepStatisticController {
|
|||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFlowStatistics(Automation $automation, Query $query): array {
|
||||||
|
$statistics = $this->automationRunLogStorage->getAutomationRunStatisticsForAutomationInTimeFrame(
|
||||||
|
$automation->getId(),
|
||||||
|
AutomationRunLog::STATUS_COMPLETED,
|
||||||
|
$query->getAfter(),
|
||||||
|
$query->getBefore()
|
||||||
|
);
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
foreach ($automation->getSteps() as $step) {
|
||||||
|
if ($step->getType() === Step::TYPE_ROOT) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$data[$step->getId()] = 0;
|
||||||
|
foreach ($statistics as $stat) {
|
||||||
|
if ($stat['step_id'] === $step->getId()) {
|
||||||
|
$data[$step->getId()] = (int)$stat['count'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user