craftcms / digital-products

Sell digital products with Craft Commerce.
https://plugins.craftcms.com/digital-products
MIT License
18 stars 9 forks source link

[4.x]: Uninstall fails #80

Closed alexanderloewe closed 1 year ago

alexanderloewe commented 1 year ago

What happened?

I'm trying to uninstall the digital-products plugin, but i can't uninstall it. I have tried it in different installations, via CP and via CLI.

Bildschirm­foto 2022-12-17 um 22 13 33
php ./craft plugin/uninstall digital-products
*** uninstalling digital-products
Exception: Attempt to read property "foreignKeys" on null (/home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/helpers/Db.php:1829)
#0 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/helpers/Db.php(1829): yii\base\ErrorHandler->handleError(2, 'Attempt to read...', '/home/wedotch/p...', 1829)
craftcms/cms#1 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/helpers/Db.php(1207): craft\helpers\Db::findForeignKey('digitalproducts...', Array, Object(craft\db\Connection))
craftcms/cms#2 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/digital-products/src/migrations/Install.php(156): craft\helpers\Db::dropForeignKeyIfExists('{{%digitalprodu...', Array)
craftcms/cms#3 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/digital-products/src/migrations/Install.php(36): craft\digitalproducts\migrations\Install->dropForeignKeys()
craftcms/cms#4 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/db/Migration.php(82): craft\digitalproducts\migrations\Install->safeDown()
craftcms/cms#5 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/db/MigrationManager.php(294): craft\db\Migration->down(true)
craftcms/cms#6 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/base/Plugin.php(165): craft\db\MigrationManager->migrateDown(Object(craft\digitalproducts\migrations\Install))
craftcms/cms#7 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/services/Plugins.php(621): craft\base\Plugin->uninstall()
craftcms/cms#8 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/console/controllers/PluginController.php(170): craft\services\Plugins->uninstallPlugin('digital-product...', false)
craftcms/cms#9 [internal function]: craft\console\controllers\PluginController->actionUninstall('digital-product...')
craftcms/cms#10 /home/wedotch/public_html/crafttpl/masterTPL/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
craftcms/cms#11 /home/wedotch/public_html/crafttpl/masterTPL/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
craftcms/cms#12 /home/wedotch/public_html/crafttpl/masterTPL/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('uninstall', Array)
craftcms/cms#13 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/console/Controller.php(227): yii\console\Controller->runAction('uninstall', Array)
craftcms/cms#14 /home/wedotch/public_html/crafttpl/masterTPL/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('uninstall', Array)
craftcms/cms#15 /home/wedotch/public_html/crafttpl/masterTPL/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('plugin/uninstal...', Array)
craftcms/cms#16 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/console/Application.php(90): yii\console\Application->runAction('plugin/uninstal...', Array)
craftcms/cms#17 /home/wedotch/public_html/crafttpl/masterTPL/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('plugin/uninstal...', Array)
craftcms/cms#18 /home/wedotch/public_html/crafttpl/masterTPL/vendor/craftcms/cms/src/console/Application.php(121): yii\console\Application->handleRequest(Object(craft\console\Request))
craftcms/cms#19 /home/wedotch/public_html/crafttpl/masterTPL/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
craftcms/cms#20 /home/wedotch/public_html/crafttpl/masterTPL/craft(24): yii\base\Application->run()
craftcms/cms#21 {main}
*** failed to uninstall digital-products: An error occurred while executing the "craft\digitalproducts\migrations\Install migration: Attempt to read property "foreignKeys" on null
Try again with --force.

Craft CMS version

Craft CMS 4.3.5

PHP version

8.1

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

brianjhanson commented 1 year ago

Thanks for reporting! This looks like an issue with the digital products plugin so I've moved this over there.

The elementindexsettings table was removed in Craft 4, but there's a leftover reference to it in this plugin. That causes an exception to be thrown when uninstalling the first time which prevents the uninstall from reporting as successful. Subsequent uninstall attempts will then throw the exception you're seeing.

When you get this error the plugin is effectively uninstalled though. The foreign keys and tables have been dropped. If the uninstall failing isn't causing other errors, you can safely ignore this error.

alexanderloewe commented 1 year ago

The problem is, by uninstalling the plugin by hand some informations are left in the db or in the project config files.

brianjhanson commented 1 year ago

In my testing, the original exception was thrown here. By that point, the DB should be cleaned up. What information are you seeing left over in the DB and project config?

alexanderloewe commented 1 year ago

Because when i rebuild the project config files from the database here is still some information about the plugin inside the files.

brianjhanson commented 1 year ago

Sorry, I should have been more clear. What specific information are you still seeing in the files?

lukeholder commented 1 year ago

@alexanderloewe Could you please open a new issue in this repo with steps to reproduce.

This issue is closed due to the original bug being fixed in the next release.

lukeholder commented 1 year ago

This was fixed in 3.2.0 just released.