Problem/Motivation

On delete of contact_type (and possibly other) entities, RedHen mass deletes all entities of the type. This leads to two critical problems:

  • Because entity delete is called as part of the Entity API implementation of the Features module feature revert operation, site admins may, unexpectedly and without warning, lose valuable data when reverting.
  • When there are many records, mass deletion may trigger timeouts due to processing time required.

Proposed resolution

  • Make mass deletion of entities optional and defaulting to FALSE.
  • Introduce a UI checkbox to trigger mass deletion.
  • Implement mass deletion using a queue operation
  • .

Remaining tasks

User interface changes

API changes

Original report by @ceng

Hi,

I have a redhen_contact type (bundle) exported to a features module, my bundle is called 'member'. When I try and revert that module, I was getting enormous out of memory exceptions.

Tracing through the code, I find that on a features revert, Features calls EntityDefaultFeaturesController::revert() followed by entity_delete('redhen_contact', 'member'). This in turn calls RedhenContactTypeController::delete(array('member'));

Now, RedhenContactTypeController overrides the delete function of EntityAPIControllerExportable and decides to delete all the entities of that type. *This is not expected Drupal behaviour* as far as I can tell when a content type is deleted. The entities themselves must be left alone.

There are two reasons. Firstly, this appears to be how the popular Features module reverts an entity bundle (as described above) and so isn't really deleting anything, just restoring it to it's natural state (despite being called delete). Secondly, if you have a large number of redhen_contact instances (as my site does) it cannot delete all the entities in one go as RedhenContactTypeController::delete() is trying to do since it will run out of memory. I'd upped to 500Mb and still ran out of memory before investigating, thank goodness I did - it was trying to delete all my CRM data on a feature revert!

So what to do? I suggest removing the delete function from RedhenContactTypeController and so you probably don't need the class at all.

Comments

johnennew’s picture

Note: I'm not a Features expert but what it's trying to do all seems a bit odd. Perhaps you need to override EntityDefaultFeaturesController with a RedHen version that handles the revert properly?

johnennew’s picture

This affects organisational contacts as well. Reverting the redhen_org_type feature deletes all your organisations.

drush fr myfeature.redhen_org_type --force -y
Do you really want to revert redhen_org_type? (y/n): y

Checked and all my organisations are gone.

nedjo’s picture

Yes, this is a critical bug.

I've updated the issue summary with proposed solutions.

johnennew’s picture

Thanks @nedjo - your solution sounds sensible to me.

johnennew’s picture

Issue summary: View changes

Updated issue summary.

levelos’s picture

Status: Active » Fixed

This has been addressed by adding a checkbox in the type deletion UI offering to delete all entities of a given type. It also indicates the number of affected entities and provides language about the ramifications. The controller and entity methods now take an additional parameter, $delete_entities, which is passed from the form.

Batch processing would be nice, but I'd prefer to leave the transactional support in place which wouldn't otherwise be possible. I think this addresses most use cases and those with many records can delete them in other ways.

Status: Fixed » Closed (fixed)

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

  • Commit 1dc21b3 on 7.x-1.x, redhen-donation by levelos:
    #2060239 by levelos: Make the deletion of orgs and contacts optional...

  • Commit 1dc21b3 on 7.x-1.x, redhen-donation, relation-roles by levelos:
    #2060239 by levelos: Make the deletion of orgs and contacts optional...