Installed the glossary module (This issue probably applies to most? contributed modules) in the module folder (not a sub-folder).
Then disabled this module (might be an optional step).

Moved the module file, glossary.module, to a sub-folder within the "module" folder (.ie. modules/glossary/glossary.module).
Re-enable the module.
The glossary modules (GUI) does not appear were it should.
I had the same issue with the "taxonomy_access" module: http://drupal.org/node/46286

Discovered that the "System" table still had the "filename" field set to modules/glossary.module
Updating that value to modules/glossary/glossary.module, by hand, corrected the problem.

I fixed my taxonomy_access isssue similarly.

Ideas:
This update should probably be done when loading or saving the "administer-->module" page or offer a "reset button" (with instruction to click it, if you have recently moved your module around, like into a sub-folder).

This is likely a common issue with newbies, since we initially copy our modules to the "modules" folder, only after 1 or 2 upgrades do we see the value in having all "contributed" modules into sub-folders.

Note: I'm note 100% sure about this, it looks like some modules still work when moved to a sub-folder making the issue even more confusing.

Comments

Steve Simms’s picture

I encountered this problem (using 4.7.0b4) when moving modules from Drupal's main modules folder to a modules folder under the sites directory. It also happened to be the taxonomy_access module in my case, and deleting the row from system solved the problem.

Caleb Case’s picture

Status: Active » Needs review
StatusFileSize
new522 bytes

The function that retrieves system file locations from the database (system_get_files_database) wasn't checking to see if the file's path had changed. With the patch, if module files have moved their new location will be detected when the site admin visits the modules page.

dopry’s picture

Can you try a unified patch file, diff -u original.file new.file > mypatch.patch

Caleb Case’s picture

StatusFileSize
new1.02 KB

k

Caleb Case’s picture

StatusFileSize
new1.23 KB

Heh ;o] a better patch file. Sorry for the floundering I'm a bit new to submitting patches.

chrisd’s picture

In,

I'm just a newbie to Drupal and PHP...

Can someone else test the patch?

----optional unrelated question------
Context: I've been a software engineer & mentor for many years...
Question:
I'm finding lots of bugs and I'm hesitating to post then because I have a difficult time dealing with some follow up questions.
I'm trying no to spend more then 1 to 2 hour per day with Drupal/Modules bugs (since I'm learning this stuff..I got to progress...).
Right now I got 2+ bugs ... I still have to log...

Is it alright to log bugs and, in some instances, let others test patches ?

In this case I'm not up to par with "diff -u original.file new.file > mypatch.patch" and to many changes to surgically apply then.

Is it better not to log the bugs, if I can not always full participate in validating the fix ?

Let me know if you have any advise on this question and thanks for your good and prompt work,
Christophe D

Steve Simms’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.07 KB

Tested on a 4.7.0b4 site, and it worked fine. For completeness, you should also set $file->filename when you're changing it in the database so that the current request uses the right filename. The attached patch adds that.

chrisd: definitely file the bugs. As a software engineer, you know the value of giving clear instructions to reproduce bugs, and that makes fixing them so much easier. Patches can be tested by others as time permits.

dries’s picture

Steve Simms’s picture

Yes, this appears to be the same problem, with different solutions. I think a combination of both would be good.

It might be worth adding a watchdog command to this patch, saying that the system table has been updated. I can do that if anyone else thinks it's worth it.

samo’s picture

Yes, it appears we had the same scenario. I will close out my issue in favor of this one.

@smsimms: Are we sure that $files[$file->name]->filename exists before updating the database? If so, can we add a watchdog comment that the file location was updated?

Thanks,
samo

Steve Simms’s picture

Yes, the function gets passed a list of files based on a directory listing (search the system.module file for calls to the system_get_files_database function to see how the lists are made).

I'm running out for a while now, but I can add the watchdog command to the patch later on this evening if someone else doesn't beat me to it (feel free).

dries’s picture

Please mark one of the issues as duplicate, and continue with one issue instead. Let's go with the solution that has the smallest performance penalty, or that is otherwise considered to be cleanest. I want you guys to figure out the best approach. :)

pfaocle’s picture

+1

Patch works great with beta 4, and fixes the problem described. We'd experienced this one moving sites to our new server recently: we've changed from 'normal', separate Drupal sites where contrib modules were stored under modules/, to a multi-site setup where each sites' modules now reside in sites/default/modules/. At one point we even managed to get our servers IP in the path... :o\

Anyway, thats a bit OT. Patch works great. Not sure of the performance hit of the additional query, but as long as this is called only on admin/modules, there shouldn't be much of a problem. Ready to apply, methinks.

pfaocle’s picture

Title: Problem when moving modules (to sub-folders)... » System table not updated when moving modules
Status: Reviewed & tested by the community » Needs review

Here's one with the watchdog call added. I'd say this is now a NOTICE, rather than an ERROR. Also, I couldn't think of a nicer message... please review.

pfaocle’s picture

StatusFileSize
new1.38 KB

Dang it.

mfredrickson’s picture

Two things:

1. The message gives the new location, not the old location. This could be confusing to users who move a module and then see a message ostensibly saying that the module has moved, again.

2. The admin has to open and save the modules page for this to work. Should it be invoked whenever a module cannot be found? Say on a bad page view.

Otherwise, it's a good fix.

mfredrickson’s picture

Two things:

1. The message gives the new location, not the old location. This could be confusing to users who move a module and then see a message ostensibly saying that the module has moved, again.

2. The admin has to open and save the modules page for this to work. Should it be invoked whenever a module cannot be found? Say on a bad page view.

