RecreatedIntegration.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Model\Message;
  7. use Magento\Framework\UrlInterface;
  8. use Magento\Integration\Api\IntegrationServiceInterface;
  9. use Magento\Integration\Model\Config;
  10. use Magento\Integration\Model\ConsolidatedConfig;
  11. use Magento\Integration\Model\Integration;
  12. /**
  13. * Class RecreatedIntegration to display message when a config-based integration needs to be reactivated
  14. */
  15. class RecreatedIntegration implements \Magento\Framework\Notification\MessageInterface
  16. {
  17. /**
  18. * @var Config
  19. */
  20. protected $integrationConfig;
  21. /**
  22. * @var UrlInterface
  23. */
  24. protected $urlBuilder;
  25. /**
  26. * @var IntegrationServiceInterface
  27. */
  28. protected $integrationService;
  29. /**
  30. * @var ConsolidatedConfig
  31. */
  32. protected $consolidatedConfig;
  33. /**
  34. * @param Config $integrationConfig
  35. * @param UrlInterface $urlBuilder
  36. * @param IntegrationServiceInterface $integrationService
  37. * @param ConsolidatedConfig $consolidatedConfig
  38. */
  39. public function __construct(
  40. Config $integrationConfig,
  41. UrlInterface $urlBuilder,
  42. IntegrationServiceInterface $integrationService,
  43. ConsolidatedConfig $consolidatedConfig
  44. ) {
  45. $this->integrationConfig = $integrationConfig;
  46. $this->consolidatedConfig = $consolidatedConfig;
  47. $this->urlBuilder = $urlBuilder;
  48. $this->integrationService = $integrationService;
  49. }
  50. /**
  51. * Check whether all indices are valid or not
  52. *
  53. * @return bool
  54. */
  55. public function isDisplayed()
  56. {
  57. foreach (array_keys($this->consolidatedConfig->getIntegrations()) as $name) {
  58. $integration = $this->integrationService->findByName($name);
  59. if ($integration->getStatus() == Integration::STATUS_RECREATED) {
  60. return true;
  61. }
  62. }
  63. return false;
  64. }
  65. //@codeCoverageIgnoreStart
  66. /**
  67. * Retrieve unique message identity
  68. *
  69. * @return string
  70. */
  71. public function getIdentity()
  72. {
  73. return md5('INTEGRATION_RECREATED');
  74. }
  75. /**
  76. * Retrieve message text
  77. *
  78. * @return \Magento\Framework\Phrase
  79. */
  80. public function getText()
  81. {
  82. $url = $this->urlBuilder->getUrl('adminhtml/integration');
  83. return __(
  84. 'One or more <a href="%1">integrations</a> have been reset because of a change to their xml configs.',
  85. $url
  86. );
  87. }
  88. /**
  89. * Retrieve message severity
  90. *
  91. * @return int
  92. */
  93. public function getSeverity()
  94. {
  95. return self::SEVERITY_MAJOR;
  96. }
  97. //@codeCoverageIgnoreEnd
  98. }