When disabling all of ubercart's modules (and I'm not talking "uninstalling", just disabling), I get the following notices near the end of the process:

The content fields table content_type_event has been deleted.
The content fields table content_type_product has been deleted.
The configuration options have been saved.

content_type_event is a CCK node type I created before I installed ubercart. And ubercart killing that node type is a huge bug!

The content is still there. I think. I say "I think" because it doesn't show any of the fields I added to those nodes, just the title and body. Devel module's "dev load" tab shows that those nodes are still "event" types. And when I try to edit such a node, I get the error:

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'event_node_form' was given in /www/includes/form.inc on line 218.

Now beside the fact that UC should not be doing this on a D5 site, since most major Drupal upgrade instructions say you should uninstall any modules, upgrade Drupal core, and then re-enable the 6.x version s of your contrib modules, this is going to be a huge data loss issue when migrating to D6.

I'm not sure which module did this. I suspect uc_product, but I can't find any HOOK_disable() functions that would be doing something like this.

CommentFileSizeAuthor
#7 node_type.patch6.98 KBIsland Usurper

Comments

Island Usurper’s picture

Status: Active » Closed (duplicate)

There's actually a combination of things happening here. When uc_product is disabled, hook_node_info() no longer has a record of that node type. When this happens CCK deletes the fields that were attached to the node type. This was brought up some time back at #196042: Field instances are deleted when node type modules are disabled, should wait until they are uninstalled

So yeah. Big, old problem.

johnalbin’s picture

Priority: Critical » Normal
Status: Closed (duplicate) » Postponed (maintainer needs more info)

(Marking this "active (needs more info)" temporarily so it appears in the UC issue queue as an FYI.)

So, wait, because I had UC add some fields to an existing CCK node type, CCK deletes the node type when UC is disabled? I can understand why UC's fields might be deleted, but not why the node type.

It sounds like UC is doing something to the CCK node type to make it a UC node type. Couldn't you use HOOK_disable() to set it back to a CCK node type?

My understanding of this is a bit sketchy. Any pointers to specific hooks that are being fired when UC is disabled and when it takes over an existing CCK node would be appreciated. For example, I see the node type deletion message in content_type_delete(), but I don't know how that is being called, since I'm only disabling a module and not intentionally trying to delete a content type. Surely, only HOOK_disable() is being called?

Island Usurper’s picture

Title: Node types deleted when disabling module » Node types and their CCK data deleted when disabling module
Status: Postponed (maintainer needs more info) » Closed (duplicate)

It's actually not any hooks that are doing it. When the module list form is submitted, it calls node_type_rebuild(). This function takes all the node types that are marked "disabled" (which happens because they aren't in hook_node_info() anymore) and calls node_type_delete(). This in turn calls hook_node_type(), which CCK uses to delete all of its data, because it's been told that that node type doesn't exist any more.

Using hook_disable() to relinquish control of the product node types is my plan, but only as a stop-gap measure. I'm also going to try to take them back with hook_enable(), but I can see that being tricky.

Just to make it clear, the nodes aren't gone. It's the CCK data that was added to them. Even if they were just "product" nodes, the same thing would happen. This problem affects all modules that implement hook_node_info(). I imagine this is part of why node type modules have become passé.

johnalbin’s picture

Title: Node types and their CCK data deleted when disabling module » Prevent node types and their CCK data being deleted when disabling module
Category: bug » feature
Status: Closed (duplicate) » Active

So it seems a work-around in UC is possible even though the bug is in core, so I'm changing this to an active feature request.

Thanks for the explanation, Lyle.

But what I still don't understand is… if I originally created a node type in CCK before making it “purchasable”, why does UC claim it as its own in ubercart_node_info()?

Island Usurper’s picture

Assigned: Unassigned » Island Usurper

All of the functionality of products come from the use of node hooks: hook_view(), hook_insert(), etc. Each node type knows which module's implementations to use when the hooks are called. When a product class is made the node types in essence are told "Stop using node_view(), node_insert(), and node_update(), and start using uc_product_view(), uc_product_insert(), and uc_product_update()." This is how they get the price fields in the edit form and the "Add to Cart" button on their page view.

In hindsight, using hook_nodeapi() may have been a better design choice. But uc_product was my first Drupal module, so I chalk it up to inexperience. Fortunately, it doesn't seem to be something that can't be changed.

Island Usurper’s picture

Status: Active » Needs review

Here's the workaround I've come up with so far. It ended up being more complicated than I thought because I kept running into newly exposed bugs and no-longer-valid assumptions in the code. I think I've covered all the usual situations, but I'm sure someone can pop my bubble easily.

There's one case I'm not sure what to do about. The theoretical steps go thusly:

  • Create a product class that has the same name as some module's node type.
  • Disable Ubercart, changing the node type's module to node.
  • Install the other module, which takes over the node type.
  • Enable Ubercart again.

At best, there's an extra row in {uc_product_classes} polluting the database. At worst, Drupal doesn't know what to do with that node type any more. Any ideas?

I'd really like to be able to rely on users to know what they're doing and clean up after themselves. I'd also like a billion dollars.

Island Usurper’s picture

StatusFileSize
new6.98 KB

Wow. Somehow I managed to go almost a month without realizing I didn't include the patch. Shame on me.

Anyway, I've tested it and it works, but this is certainly the kind of thing that lots of people need to look at.

Island Usurper’s picture

Status: Needs review » Fixed

Well, it's all a moot point now, since CCK no longer deletes its data when node types disappear: #196042: Field instances are deleted when node type modules are disabled, should wait until they are uninstalled
Since no one gave any input on this, I ended up committing that patch anyway.

I suppose it's unnecessary now, but I'm not sure I will actually roll it back. Maybe only for the 2.x version.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.