Executor.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Setup\SampleData;
  7. class Executor
  8. {
  9. /**
  10. * @var State
  11. */
  12. private $state;
  13. /**
  14. * @var \Psr\Log\LoggerInterface
  15. */
  16. private $logger;
  17. /**
  18. * @var \Magento\Framework\App\State
  19. */
  20. private $appState;
  21. /**
  22. * @param \Psr\Log\LoggerInterface $logger
  23. * @param State $state
  24. * @param \Magento\Framework\App\State $appState
  25. */
  26. public function __construct(
  27. \Psr\Log\LoggerInterface $logger,
  28. \Magento\Framework\Setup\SampleData\State $state,
  29. \Magento\Framework\App\State $appState
  30. ) {
  31. $this->logger = $logger;
  32. $this->state = $state;
  33. $this->appState = $appState;
  34. }
  35. /**
  36. * Execute SampleData module installation.
  37. * Catch exception if it appeared and continue installation
  38. *
  39. * @param InstallerInterface $installer
  40. * @return void
  41. */
  42. public function exec(InstallerInterface $installer)
  43. {
  44. try {
  45. $this->appState->emulateAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL, [$installer, 'install']);
  46. $this->state->setInstalled();
  47. } catch (\Exception $e) {
  48. $this->state->setError();
  49. $this->logger->error('Sample Data error: ' . $e->getMessage());
  50. }
  51. }
  52. }