0

This the directory structure of my drupal 8 installation:

├── composer.json
├── composer.lock
├── drush
├── LICENSE
├── load.environment.php
├── phpunit.xml.dist
├── README.md
├── scripts
├── vendor
└── web
    ├── autoload.php
    ├── core
    ├── index.php
    ├── modules
    │   └── custom
    │       └── xyz (version 1.0)
    ├── profiles
    │   └── custom
    │       └── qwer
    │           └── modules
    │               └── custom
    │                   └── xyz (version 1.1)
    ├── robots.txt
    ├── sites
    │   └── example.com
    │       └── modules
    │           └── custom
    │               └── xyz (version 1.2)
    ├── themes
    ├── update.php
    └── web.config

Which version of xyz module "win" in this structure ? For example: - A site installed with qwer profile (sites/example.com). - A site installed without qwer profile (sites/example.com). - Another option ?

I would like to know the preference that Drupal has when it have the same module with different versions in several places

2
  • 1
    From my experience the one that's been installed first will "win". But unsure how it will work with a fresh setup and xyz not installed at all but listed on the /admin/modules page. The only person who can test this quickly is you.
    – leymannx
    Commented Jul 25, 2019 at 17:23
  • I know in D7 the sites overrode everything and I think modules overrode profiles. However not sure if this logic survived the conversion to symphony et. al.
    – CG Monroe
    Commented Jul 30, 2019 at 14:05

1 Answer 1

2

If each copy of the module in the directory structure is in fact a different version (the module's .info file must specify a version number), you can inspect the version listing either via Drush or on the modules listing (install) page.

Version Listing from the Modules Listing page

  1. Navigate to /admin/modules
  2. Find module "xyz" and expand the description section to reveal which version is being detected/loaded.
  3. Refer to the example screenshot below, where Activity Tracker has been expanded.

module-version-info

Version Listing via Drush

  1. Run 'drush pm-list --no-core --status Enabled' to show a list of all modules other than those included with Drupal Core.
  2. Scroll through the list to find your custom module and note the version number in the right column.
  3. Refer to example screenshot below.

drush package list example

What if there are no version numbers, or they are all the same version?

  1. Temporarily modify the version number in the info file.
  2. Push the updated code to your server (if not a local copy of the site).
  3. Flush Drupal Cache, rebuild the registry.
  4. Follow the instructions above to detect which one is used.
  5. Reset the version number and push the updated code to your server (if not a local copy of the site).

Drupal Multisite Note:

If you are running Drupal Multisite, each site with the custom module enabled may be referencing it from a different path (depending on where the module was located at the time the site was being built).

  1. In this situation, check the versions on each site using the instructions above.
  2. Find the most updated version being used so that you can consolidate all the other sites to use the same version/instance.

Consolidating duplicate instances of the module

Since this is a custom module, be sure to check that the functionality provided between versions is in fact the same and that there is an upgrade path between them before consolidating. Sometimes, lesser experienced developers will copy a custom module and completely overhaul its functionality for use on a similar or different site without understanding best practices.

  1. Backup your code and databases, just in case you need to rollback.
  2. Remove older versions/unused copies, ideally keeping/moving your one copy of the module in /web/modules/custom/.
  3. Push the updated codebase to your server.
  4. Clear caches and rebuild the registry.
  5. Run update.php or drush updatedb to ensure any update hooks for the module are applied.
  6. Test the functionality the module provides on each site (for some custom modules, you may need to edit/resave the configuration settings for the module to properly function).
  7. If all is working, it's recommended to create a new restore point backup; otherwise troubleshoot until you get it working or rollback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.