Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-on with inverse relationships uninstall creates a problem when dropping the table #1901

Closed
gb-lin opened this issue Mar 18, 2022 · 4 comments
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.

Comments

@gb-lin
Copy link

gb-lin commented Mar 18, 2022

Working on a custom add-on (fieldtype and extension and module) here and I have a model with inverse relationships to ChannelEntry and ChannelField. When I uninstall, I'm also dropping the custom table that the model saves to. However, I tired putting the drop table sequence in the ft. and the upd. and both places will result in SQLSTATE[42S02]: Base table or view not found: 1146 Table 'playground.exp_gb_gated_content_keys' doesn't exist. From the trace I can see that it's the uninstallFieldtype() method that's calling for the deletion of the fieldtype which will trigger the deletion of the related custom model's rows. But somehow that's happening after the table is dropped. What is the last sequence that runs that I can use to delete my custom table? I also tried using weak in the model and it doesn't work.

#0 ee/legacy/database/drivers/mysqli/mysqli_driver.php(112): CI_DB_mysqli_connection->query()
#1 ee/legacy/database/DB_driver.php(260): CI_DB_mysqli_driver->_execute()
#2 ee/legacy/database/DB_driver.php(175): CI_DB_driver->simple_query()
#3 ee/legacy/database/DB_active_rec.php(1076): CI_DB_driver->query()
#4 ee/ExpressionEngine/Service/Model/Query/Select.php(51): CI_DB_active_record->get()
#5 ee/ExpressionEngine/Service/Model/DataStore.php(275): ExpressionEngine\Service\Model\Query\Select->run()
#6 ee/ExpressionEngine/Service/Model/DataStore.php(220): ExpressionEngine\Service\Model\DataStore->runQuery()
#7 ee/ExpressionEngine/Service/Model/Query/Builder.php(138): ExpressionEngine\Service\Model\DataStore->selectQuery()
#8 ee/ExpressionEngine/Service/Model/Query/Builder.php(63): ExpressionEngine\Service\Model\Query\Builder->fetch()
#9 ee/ExpressionEngine/Service/Model/Query/Delete.php(352): ExpressionEngine\Service\Model\Query\Builder->all()
#10 ee/ExpressionEngine/Service/Model/Query/Delete.php(67): ExpressionEngine\Service\Model\Query\Delete->ExpressionEngine\Service\Model\Query{closure}()
#11 ee/ExpressionEngine/Service/Model/DataStore.php(275): ExpressionEngine\Service\Model\Query\Delete->run()
#12 ee/ExpressionEngine/Service/Model/DataStore.php(250): ExpressionEngine\Service\Model\DataStore->runQuery()
#13 ee/ExpressionEngine/Service/Model/Query/Builder.php(87): ExpressionEngine\Service\Model\DataStore->deleteQuery()
#14 ee/legacy/libraries/addons/Addons_installer.php(314): ExpressionEngine\Service\Model\Query\Builder->delete()
#15 ee/legacy/libraries/addons/Addons_installer.php(51): Addons_installer->_update_addon()
#16 ee/ExpressionEngine/Controller/Addons/Addons.php(1415): Addons_installer->uninstall()
#17 ee/ExpressionEngine/Controller/Addons/Addons.php(670): ExpressionEngine\Controller\Addons\Addons->uninstallFieldtype()
#18 [internal function]: ExpressionEngine\Controller\Addons\Addons->remove()

@gb-lin
Copy link
Author

gb-lin commented Mar 20, 2022

Here's an example fieldtype that I made to demonstrate: https://github.com/gb-lin/Example-Fieldtype/

@intoeetive
Copy link
Contributor

Looking at associated EE code, I see that the module is getting uninstalled prior to the fieldtype. Which might be what is expected - if the fieldtype is using custom table, it probably should exists when fieldtype is getting removed.

So maybe you need to have uninstall() function in your ft. file that will remove the table, not in the upd. file

@gb-lin
Copy link
Author

gb-lin commented Mar 21, 2022

Hey @intoeetive I actually tried putting the drop_table sequence in the ft. uninstall() and it also shows the same error. I tested in both 6.2.3 and 6.2.7. This happens when models.dependencies is defined in addon.setup.php.

@intoeetive intoeetive added the Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on. label Mar 23, 2022
intoeetive added a commit that referenced this issue Mar 23, 2022
to have the fieldtype dropped before dropping the related model

fixes #1901

EECORE-1741
@intoeetive
Copy link
Contributor

@gb-lin unfortunately the "fix" we made was not right. We have to revert it because it causes issues with other add-ons.

Re-opening the issue until we get better fix for add-ons that use the (almost not documented) models.dependencies feature (can't yet provide any ETA for it)

@intoeetive intoeetive reopened this Sep 1, 2022
matthewjohns0n added a commit that referenced this issue Sep 1, 2022
…l-revert

Revert "Resolved #1901 where add-ons with related models were not properly uninstalled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Accepted Bug has been confirmed, is reproducible, and ready to work on.
Projects
None yet
2 participants