Doesn't handle node and file deletion

ehart - August 21, 2008 - 21:07
Project:Swish-E Indexer
Version:5.x-1.1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Let's say a user uploads a pdf, myfile.pdf, which is attached to a node. myfile.pdf is indexed and everything works fine. Later, the node and attached myfile.pdf file are deleted. myfile.pdf remains in the swish_fulltext table in the database. In my experience, this does not usually cause any problems.

However, let's say another user comes along and decides to upload a different file named myfile.pdf. During cron, swish will attempt to add this file into swish_fulltext. This will cause an attempted duplicate entry in a primary key column, which will occasionally cause a scary-looking user error.

#1

ehart - August 21, 2008 - 21:21
Status:active» needs review

Solution: in hook_nodeapi in swish.module, find the following code:

    case "search result":
      // return items to be added to search results
    break;
Immediately after this code, place the following new code:
    case "delete":
    // Check if this node has any references in the files table
    // Note: we do this because other attachments might not be found in $node->file
    $result = db_query("SELECT filepath FROM {files} WHERE nid = %d", $node->nid);
    if (db_num_rows($result)) {
      while ($row = db_fetch_object($result)) {
        // Do a delete
        db_query("DELETE FROM {swish_fulltext} WHERE filepath = '%s'", $row->filepath);
      }
    }
    break;

 
 

Drupal is a registered trademark of Dries Buytaert.