Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
WorldFallz CreditAttribution: WorldFallz commentedThis 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.
Comment #2
kirilius CreditAttribution: kirilius commentedThanks 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?
Comment #3
WorldFallz CreditAttribution: WorldFallz commentedThat'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:
Comment #4
KarenS CreditAttribution: KarenS commentedThere 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).
Comment #5
WorldFallz CreditAttribution: WorldFallz commentedI 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.
Comment #6
kirilius CreditAttribution: kirilius commentedThanks WorldFallz, where exactly do I put this piece of code and what configuration is required for that?
Comment #7
kirilius CreditAttribution: kirilius commentedI 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:
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?
Comment #8
WorldFallz CreditAttribution: WorldFallz commentedGlad 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.
Comment #9
vitok-dupe CreditAttribution: vitok-dupe commentedhttp://drupal.org/node/83929#comment-1443160
For my this module work well
Comment #10
eL CreditAttribution: eL commentedStill no way to elegant images delete after gallery delete? Tried Reference integrity module, but it is not solving anything.
Comment #11
MKorostoff CreditAttribution: MKorostoff commentedComment #12
MKorostoff CreditAttribution: MKorostoff commented