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.


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.

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

Please check RecurringData.php worked for me.

        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(

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

            public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)

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

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.