Problems after moving modules to other directories

I have already had this problem several times. So I'm going to write it down here for future cases that may arise.

In my current case I'm upgrading a Drupal 8 to Drupal 9, that website has been created WITHOUT composer (moreover, it doesn't even have GIT, they still work with FTP and have overwritten contrib code). Leaving aside the bad practices followed by the team that made that website, the fact is that most of the modules are not organized in the modules/contrib/ and modules/custom/ directories. In order to be able to update and make my life easier, I decided to convert the website to a Drupal with composer.

When using composer, modules and contrib themes will be stored in their corresponding contrib/ directories and that means that many of the modules have been moved from one directory to another.

When moving code from one location to another, in many cases it is sufficient to clear caches from drush:

drush cr

But in other cases it may not be enough and it is necessary to flush the table caches manually with:

# Truncate cache tables in MySQL regardless of the active cache backend
echo "SHOW TABLES LIKE 'cache%'" | $(drush sql-connect) | tail -n +2 | xargs -L1 -I% echo "TRUNCATE TABLE %;" | $(drush sql-connect) -v

And that's it, you just have to clear the caches, but "drush cr" is not always enough.

And I remind you to always do this first in a controlled environment, never do it directly in production without having tested it first.

Have Any Project in Mind?

If you want to do something in Drupal maybe you can hire me.

Either for consulting, development or maintenance of Drupal websites.