I have a relation type name "order_customer":

source_bundles = array(
    0 => 'order:*',
    1 => 'customer:*',
);

Entity type "order" is defined in module "order".
Entity type "customer" is defined in module "customer".

Relation type "order_customer" is created when module "customer" is installed. After i install 2 modules, relation type "order_customer" is created and everything is ok.
But when i disable module customer. I get the error message:

Notice: Undefined index: customer in relation_views_data_alter() (line 188 of /data/www/myapp/sites/all/modules/contrib/relation/views/relation.views.inc).

When i disable module "customer", entity type "customer" is also disable, but relation type between "order" and "customer" still exists in database. So i get this error message.

Comments

howto’s picture

Assigned: Unassigned » howto
Status: Active » Needs review
StatusFileSize
new1.22 KB

Upload a patch to fix this problem.

howto’s picture

StatusFileSize
new1.24 KB

We need to check $source_bundle is "*"
I apply new patch. Sorry for spam.

mikran’s picture

Category: bug » support

If the relation is provided by the 'customer' module shouldn't that module also take care of disabling views and relations that were provided by said module? Changing to support request for now as I can't really catch the bug in here

steveoliver’s picture

Title: Display error message when disable module provide relation » How do I clean up after disabling my custom module?
Status: Needs review » Closed (cannot reproduce)

To #3's point:

that module also take care of disabling views and relations that were provided by said module

, you'll need to implement hook_disable in your custom module. Best of luck. Changing title and marking closed.

zkday’s picture

Assigned: howto » Unassigned
Category: support » bug
Status: Closed (cannot reproduce) » Active

This module should fixed this bug!

In this case, the relation module have used and created this information (relationship from order to customer). I thinks, relation module need support for fixing this bug!

naught101’s picture

Status: Active » Postponed (maintainer needs more info)

I don't really see how this is relation's problem. If the relation was created manually, then just delete it. If it was created by the custom module, then the custom module should delete it, as per #4.

The other options would be:

  1. for relation to try to prevent the module from being disabled if there is a relation that depends on it (I don't think this is possible)
  2. remove the entity type from the relation type definition. This would be difficult if the entity type is the last entity type in the relation type definition, what would you do then?
  3. delete the relation type entirely. What happens if there are still other legitimate uses for this relation type?

Either of the last two should be possible with hook_entity_bundle_delete(), however this is D8 only, and there is no equivalent in D7, so this code would have to implement each hook_[entity]_type_delete manually, which wouldn't work for custom module's custom entity types anyway.

So zkday: I agree, relation does need support for fixing this bug. If you have any good ideas, or patches, let us know. For the moment though, I'm inclined to think that this is such an edge case that it's not worth dealing with.

ayalas’s picture

I am having this problem too.

Deleting relations in hook_disable is not a good solution, because all the module's other data remains until the module is uninstalled. So, if the module is re-enabled, we end up with all the data, just without the relations, i.e. with a corrupted data.

If there was a way to disable and enable the relation types that would have helped - and such code should indeed be in hook_enable/disable.

naught101’s picture

Interesting idea ayalas. See discussion at #1976546: Add managed flags to relation type table

naught101’s picture

Issue summary: View changes

Fix some typo

mikran’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (won't fix)

I don't think there really is anything relation can do here, in D7 at least.

There are similar problems elsewhere too, for example taxonomy references don't get deleted when you delete taxonomy term / vocab (see https://www.drupal.org/project/taxonomy_orphanage).