|
11 | 11 | use Magento\Framework\Autoload\AutoloaderInterface;
|
12 | 12 | use Magento\Framework\Config\ConfigOptionsListConstants;
|
13 | 13 | use Magento\Framework\Filesystem\Glob;
|
| 14 | +use Magento\Framework\Indexer\IndexerRegistry; |
14 | 15 | use Magento\Framework\Mail;
|
| 16 | +use Magento\Indexer\Model\Indexer\Collection; |
15 | 17 | use Magento\TestFramework;
|
16 | 18 | use Magento\TestFramework\Fixture\Data\ProcessorInterface;
|
17 | 19 | use Psr\Log\LoggerInterface;
|
@@ -567,9 +569,11 @@ public function install($cleanup)
|
567 | 569 | );
|
568 | 570 |
|
569 | 571 | $this->runPostInstallCommands();
|
| 572 | + $this->makeIndexStatusRealtime(); |
570 | 573 |
|
571 | 574 | // enable only specified list of caches
|
572 | 575 | $initParamsQuery = $this->getInitParamsQuery();
|
| 576 | + |
573 | 577 | $this->_shell->execute(
|
574 | 578 | PHP_BINARY . ' -f %s cache:disable -vvv --bootstrap=%s',
|
575 | 579 | [BP . '/bin/magento', $initParamsQuery]
|
@@ -745,7 +749,7 @@ protected function _ensureDirExists($dir)
|
745 | 749 | // phpcs:ignore Magento2.Functions.DiscouragedFunction
|
746 | 750 | mkdir($dir, 0777, true);
|
747 | 751 | umask($old);
|
748 |
| - // phpcs:ignore Magento2.Functions.DiscouragedFunction |
| 752 | + // phpcs:ignore Magento2.Functions.DiscouragedFunction |
749 | 753 | } elseif (!is_dir($dir)) {
|
750 | 754 | throw new \Magento\Framework\Exception\LocalizedException(__("'%1' is not a directory.", $dir));
|
751 | 755 | }
|
@@ -825,4 +829,90 @@ protected function getCustomDirs()
|
825 | 829 | ];
|
826 | 830 | return $customDirs;
|
827 | 831 | }
|
| 832 | + |
| 833 | + /** |
| 834 | + * Initialize the application and set the index status to realtime. |
| 835 | + * |
| 836 | + * @return void |
| 837 | + */ |
| 838 | + private function makeIndexStatusRealtime(): void |
| 839 | + { |
| 840 | + $overriddenParams = $this->getOverriddenParams(); |
| 841 | + $directoryList = $this->getDirectoryList($overriddenParams); |
| 842 | + $objectManager = $this->getObjectManagers($overriddenParams, $directoryList); |
| 843 | + Helper\Bootstrap::setObjectManager($objectManager); |
| 844 | + $objectManagerConfiguration = [ |
| 845 | + 'preferences' => [ |
| 846 | + \Magento\Framework\App\State::class => TestFramework\App\State::class |
| 847 | + ] |
| 848 | + ]; |
| 849 | + $objectManager->configure($objectManagerConfiguration); |
| 850 | + $this->setIndexerToRealtime($objectManager); |
| 851 | + } |
| 852 | + |
| 853 | + /** |
| 854 | + * Retrieves the overridden parameters. |
| 855 | + * |
| 856 | + * @return array |
| 857 | + */ |
| 858 | + private function getOverriddenParams(): array |
| 859 | + { |
| 860 | + $overriddenParams[\Magento\Framework\App\State::PARAM_MODE] = $this->_appMode; |
| 861 | + return $this->_customizeParams($overriddenParams); |
| 862 | + } |
| 863 | + |
| 864 | + /** |
| 865 | + * Retrieves the directory list. |
| 866 | + * |
| 867 | + * @param array $overriddenParams |
| 868 | + * @return DirectoryList |
| 869 | + */ |
| 870 | + private function getDirectoryList($overriddenParams): DirectoryList |
| 871 | + { |
| 872 | + $directories = isset($overriddenParams[\Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) |
| 873 | + ? $overriddenParams[\Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] |
| 874 | + : []; |
| 875 | + return new DirectoryList(BP, $directories); |
| 876 | + } |
| 877 | + |
| 878 | + /** |
| 879 | + * Retrieves the object manager. |
| 880 | + * |
| 881 | + * @param array $overriddenParams |
| 882 | + * @param DirectoryList $directoryList The directory list. |
| 883 | + * @return ObjectManager |
| 884 | + */ |
| 885 | + private function getObjectManagers($overriddenParams, $directoryList): ObjectManager |
| 886 | + { |
| 887 | + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 888 | + if (!$objectManager) { |
| 889 | + $objectManager = $this->_factory->create($overriddenParams); |
| 890 | + $objectManager->addSharedInstance($directoryList, DirectoryList::class); |
| 891 | + $objectManager->addSharedInstance($directoryList, \Magento\Framework\Filesystem\DirectoryList::class); |
| 892 | + } else { |
| 893 | + $objectManager = $this->_factory->restore($objectManager, $directoryList, $overriddenParams); |
| 894 | + } |
| 895 | + return $objectManager; |
| 896 | + } |
| 897 | + |
| 898 | + /** |
| 899 | + * Sets the indexer mode to realtime. |
| 900 | + * |
| 901 | + * @param ObjectManager $objectManager |
| 902 | + * @return void |
| 903 | + */ |
| 904 | + private function setIndexerToRealtime($objectManager): void |
| 905 | + { |
| 906 | + /** @var Collection $indexCollection */ |
| 907 | + $indexCollection = $objectManager->get(Collection::class); |
| 908 | + $indexerIds = $indexCollection->getAllIds(); |
| 909 | + if (!empty($indexerIds)) { |
| 910 | + foreach ($indexerIds as $indexerId) { |
| 911 | + /** @var IndexerInterface $model */ |
| 912 | + $model = $objectManager->get(IndexerRegistry::class) |
| 913 | + ->get($indexerId); |
| 914 | + $model->setScheduled(false); |
| 915 | + } |
| 916 | + } |
| 917 | + } |
828 | 918 | }
|
0 commit comments