123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\AsynchronousOperations\Model\Operation;
- use Magento\Framework\Bulk\OperationInterface;
- use Magento\Framework\Bulk\BulkStatusInterface;
- class Details
- {
- /**
- * @var array
- */
- private $operationCache = [];
- /**
- * @var \Magento\Framework\Bulk\BulkStatusInterface
- */
- private $bulkStatus;
- /**
- * @var null
- */
- private $bulkUuid;
- /**
- * Map between status codes and human readable indexes
- *
- * @var array
- */
- private $statusMap = [
- OperationInterface::STATUS_TYPE_COMPLETE => 'operations_successful',
- OperationInterface::STATUS_TYPE_RETRIABLY_FAILED => 'failed_retriable',
- OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED => 'failed_not_retriable',
- OperationInterface::STATUS_TYPE_OPEN => 'open',
- OperationInterface::STATUS_TYPE_REJECTED => 'rejected',
- ];
- /**
- * Init dependencies.
- *
- * @param \Magento\Framework\Bulk\BulkStatusInterface $bulkStatus
- * @param null $bulkUuid
- */
- public function __construct(
- BulkStatusInterface $bulkStatus,
- $bulkUuid = null
- ) {
- $this->bulkStatus = $bulkStatus;
- $this->bulkUuid = $bulkUuid;
- }
- /**
- * Collect operations statistics for the bulk
- *
- * @param string $bulkUuid
- * @return array
- */
- public function getDetails($bulkUuid)
- {
- $details = [
- 'operations_total' => 0,
- 'operations_successful' => 0,
- 'operations_failed' => 0,
- 'failed_retriable' => 0,
- 'failed_not_retriable' => 0,
- 'rejected' => 0,
- ];
- if (array_key_exists($bulkUuid, $this->operationCache)) {
- return $this->operationCache[$bulkUuid];
- }
- foreach ($this->statusMap as $statusCode => $readableKey) {
- $details[$readableKey] = $this->bulkStatus->getOperationsCountByBulkIdAndStatus(
- $bulkUuid,
- $statusCode
- );
- }
- $details['operations_total'] = array_sum($details);
- $details['operations_failed'] = $details['failed_retriable'] + $details['failed_not_retriable'];
- $this->operationCache[$bulkUuid] = $details;
- return $details;
- }
- /**
- * @inheritDoc
- */
- public function getOperationsTotal()
- {
- $this->getDetails($this->bulkUuid);
- return $this->operationCache[$this->bulkUuid]['operations_total'];
- }
- /**
- * @inheritDoc
- */
- public function getOpen()
- {
- $this->getDetails($this->bulkUuid);
- $statusKey = $this->statusMap[OperationInterface::STATUS_TYPE_OPEN];
- return $this->operationCache[$this->bulkUuid][$statusKey];
- }
- /**
- * @inheritDoc
- */
- public function getOperationsSuccessful()
- {
- $this->getDetails($this->bulkUuid);
- $statusKey = $this->statusMap[OperationInterface::STATUS_TYPE_COMPLETE];
- return $this->operationCache[$this->bulkUuid][$statusKey];
- }
- /**
- * @inheritDoc
- */
- public function getTotalFailed()
- {
- $this->getDetails($this->bulkUuid);
- return $this->operationCache[$this->bulkUuid]['operations_failed'];
- }
- /**
- * @inheritDoc
- */
- public function getFailedNotRetriable()
- {
- $statusKey = $this->statusMap[OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED];
- return $this->operationCache[$this->bulkUuid][$statusKey];
- }
- /**
- * @inheritDoc
- */
- public function getFailedRetriable()
- {
- $this->getDetails($this->bulkUuid);
- $statusKey = $this->statusMap[OperationInterface::STATUS_TYPE_RETRIABLY_FAILED];
- return $this->operationCache[$this->bulkUuid][$statusKey];
- }
- /**
- * @inheritDoc
- */
- public function getRejected()
- {
- $this->getDetails($this->bulkUuid);
- $statusKey = $this->statusMap[OperationInterface::STATUS_TYPE_REJECTED];
- return $this->operationCache[$this->bulkUuid][$statusKey];
- }
- }
|