backdrop / backdrop-issues

Issue tracker for Backdrop core.
144 stars 40 forks source link

Offer to remove module dependencies that are no longer needed #3582

Open ghost opened 5 years ago

ghost commented 5 years ago

Description of the need On Linux, when you remove a package that has dependencies (which aren't used by any other installed package), you'll be told that those dependencies are no longer needed and can be safely removed. It'd be cool to have something similar in Backdrop. This would help to reduce situations where a site has modules installed that it doesn't need because the module(s) that depended on them was uninstalled (e.g. Libraries, Field Formatter Settings, etc.).

Proposed solution No idea, just putting the thought out there :smiley:

ghost commented 4 years ago

Here's an example: You want to use the manualcrop module. It depends on the imgareaselect and imagesloaded modules, so all 3 are installed together. In the future, you decide you no longer need manualcrop and so uninstall it. However imgareaselect and imagesloaded and still installed, and still require updating, etc.

Ideally there'd be a list of dependencies somewhere to keep track of this. So when manualcrop was installed, imgareaselect and imagesloaded would be added to this list as dependencies of manualcrop. E.g.:

$module_dependencies = array(
  'imgareaselect' => array('manualcrop'),
  'imagesloaded' => array('manualcrop'),
);

When manualcrop is uninstalled the list is updated as such:

$module_dependencies = array(
  'imgareaselect' => array(),
  'imagesloaded' => array(),
);

Since those module are no longer required by anything, a message can be displayed informing the user that they can be safely removed.

If, while manualcrop is still installed, another module that requires one of these is also installed, the list can be updated as such:

$module_dependencies = array(
  'imgareaselect' => array('manualcrop'),
  'imagesloaded' => array('manualcrop', 'masonry'),
);

So when manualcrop is uninstalled now, imgareaselect can be removed, but not imagesloaded since it's still required by an active module.

The only problem I see with this is when a dependency (e.g. imagesloaded) is used in another way. For example, if it provides functionality of its own, or if it's used by a custom module, that'll cause issues. Not sure how to address that...

laryn commented 4 years ago

I think this is a good idea, especially if it is providing an easy option to disable the seemingly unused dependencies but not requiring it. Then if it's still required for something else or providing functionality on its own, the admin can decline to disable it. OR, it could just be a message that pops up saying that no more installed modules are dependent on X module, and that the admin can consider disabling it if they don't need it anymore.

An alternative to tracking this in an ongoing way, how about just looking at the dependencies of the modules being disabled and running through to check all activated modules at that time? Is that too big of a performance hit when disabling modules?

ghost commented 4 years ago

I think tracking them in an ongoing way is better, then we can provide a report page that lists all installed modules and any dependencies. The system can display a message when modules are installed with no dependencies left, and maybe there can be an option for each one where admins can mark it as required manually, so it won't show up in messages anymore (i.e. if they install imagesloaded because some custom code uses it, they can mark imagesloaded as required which stop the system saying it can be uninstalled).

klonos commented 4 years ago

The only problem I see with this is when a dependency (e.g. imagesloaded) is used in another way. For example, if it provides functionality of its own, or if it's used by a custom module, that'll cause issues. Not sure how to address that...

My main concern is this ^^ ...and the fact that this seems like a potential way to be providing "young" admins with a gun to shoot themselves on the foot. If a site admin inherits the site, they may not know what certain modules may have been used for. Showing warnings that urge them to action (either remove no-longer-needed modules, or dismiss the message) may have the effect of added stress/complexity, and people may just be compelled to remove something which would otherwise be safe to just leave alone 🤷