Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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();
                }
            }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top