Jump to content
Gadgetto

Module uninstall when Fieldtype is still in use?

Recommended Posts

I'm developing a module which comes with 3 other integrated (and required) modules. On of them is a custom selector FieldType which gets its data from a helper class within the main module. The problem is if one wants to uninstall the main module but wants to preserve the pages which uses the custom selector FieldType, the uninstallation process is interrupted as this FieldType is still in use.

I first thought to simply let the FieldType installed (standalone), but it has dependencies in a helper class which won't work when main module is un installed.

Do you have an idea how to solve this? Should I eventually convert to another Fieldtype (e.g. FieldTypeText) while uninstalling this? Is this even possible?

Share this post


Link to post
Share on other sites

AFAIK, you can't uninstall any Filetype module that is in use. My experience is that I have to drop the fields out of all templates before I'm able to uninstall field-modules. And this makes sence. :-)

Share this post


Link to post
Share on other sites
1 hour ago, horst said:

AFAIK, you can't uninstall any Filetype module that is in use. My experience is that I have to drop the fields out of all templates before I'm able to uninstall field-modules. And this makes sence. 🙂

Yep, I know. Therefore I'd like to use your hook you posted above to prevent an uninstallation mess. Currently, if someone uninstalls my module and the FieldType submodule is still in use the uninstall process is interrupted and parts of my module stay installed.

Your code snippet seems to handle exactly this. I just wanted to know in which module to place this hook.

Sorry, I just had a chat with @bernhard and confused your post with bernhard's.

  • Like 1

Share this post


Link to post
Share on other sites
On 2/25/2020 at 6:53 PM, horst said:

AFAIK, you can't uninstall any Filetype module that is in use. My experience is that I have to drop the fields out of all templates before I'm able to uninstall field-modules. And this makes sence. 🙂

I still have no idea on how to handle this problem within my module (SnipWire) properly. The main module comes with 3 required sub-modules and one of them is a custom field type. The custom field type has dependencies in helpers classes of the main module. What should I do if someone tries to uninstall the main module but the custom field type is still in use?

Should I prevent uninstallation of the complete module package? Or let the user uninstall the main module but only let the custom field type installed (which would lead to problems because of the dependencies)?

One idea is to convert the field which uses the custom field type to a simple text field when the custom field type is uninstalled.

Share this post


Link to post
Share on other sites

I think this is hard to say when we don't know the exact setup. I could think of these options:

  • Prevent uninstall (as you said).
  • Convert the fieldtype (as you said).
  • Move the dependencies out of SnipWire into the Fieldtype. This means SnipWire could not live without the Fieldtype but the Fieldtype could live without SnipWire.
  • Move the helper functions in a separate module that both SnipWire and the Fieldtype can use as a dependency.
  • Maybe static methods are an option? https://www.php.net/manual/en/language.oop5.static.php Though I think you can't access the $wire object in static methods, so that might not be the easiest option, because you can't use all of PW's internal tools.
  • Like 2

Share this post


Link to post
Share on other sites
On 2/28/2020 at 10:34 AM, bernhard said:

I think this is hard to say when we don't know the exact setup. I could think of these options:

  • Prevent uninstall (as you said).
  • Convert the fieldtype (as you said).
  • Move the dependencies out of SnipWire into the Fieldtype. This means SnipWire could not live without the Fieldtype but the Fieldtype could live without SnipWire.
  • Move the helper functions in a separate module that both SnipWire and the Fieldtype can use as a dependency.
  • Maybe static methods are an option? https://www.php.net/manual/en/language.oop5.static.php Though I think you can't access the $wire object in static methods, so that might not be the easiest option, because you can't use all of PW's internal tools.

Thanks @bernhard, problem solved! I decided to use the "convert field type" method.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...