Magento2 Delete config row while Extension Uninstall
Clash 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.
magento2 module extensions composer uninstall
add a comment |Â
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.
magento2 module extensions composer uninstall
add a comment |Â
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.
magento2 module extensions composer uninstall
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.
magento2 module extensions composer uninstall
edited Aug 22 at 13:13


Priyank
4,64331744
4,64331744
asked Aug 22 at 9:14
LAW
803516
803516
add a comment |Â
add a comment |Â
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.
add a comment |Â
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
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
add a comment |Â
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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered Aug 22 at 9:19


Marius♦
159k26295630
159k26295630
add a comment |Â
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Aug 22 at 11:15
LAW
803516
803516
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password