RecreatedIntegration.php 2.69 KB
Newer Older
Ketan's avatar
Ketan committed
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace Magento\Integration\Model\Message;

use Magento\Framework\UrlInterface;
use Magento\Integration\Api\IntegrationServiceInterface;
use Magento\Integration\Model\Config;
use Magento\Integration\Model\ConsolidatedConfig;
use Magento\Integration\Model\Integration;

/**
 * Class RecreatedIntegration to display message when a config-based integration needs to be reactivated
 */
class RecreatedIntegration implements \Magento\Framework\Notification\MessageInterface
{
    /**
     * @var Config
     */
    protected $integrationConfig;

    /**
     * @var UrlInterface
     */
    protected $urlBuilder;

    /**
     * @var IntegrationServiceInterface
     */
    protected $integrationService;

    /**
     * @var ConsolidatedConfig
     */
    protected $consolidatedConfig;

    /**
     * @param Config $integrationConfig
     * @param UrlInterface $urlBuilder
     * @param IntegrationServiceInterface $integrationService
     * @param ConsolidatedConfig $consolidatedConfig
     */
    public function __construct(
        Config $integrationConfig,
        UrlInterface $urlBuilder,
        IntegrationServiceInterface $integrationService,
        ConsolidatedConfig $consolidatedConfig
    ) {
        $this->integrationConfig = $integrationConfig;
        $this->consolidatedConfig = $consolidatedConfig;
        $this->urlBuilder = $urlBuilder;
        $this->integrationService = $integrationService;
    }

    /**
     * Check whether all indices are valid or not
     *
     * @return bool
     */
    public function isDisplayed()
    {
        foreach (array_keys($this->consolidatedConfig->getIntegrations()) as $name) {
            $integration = $this->integrationService->findByName($name);
            if ($integration->getStatus() == Integration::STATUS_RECREATED) {
                return true;
            }
        }

        return false;
    }

    //@codeCoverageIgnoreStart

    /**
     * Retrieve unique message identity
     *
     * @return string
     */
    public function getIdentity()
    {
        return md5('INTEGRATION_RECREATED');
    }

    /**
     * Retrieve message text
     *
     * @return \Magento\Framework\Phrase
     */
    public function getText()
    {
        $url = $this->urlBuilder->getUrl('adminhtml/integration');
        return __(
            'One or more <a href="%1">integrations</a> have been reset because of a change to their xml configs.',
            $url
        );
    }

    /**
     * Retrieve message severity
     *
     * @return int
     */
    public function getSeverity()
    {
        return self::SEVERITY_MAJOR;
    }

    //@codeCoverageIgnoreEnd
}