Hello All,
When we delete an attachment, is there a way to remove it from the search index ?
The entire node is not being deleted, just the attachment. The attachment, however, remains in the revision history.
Thanks,
Dale
Hello All,
When we delete an attachment, is there a way to remove it from the search index ?
The entire node is not being deleted, just the attachment. The attachment, however, remains in the revision history.
Thanks,
Dale
Comments
Comment #1
markj commentedNo, not without manually deleting the attachment's rows from search_dataset and search_index. However, this problem will not occur in version 5.x-4, which is currently under development. In that version, if you delete the file, it is removed permanently from the search index.
If you can tell me which module was used to upload the file and attach it to the node (upload, webfm, etc.), I can supply SQL that will let you delete the file's rows in search_dataset and search_index.
Comment #2
markj commentedThis question has made me aware of a bug in the driver for the upload module (which I assume you are using since this issue has come up) -- it doesn't take into account entries in Drupal's file_revisions table. So, the correct answer to your question should have been: in the upcoming version, if you delete a file from a node that was attached using upload.module, its text will be removed from the search index if it is not attached to the current version of the node. Thanks for bringing this to my attention.
Assuming you are using the core upload module to attach the file, here is SQL to delete its text from the index tables. You will need the nid of the node the file was attached to in order to perform the first SQL query.
Be sure to back up your database before deleting anything.
There is no need to rebuild your index at this point.
Comment #3
drenton commentedYes, you are correct, we are using the core upload module.
In the meantime I've created a cron job that runs daily to clean up any old attachments. Does it look ok ?
Thanks
Comment #4
markj commentedI didn't test the script as a cron job but I did set up a test case and ran the $query2 SQL, and it returned expected results. $query3 and $query4 look good too. I'd say back up your db and run the cron job to see if it deletes the orphaned file_upload entries.
Comment #5
drenton commentedLooks like it did the trick.
I changed $query2 to this though :
$query2 = "SELECT f.fid FROM files f, file_revisions r WHERE r.fid = f.fid AND f.nid={$line['nid']} AND r.vid<>{$line['vid']}";
Thanks
Comment #6
drenton commentedI had to make some changes. New cron job is :