Invalid.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Indexer\Model\Message;
  7. /**
  8. * Message about invalid indexers.
  9. */
  10. class Invalid implements \Magento\Framework\Notification\MessageInterface
  11. {
  12. /**
  13. * @var \Magento\Indexer\Model\Indexer\Collection
  14. */
  15. protected $collection;
  16. /**
  17. * @var \Magento\Framework\UrlInterface
  18. */
  19. protected $urlBuilder;
  20. /**
  21. * @param \Magento\Indexer\Model\Indexer\Collection $collection
  22. * @param \Magento\Framework\UrlInterface $urlBuilder
  23. */
  24. public function __construct(
  25. \Magento\Indexer\Model\Indexer\Collection $collection,
  26. \Magento\Framework\UrlInterface $urlBuilder
  27. ) {
  28. $this->collection = $collection;
  29. $this->urlBuilder = $urlBuilder;
  30. }
  31. /**
  32. * Check whether all indices are valid or not
  33. *
  34. * @return bool
  35. */
  36. public function isDisplayed()
  37. {
  38. /** @var \Magento\Indexer\Model\Indexer $indexer */
  39. foreach ($this->collection->getItems() as $indexer) {
  40. if ($indexer->getStatus() == \Magento\Framework\Indexer\StateInterface::STATUS_INVALID) {
  41. return true;
  42. }
  43. }
  44. return false;
  45. }
  46. //@codeCoverageIgnoreStart
  47. /**
  48. * Retrieve unique message identity
  49. *
  50. * @return string
  51. */
  52. public function getIdentity()
  53. {
  54. return md5('INDEX_INVALID');
  55. }
  56. /**
  57. * Retrieve message text
  58. *
  59. * @return \Magento\Framework\Phrase
  60. */
  61. public function getText()
  62. {
  63. $url = $this->urlBuilder->getUrl('indexer/indexer/list');
  64. //@codingStandardsIgnoreStart
  65. return __(
  66. 'One or more <a href="%1">indexers are invalid</a>. Make sure your <a href="%2" target="_blank">Magento cron job</a> is running.',
  67. $url,
  68. 'https://devdocs.magento.com/guides/v2.2/config-guide/cli/config-cli-subcommands-cron.html#create-or-remove-the-magento-crontab'
  69. );
  70. //@codingStandardsIgnoreEnd
  71. }
  72. /**
  73. * Retrieve message severity
  74. *
  75. * @return int
  76. */
  77. public function getSeverity()
  78. {
  79. return self::SEVERITY_MAJOR;
  80. }
  81. //@codeCoverageIgnoreEnd
  82. }