1

Can anybody explain the purpose of this two files in Setup folder? When should I use it? I know, that it fires every time when I run setup:upgrade

But I want to know at least one example of usage. Thanks in advance.

5

I've found this from online sources:

The recurring scripts are executed after any module setup. If a module needs to do something everytime other modules are installed it can do it via the recurring script.

In Magento2 you can check in Magento\Indexer\Setup\Recurring class where Magento_Indexer module checks for new defined indexers and adds them to indexer_state table.

1
  • subquestion: does it run even if no new module is setup ? I gues not – medmek Jan 15 '20 at 10:40
0

Please check RecurringData.php worked for me.

<?php
        namespace Vendor\Module\Setup;
        use Magento\Framework\Setup\InstallDataInterface;
        use Magento\Framework\Setup\ModuleContextInterface;
        use Magento\Framework\Setup\ModuleDataSetupInterface;
        use Magento\Customer\Model\GroupFactory;


        class RecurringData implements InstallDataInterface
        {

            protected $_indexerFactory;
            public $indexerIds = array(
                    'catalog_category_product',
                    'catalog_product_category',
                    'catalog_product_price',
                    'catalog_product_attribute',
                    'cataloginventory_stock',
                    'catalogrule_product',
                    'catalogsearch_fulltext',
                );


            public function __construct(
                \Magento\Indexer\Model\IndexerFactory $indexerFactory
            ) {
                $this->_indexerFactory = $indexerFactory;
            }

            public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
            {
                $this->reindexAll();
            }

            public function reindexAll() {
                foreach ($this->indexerIds as $indexerId) {
                    $indexer = $this->_indexerFactory->create();
                    $indexer->load($indexerId);
                    $indexer->reindexAll();
                }
            }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.