If I use this module to give my users the ability to manage their own galleries, what happens if a gallery is deleted? Will the images within that gallery be automatically deleted as well? Or will the user see some warning? Or will the site be left in an inconsistent state, i.e. a bunch of images with no gallery they belong to?

Thanks!

Comments

WorldFallz’s picture

This is an issue for all nodereferences not just with this module. I've implemented rules (using the http://drupal.org/project/rules module) to enforce referential integrity, but there's also the http://drupal.org/project/cck_referential_integrity module which looks promising.

kirilius’s picture

Thanks for the explanation.

Briefly looking at cck_referential_integrity, it seems it can only clean the broken reference but the child record still remains there. It is not deleted and logically it is still an orphan.

Rules seem to be more flexible but I am not quite sure how to implement the behavior I need. Do I need to custom code something?

WorldFallz’s picture

That's what I did. To make it easier, I added a http://drupal.org/project/nodereferrer field on the referenced content type so I could easily get the list of referencing nodes, then add a php action as follows to do the actual deletion:

foreach ($node->field_referrers[0][items] as $item) {
  node_delete($item[nid]);
}
KarenS’s picture

There is no automatic way to do this now, and it would not always be desired. Some people might want the images to live on even if the gallery was deleted. I was planning to add a configuration option where you could say if deleting a gallery should also delete all its images. It should not be too hard to add this in, whenever I get a chance to do it (unless someone provides a patch before that).

WorldFallz’s picture

I agree, but the problem with leaving the images behind is that afaik currently there is no way to change to which gallery they belong-- which is actually a nodereference_url issue (see #396818: Ability to change values when editing for more info).

I spent quite a bit of time trying to figure out how to hook_form_alter the nodereference_url widget back to a select list but couldn't make it work. So the only real option for now is to delete images and recreate them as part of a new gallery.

kirilius’s picture

Thanks WorldFallz, where exactly do I put this piece of code and what configuration is required for that?

kirilius’s picture

I did a little bit of digging and was surpised how easy it is with rules and the code supplied above. Thank you for this tip!

One more comment and one more question though:

Comment: The event I configured my rule for is called "After deleting content". I believe the word "after" is not accurate because if the deletion has already happened, the above code wouldn't have access to the "deleted" node's properties. A better name for that would be "Before deleting content" or "On deleting content" (I am borrowing some terminology from Oracle DRBMS)

Question: Is it somehow ensured that the deletion is done consistently in this case? Again in RDBMS terms: are the parent's and the children's deletion encapsulated in a single transaction? I don't know MySQL and the DB isolation layer that Drupal is using but if I had to do this in Oracle or some other major DB that supports transactions, my pseudo-code would look something like this:

BEGIN a transaction

  delete_the_children;

  delete_the_parent;

  COMMIT the transaction /* make DB changes available to other users and sessions */

EXCEPTION handling
  if an exception is raised then
    ROLLBACK the entire transaction so that either everything or nothing is deleted;
  end if;
END;

In other words what is going to hapen if during the process of deleting the children, the DB crashes? Will there be some children deleted, some not and the parent still there as well?

WorldFallz’s picture

Glad you figured it out!

And that's a great question about the transaction I hadn't thought of-- mySQL does have support for transactions since v4 iirc, but I'm not sure that drupal makes any use of it.

vitok-dupe’s picture

eL’s picture

Still no way to elegant images delete after gallery delete? Tried Reference integrity module, but it is not solving anything.

MKorostoff’s picture

Title: What about the referential integrity? » MKorostoff
Issue summary: View changes
MKorostoff’s picture

Title: MKorostoff » What about the referential integrity?