Magento2 Delete config row while Extension Uninstall

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I have created a custom module which is being installed via composer.



When I run the command - php bin/magento module:uninstall Vendor_Faq



It is removing all the corresponding tables which I wrote in Uninstall script. But how to remove the entry from core_config_data and setup_module table using Uninstall script.







share|improve this question




























    up vote
    1
    down vote

    favorite












    I have created a custom module which is being installed via composer.



    When I run the command - php bin/magento module:uninstall Vendor_Faq



    It is removing all the corresponding tables which I wrote in Uninstall script. But how to remove the entry from core_config_data and setup_module table using Uninstall script.







    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have created a custom module which is being installed via composer.



      When I run the command - php bin/magento module:uninstall Vendor_Faq



      It is removing all the corresponding tables which I wrote in Uninstall script. But how to remove the entry from core_config_data and setup_module table using Uninstall script.







      share|improve this question














      I have created a custom module which is being installed via composer.



      When I run the command - php bin/magento module:uninstall Vendor_Faq



      It is removing all the corresponding tables which I wrote in Uninstall script. But how to remove the entry from core_config_data and setup_module table using Uninstall script.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 22 at 13:13









      Priyank

      4,64331744




      4,64331744










      asked Aug 22 at 9:14









      LAW

      803516




      803516




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          from setup module it should be deleted automatically (might be wrong on this one), but from the config table you should delete them using the same uninstall script.



          If the record from the setup_module table is not deleted automatically, you can do it from the same uninstall script.



          If this is not your module then it means the uninstall script is not properly coded.






          share|improve this answer



























            up vote
            3
            down vote













            I think Marius has forgotten his own module :)



            He has created a sample module with an uninstall script you can refer to same.



             $collection = $this->collectionFactory->create()
            ->addPathFilter('sample_news');
            foreach ($collection as $config)
            $this->configResource->delete($config);



            Credit to Great Marius






            share|improve this answer




















            • I am confused whose answer to verify. You gave me the code which was written by Marius :)
              – LAW
              Aug 22 at 11:10










            • Never mind hope you got the solution for your problem.
              – Priyank
              Aug 22 at 11:29










            • Yes, Thanks for the time :)
              – LAW
              Aug 22 at 11:34

















            up vote
            1
            down vote













            The answer shared by 2 is correct but just to update the code which worked for me -



            There are 2 ways which I tried, and I am writing both the code here because both worked(There may be other ways also).



            1) If you want to delete via delete method of Magento2 which is not so optimum way, but still want to share.



            $connection->delete($connection->getTableName('core_config_data'),['path=?'=>'section/group/field']);


            2) The link share by Priyank which has code by Marius -



            use MagentoFrameworkModelAbstractModel;
            use MagentoFrameworkSetupUninstallInterface;
            use MagentoFrameworkSetupModuleContextInterface;
            use MagentoFrameworkSetupSchemaSetupInterface;
            use MagentoConfigModelResourceModelConfigData;
            use MagentoConfigModelResourceModelConfigDataCollectionFactory;

            public function __construct(
            CollectionFactory $collectionFactory,
            Data $configResource
            )

            $this->collectionFactory = $collectionFactory;
            $this->configResource = $configResource;



            In the public function Uninstall add the code



            $collection = $this->collectionFactory->create()
            ->addPathFilter('section_id');
            foreach ($collection as $config)
            $this->deleteConfig($config);



            Then add the function -



            protected function deleteConfig(AbstractModel $config)

            $this->configResource->delete($config);




            And Yes code from setup_module gets removed by itself







            share|improve this answer




















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "479"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f239181%2fmagento2-delete-config-row-while-extension-uninstall%23new-answer', 'question_page');

              );

              Post as a guest






























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote



              accepted










              from setup module it should be deleted automatically (might be wrong on this one), but from the config table you should delete them using the same uninstall script.



              If the record from the setup_module table is not deleted automatically, you can do it from the same uninstall script.



              If this is not your module then it means the uninstall script is not properly coded.






              share|improve this answer
























                up vote
                1
                down vote



                accepted










                from setup module it should be deleted automatically (might be wrong on this one), but from the config table you should delete them using the same uninstall script.



                If the record from the setup_module table is not deleted automatically, you can do it from the same uninstall script.



                If this is not your module then it means the uninstall script is not properly coded.






                share|improve this answer






















                  up vote
                  1
                  down vote



                  accepted







                  up vote
                  1
                  down vote



                  accepted






                  from setup module it should be deleted automatically (might be wrong on this one), but from the config table you should delete them using the same uninstall script.



                  If the record from the setup_module table is not deleted automatically, you can do it from the same uninstall script.



                  If this is not your module then it means the uninstall script is not properly coded.






                  share|improve this answer












                  from setup module it should be deleted automatically (might be wrong on this one), but from the config table you should delete them using the same uninstall script.



                  If the record from the setup_module table is not deleted automatically, you can do it from the same uninstall script.



                  If this is not your module then it means the uninstall script is not properly coded.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 22 at 9:19









                  Marius♦

                  159k26295630




                  159k26295630






















                      up vote
                      3
                      down vote













                      I think Marius has forgotten his own module :)



                      He has created a sample module with an uninstall script you can refer to same.



                       $collection = $this->collectionFactory->create()
                      ->addPathFilter('sample_news');
                      foreach ($collection as $config)
                      $this->configResource->delete($config);



                      Credit to Great Marius






                      share|improve this answer




















                      • I am confused whose answer to verify. You gave me the code which was written by Marius :)
                        – LAW
                        Aug 22 at 11:10










                      • Never mind hope you got the solution for your problem.
                        – Priyank
                        Aug 22 at 11:29










                      • Yes, Thanks for the time :)
                        – LAW
                        Aug 22 at 11:34














                      up vote
                      3
                      down vote













                      I think Marius has forgotten his own module :)



                      He has created a sample module with an uninstall script you can refer to same.



                       $collection = $this->collectionFactory->create()
                      ->addPathFilter('sample_news');
                      foreach ($collection as $config)
                      $this->configResource->delete($config);



                      Credit to Great Marius






                      share|improve this answer




















                      • I am confused whose answer to verify. You gave me the code which was written by Marius :)
                        – LAW
                        Aug 22 at 11:10










                      • Never mind hope you got the solution for your problem.
                        – Priyank
                        Aug 22 at 11:29










                      • Yes, Thanks for the time :)
                        – LAW
                        Aug 22 at 11:34












                      up vote
                      3
                      down vote










                      up vote
                      3
                      down vote









                      I think Marius has forgotten his own module :)



                      He has created a sample module with an uninstall script you can refer to same.



                       $collection = $this->collectionFactory->create()
                      ->addPathFilter('sample_news');
                      foreach ($collection as $config)
                      $this->configResource->delete($config);



                      Credit to Great Marius






                      share|improve this answer












                      I think Marius has forgotten his own module :)



                      He has created a sample module with an uninstall script you can refer to same.



                       $collection = $this->collectionFactory->create()
                      ->addPathFilter('sample_news');
                      foreach ($collection as $config)
                      $this->configResource->delete($config);



                      Credit to Great Marius







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Aug 22 at 9:26









                      Priyank

                      4,64331744




                      4,64331744











                      • I am confused whose answer to verify. You gave me the code which was written by Marius :)
                        – LAW
                        Aug 22 at 11:10










                      • Never mind hope you got the solution for your problem.
                        – Priyank
                        Aug 22 at 11:29










                      • Yes, Thanks for the time :)
                        – LAW
                        Aug 22 at 11:34
















                      • I am confused whose answer to verify. You gave me the code which was written by Marius :)
                        – LAW
                        Aug 22 at 11:10










                      • Never mind hope you got the solution for your problem.
                        – Priyank
                        Aug 22 at 11:29










                      • Yes, Thanks for the time :)
                        – LAW
                        Aug 22 at 11:34















                      I am confused whose answer to verify. You gave me the code which was written by Marius :)
                      – LAW
                      Aug 22 at 11:10




                      I am confused whose answer to verify. You gave me the code which was written by Marius :)
                      – LAW
                      Aug 22 at 11:10












                      Never mind hope you got the solution for your problem.
                      – Priyank
                      Aug 22 at 11:29




                      Never mind hope you got the solution for your problem.
                      – Priyank
                      Aug 22 at 11:29












                      Yes, Thanks for the time :)
                      – LAW
                      Aug 22 at 11:34




                      Yes, Thanks for the time :)
                      – LAW
                      Aug 22 at 11:34










                      up vote
                      1
                      down vote













                      The answer shared by 2 is correct but just to update the code which worked for me -



                      There are 2 ways which I tried, and I am writing both the code here because both worked(There may be other ways also).



                      1) If you want to delete via delete method of Magento2 which is not so optimum way, but still want to share.



                      $connection->delete($connection->getTableName('core_config_data'),['path=?'=>'section/group/field']);


                      2) The link share by Priyank which has code by Marius -



                      use MagentoFrameworkModelAbstractModel;
                      use MagentoFrameworkSetupUninstallInterface;
                      use MagentoFrameworkSetupModuleContextInterface;
                      use MagentoFrameworkSetupSchemaSetupInterface;
                      use MagentoConfigModelResourceModelConfigData;
                      use MagentoConfigModelResourceModelConfigDataCollectionFactory;

                      public function __construct(
                      CollectionFactory $collectionFactory,
                      Data $configResource
                      )

                      $this->collectionFactory = $collectionFactory;
                      $this->configResource = $configResource;



                      In the public function Uninstall add the code



                      $collection = $this->collectionFactory->create()
                      ->addPathFilter('section_id');
                      foreach ($collection as $config)
                      $this->deleteConfig($config);



                      Then add the function -



                      protected function deleteConfig(AbstractModel $config)

                      $this->configResource->delete($config);




                      And Yes code from setup_module gets removed by itself







                      share|improve this answer
























                        up vote
                        1
                        down vote













                        The answer shared by 2 is correct but just to update the code which worked for me -



                        There are 2 ways which I tried, and I am writing both the code here because both worked(There may be other ways also).



                        1) If you want to delete via delete method of Magento2 which is not so optimum way, but still want to share.



                        $connection->delete($connection->getTableName('core_config_data'),['path=?'=>'section/group/field']);


                        2) The link share by Priyank which has code by Marius -



                        use MagentoFrameworkModelAbstractModel;
                        use MagentoFrameworkSetupUninstallInterface;
                        use MagentoFrameworkSetupModuleContextInterface;
                        use MagentoFrameworkSetupSchemaSetupInterface;
                        use MagentoConfigModelResourceModelConfigData;
                        use MagentoConfigModelResourceModelConfigDataCollectionFactory;

                        public function __construct(
                        CollectionFactory $collectionFactory,
                        Data $configResource
                        )

                        $this->collectionFactory = $collectionFactory;
                        $this->configResource = $configResource;



                        In the public function Uninstall add the code



                        $collection = $this->collectionFactory->create()
                        ->addPathFilter('section_id');
                        foreach ($collection as $config)
                        $this->deleteConfig($config);



                        Then add the function -



                        protected function deleteConfig(AbstractModel $config)

                        $this->configResource->delete($config);




                        And Yes code from setup_module gets removed by itself







                        share|improve this answer






















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          The answer shared by 2 is correct but just to update the code which worked for me -



                          There are 2 ways which I tried, and I am writing both the code here because both worked(There may be other ways also).



                          1) If you want to delete via delete method of Magento2 which is not so optimum way, but still want to share.



                          $connection->delete($connection->getTableName('core_config_data'),['path=?'=>'section/group/field']);


                          2) The link share by Priyank which has code by Marius -



                          use MagentoFrameworkModelAbstractModel;
                          use MagentoFrameworkSetupUninstallInterface;
                          use MagentoFrameworkSetupModuleContextInterface;
                          use MagentoFrameworkSetupSchemaSetupInterface;
                          use MagentoConfigModelResourceModelConfigData;
                          use MagentoConfigModelResourceModelConfigDataCollectionFactory;

                          public function __construct(
                          CollectionFactory $collectionFactory,
                          Data $configResource
                          )

                          $this->collectionFactory = $collectionFactory;
                          $this->configResource = $configResource;



                          In the public function Uninstall add the code



                          $collection = $this->collectionFactory->create()
                          ->addPathFilter('section_id');
                          foreach ($collection as $config)
                          $this->deleteConfig($config);



                          Then add the function -



                          protected function deleteConfig(AbstractModel $config)

                          $this->configResource->delete($config);




                          And Yes code from setup_module gets removed by itself







                          share|improve this answer












                          The answer shared by 2 is correct but just to update the code which worked for me -



                          There are 2 ways which I tried, and I am writing both the code here because both worked(There may be other ways also).



                          1) If you want to delete via delete method of Magento2 which is not so optimum way, but still want to share.



                          $connection->delete($connection->getTableName('core_config_data'),['path=?'=>'section/group/field']);


                          2) The link share by Priyank which has code by Marius -



                          use MagentoFrameworkModelAbstractModel;
                          use MagentoFrameworkSetupUninstallInterface;
                          use MagentoFrameworkSetupModuleContextInterface;
                          use MagentoFrameworkSetupSchemaSetupInterface;
                          use MagentoConfigModelResourceModelConfigData;
                          use MagentoConfigModelResourceModelConfigDataCollectionFactory;

                          public function __construct(
                          CollectionFactory $collectionFactory,
                          Data $configResource
                          )

                          $this->collectionFactory = $collectionFactory;
                          $this->configResource = $configResource;



                          In the public function Uninstall add the code



                          $collection = $this->collectionFactory->create()
                          ->addPathFilter('section_id');
                          foreach ($collection as $config)
                          $this->deleteConfig($config);



                          Then add the function -



                          protected function deleteConfig(AbstractModel $config)

                          $this->configResource->delete($config);




                          And Yes code from setup_module gets removed by itself








                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Aug 22 at 11:15









                          LAW

                          803516




                          803516



























                               

                              draft saved


                              draft discarded















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f239181%2fmagento2-delete-config-row-while-extension-uninstall%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              Comments

                              Popular posts from this blog

                              What does second last employer means? [closed]

                              List of Gilmore Girls characters

                              Confectionery