Indexer.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Indexer\App;
  7. use Magento\Framework\App;
  8. use Magento\Framework\App\Filesystem\DirectoryList;
  9. class Indexer implements \Magento\Framework\AppInterface
  10. {
  11. /**
  12. * Report directory
  13. *
  14. * @var string
  15. */
  16. protected $reportDir;
  17. /**
  18. * @var \Magento\Framework\Filesystem
  19. */
  20. protected $filesystem;
  21. /**
  22. * @var \Magento\Framework\App\Console\Response
  23. */
  24. protected $_response;
  25. /**
  26. * @param string $reportDir
  27. * @param \Magento\Framework\Filesystem $filesystem
  28. * @param \Magento\Indexer\Model\Processor $processor
  29. * @param \Magento\Framework\App\Console\Response $response
  30. */
  31. public function __construct(
  32. $reportDir,
  33. \Magento\Framework\Filesystem $filesystem,
  34. \Magento\Indexer\Model\Processor $processor,
  35. \Magento\Framework\App\Console\Response $response
  36. ) {
  37. $this->reportDir = $reportDir;
  38. $this->filesystem = $filesystem;
  39. $this->processor = $processor;
  40. $this->_response = $response;
  41. }
  42. /**
  43. * Run application
  44. *
  45. * @return \Magento\Framework\App\ResponseInterface
  46. */
  47. public function launch()
  48. {
  49. /* Clean reports */
  50. $directory = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
  51. $path = $directory->getRelativePath($this->reportDir);
  52. if ($directory->isExist($path)) {
  53. $directory->delete($path);
  54. }
  55. /* Regenerate all indexers */
  56. $this->processor->reindexAll();
  57. $this->_response->setCode(0);
  58. return $this->_response;
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function catchException(App\Bootstrap $bootstrap, \Exception $exception)
  64. {
  65. return false;
  66. }
  67. }