Posted by mattbk on January 27, 2009 at 3:51am
4 followers
| Project: | Image |
| Version: | 6.x-1.x-dev |
| Component: | image_attach |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
I think it would be useful to have this as a checkbox in the content type settings. For example, we are running classified ads on our site, and it would be easiest if people's uploaded images were automatically deleted when the associated ad node is deleted, rather than having to be manually deleted sometime in the future.
Failing that, integration with Rules could be used to do the same thing, I suppose.
Comments
#1
Would be nice as a feature.
In the meantime, you can set up a view to show unattached image nodes: see the docs for this. Combine this with VBO and you can quickly delete unattached nodes.
#2
This feature would require the deletion system to check for each candidate image node:
- if the current user may delete it
- if the node is not attached to anything else.
I wonder if a ticky box on the node deletion confirmation form might be the best way to do it rather than a global setting.
#3
Hi there,
I'm working on a site that may need this feature. I see it hasn't been touched in a while. If I wind up needing to do it, can I submit a patch with it? I'll try to follow your spec - could you clarify though what you mean by "if the current user may delete it" - do you mean user permissions? Which permission (or is a new one needed)?
Thanks!
Kevin
#4
> If I wind up needing to do it, can I submit a patch with it?
Of course :)
> could you clarify though what you mean by "if the current user may delete it"
Using http://api.drupal.org/api/function/node_access
#5
Hi,
Here is a patch that will add this feature requested.
- Added image_attach_auto_delete field in image_attach_form_node_type_form_alter function to give admin the option enable/disable auto delete
- Modified image_attach_nodeapi function to delete associated image nodes when parent node is deleted
- Modified image_attach_nodeapi function to delete detached image nodes
#6
I'm not entirely following what this patch does -- also, could you take a look at http://drupal.org/patch/create, as the patch doesn't apply and doesn't seem to be in the standard format.
> - Modified image_attach_nodeapi function to delete detached image nodes
I think this is beyond the scope of this issue -- could we focus just on 'Automatically delete attached images when node deleted option' please, and come to this other feature afterwards? It probably needs a separate admin settings too.
#7
Hi joachim,
I apologize for the invalid format. Here is the patch with the format as instructed in the http://drupal.org/patch/create.
I also removed the codes that were out of scope.
#8
Thanks for working on this!
It's looking good, but there's a fairly big flaw I think... and some nitpicking ;)
+++ b/contrib/image_attach/image_attach.module@@ -176,6 +176,13 @@ function image_attach_form_node_type_form_alter(&$form, $form_state) {
+ '#title' => t('Auto Delete Attached Images'),
Should be sentence case rather than title case, and maybe something that reads like a sentence, such as 'Automatically delete attached images when a node is deleted'.
+++ b/contrib/image_attach/image_attach.module@@ -425,6 +432,13 @@ function image_attach_nodeapi(&$node, $op, $teaser, $page) {
+ // delete attached images
Comments should be sentences with a capital and full stop.
+++ b/contrib/image_attach/image_attach.module@@ -425,6 +432,13 @@ function image_attach_nodeapi(&$node, $op, $teaser, $page) {
+ $nids = db_query("SELECT iid FROM {image_attach} WHERE nid = %d", $node->nid);
+ while ($nid = db_result($nids)) {
+ node_delete($nid);
+ }
If image X is attached to nodes A and B, and I delete A, won't this delete X?
Powered by Dreditor.
#9
Here is a new patch with the fixes on the ff flaws:
- Changed field '#title' to something that reads like a sentence. I've used your suggestion "Automatically delete attached images when a node is deleted"
- Modified comment to sentence with a capital and full stop
- Prevent deletion of attached image nodes when being used by other nodes
Thanks!
#10
Looking good!
+++ b/contrib/image_attach/image_attach.module@@ -425,6 +432,14 @@ function image_attach_nodeapi(&$node, $op, $teaser, $page) {
+ $nids = db_query("SELECT iid FROM {image_attach} ia1 WHERE nid = %d AND NOT EXISTS(SELECT * FROM {image_attach} ia2 WHERE ia2.nid != ia1.nid AND ia2.nid != 0 AND ia2.iid = ia1.iid)", $node->nid);
This is a bit scary... as maintainer I wouldn't want to ever have to debug that.
What about:
SELECT iid FROM image_attach ia_outer WHERE ia_outer.nid = %d AND
(SELECT COUNT(ia_inner.nid) attached_count FROM image_attach ia_inner WHERE ia_inner.iid = ia_outer.iid) = 1
ie "give me images attached to this node, who are only attached to one node"
Powered by Dreditor.
#11
Thanks for your suggestion joachim. Here is the new patch without the scary sql statement. :))
#12
That's two successive patches... which instructions did you follow? -- I think I filed a bug report on them, but if it's doing successive patches as well, I should file another...
#13
* Patch 1/2 - added the requested feature, this was automatic_delete_attached_images-364796-8.patch attached on comment-9.
* Patch 2/2 - changed sql statement as suggested in comment-10.
#14
Could you post a single patch for the entire thing please?
#15
Hi! Here's the same patch with the entire thing in single file. :)