Otherwise, it's a good fix.

Steve Simms’s picture

I was literally changing the patch to give both filenames when you wrote this. :-)

Also, the first query in the patch needs to be removed. I'll have a new patch uploaded in a few minutes.

Steve

Steve Simms’s picture

Version: 4.7.0-beta4 » x.y.z
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new1.44 KB

Here's the updated patch, against current CVS.

@mfredrickson: With regard to your second comment, the modules page doesn't have to be saved, just opened (or any other activity that triggers a list of modules to be built from the filesystem). Having the list rebuilt every time there's a 404 error would probably get resource-heavy, which may be why it isn't being done now. By all means, file an issue if you think that should be done differently, but I don't think it needs to be a part of this fix.

Steve

pfaocle’s picture

StatusFileSize
new1.42 KB

Looks good to me: tested, working fine. Not quite convinced about the message itself - perhaps we need to explain the message a little, eg: "%oldfile was moved to %newfile. System settings changed accordingly". If no one else agrees, I'd say this was RTC.

Attached patch is a very, very minor tweak of smsimms', to include 2 spaces for indentation on a couple of lines, as per coding standards.

Steven’s picture

We do a file_exists() check for every module include anyway. Why not move the code there? It does not add any additional performance penalty if no modules are missing.

chx’s picture

Status: Reviewed & tested by the community » Needs work
owen barton’s picture

-1 on this patch
We should be using drupal_get_filename() to test/update the systems table, rather than a db_query().

I think that the test is in the correct place however, as it will only be called on admin/modules, and only for moved modules. I don't think the performance hit in this situation makes it worth the extra code to push multiple changes into a single query.
I can't find the file_exists() Steven mentioned.

I will try to have a look at patching this now

owen barton’s picture

StatusFileSize
new879 bytes

OK scratch the part about using drupal_get_filename(), I misread the docs - it only updates the value for the current session.

I did find another location where the fix could fit in quite nicely (see attached patch) - in system_modules(), right before the module is loaded. The only benefit of this over the other patch, is that it seems less likely to duplicate updating, because the themes code already updates the location for each theme after calling system_get_files_database() - which would (I think) cause any moved modules to get updated twice.

The other possibility for fixing this is (which I think is the part Steven is referring to) would be for drupal_get_filename() - right after the file_exists() check - to update the database. The problem with this is I don't know if this is really part of this functions spec or not - and also that this code does not seem to be running when a module is moved.

owen barton’s picture

Status: Needs work » Needs review
Steve Simms’s picture

That works, too. I haven't tested it, but it looks fine.

Is there any reason why for themes and theme engines we wipe out and recreate the system table each time, but for modules, we update it? Shouldn't we be doing the same thing (either delete+insert or update) for all three?

chx’s picture

Status: Needs review » Reviewed & tested by the community

This I have found an excellent piece of code. Very short, to the point and even watchdogs.

eaton’s picture

Status: Reviewed & tested by the community » Needs review

Tested the patches in both comment #20 and #24. #24 didn't seem to recognize when I'd moved a file from a site-specific directory to the overall drupal/modules folder, while #20 handled it flawlessly.

this makes rolling out tests sites a LOT easier, as themes/modules will automatically adapt to a new directory. so, a BIG +1-this-works to the #20 patch. (system_module_moving_files_r2.patch)

chx’s picture

StatusFileSize
new709 bytes

A reroll of the patch in proper Drupal format.

owen barton’s picture

I can confirm that patch #24 does not work for the instance of moving a module to a sites/*/modules directory. I think this must be related to the use of drupal_get_filename to test if the file has moved. Maybe testing for false when compared to $file->filename will catch this case?

owen barton’s picture

StatusFileSize
new1.38 KB

Here is a working patch. It adds one line of new code ($file->oldfilename), and modifies 3 others.

The advantage of this over the patch in #20 is that:
* It doesn't duplicate updates when called from theme code.
* It adds a $file->oldfilename variable, which could be used in another patch to make system_theme_data() update the system table as neccessary, rather than delete & insert everything as it does now).

The advantage over patches #24 and #29 are:
* That it works for situations where the folder is either renamed, moved between /modules <--> /sites/*/modules or both renamed and moved.

There is no watchdog call (the update is invisible to the user), but I don't know how necessary that is, especially if the system works reliably!

chx’s picture

Status: Needs review » Reviewed & tested by the community

Now, this one is real good, no surplus queries and yes it works -- sorry for mine had issues.

pfaocle’s picture

Yup. Tested here on the same site I've tested all the others on - it works fine and dandy.

pfaocle’s picture

Oh, and with regards to watchdog msg or not, I'd say its unneccessary. In most cases it will be the site maintainer who moves themes and modules files around, so Drupal should just deal with it quietly. Nice one, all.

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed

committed. change oldfilename to old_filename.

owen barton’s picture

Status: Fixed » Needs review
StatusFileSize
new1.4 KB

This revised patch should fix an issue where new modules are no longer detected

owen barton’s picture

StatusFileSize
new565 bytes

Here is a patch on HEAD

hunmonk’s picture

StatusFileSize
new615 bytes

the last conditions weren't right. here's one that should do it

Steve Simms’s picture

Status: Needs review » Reviewed & tested by the community

Tested against CVS. This works when a module is moved, and also doesn't break when a module is added.

hunmonk’s picture

StatusFileSize
new613 bytes

same thing, i just had an extra set of parentheses that i needed to remove :)

killes@www.drop.org’s picture

Status: Reviewed & tested by the community » Fixed

applied.

Anonymous’s picture

Status: Fixed » Closed (fixed)