Datamanager attachment/filedata?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akke
    New Member
    • Sep 2007
    • 25

    [Forum] Datamanager attachment/filedata?

    vb4 is using a global attachment system and it's not writing an already uploaded image to the system again. Instead it's re-using the same row from the filedata table.
    Now, when I want to programmatically delete an attachment I would use the 'Attachment' datamanager like this:

    $attachdata =& datamanager_init('Attachment', $vbulletin, ERRTYPE_SILENT, 'attachment');
    $attachdata->condition = <condition>;
    $attachdata->delete(true, false);

    My question is: will the Attachment datamanager delete the file from the system AND filedata table too? And will it do this only if it's not being in use somewher else?

    Thanks for a clarification.
  • Andy
    Senior Member
    • Jan 2002
    • 5886
    • 4.1.x

    #2
    Originally posted by akke
    My question is: will the Attachment datamanager delete the file from the system AND filedata table too? And will it do this only if it's not being in use somewher else?
    This is correct.

    Every hour cron/cleanup2.php is run as a cron job and initiates the clean up.

    Code:
    // Orphaned Attachments are removed after one hour
    $attachdata =& datamanager_init('Attachment', $vbulletin, ERRTYPE_SILENT, 'attachment');
    $attachdata->set_condition("a.contentid = 0 AND a.dateline < " . (TIMENOW - 3600));
    $attachdata->delete(true, false);
    
    // Unused filedata is removed after one hour
    $attachdata =& datamanager_init('Filedata', $vbulletin, ERRTYPE_SILENT, 'attachment');
    $attachdata->set_condition("fd.refcount = 0 AND fd.dateline < " . (TIMENOW - 3600));
    $attachdata->delete();

    Comment

    • akke
      New Member
      • Sep 2007
      • 25

      #3
      But the records I have are more than an hour old. A couple of days...

      Comment

      • akke
        New Member
        • Sep 2007
        • 25

        #4
        When I upload an attachment to a post and then finally not post anything. Records are added to the attachment and filedata table. After an hour the record is removed from the attachment table but it is never removed from the filedata table.

        So I suppose there's a bug with the cleanup of the filedata table?

        Comment

        • Darksome
          New Member
          • Apr 2011
          • 9
          • 4.1.x

          #5
          This sounds the same as the problem I'm experiencing HERE.

          cleanup2.php removes the attachment from the attachment table but not from the filedata table nor does it remove the actual attachment itself.

          Comment

          • kralex
            New Member
            • Nov 2007
            • 4
            • 3.6.x

            #6
            I've fixed this way.

            before, all attachments move to database.

            after, run the following command in phpmyadmin.

            PHP Code:
            DELETE FROM filedata WHERE NOT EXISTS(SELECT filedataid FROM attachment WHERE filedataid=filedata.filedataid
            note: Get a backup before you start.
            Last edited by kralex; Fri 23 Sep '11, 2:26am.

            Comment

            Related Topics

            Collapse

            Working...