1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Delete Video File from xf_attachment

Discussion in 'XenForo Development Discussions' started by Bugfix, Feb 17, 2016.

  1. Bugfix

    Bugfix Member

    Hello!

    I have a short question about attachments:
    I uploaded a video in XF MG1.1 and after that, I deleted the user.

    Question: When does the file be deleted? Or does it even be deleted?
    I saw that the hourly cron only deletes images from xf_attachment with flag unassociated = 1.
    Question: When does the file get the flag unassociated = 1 instead of unassociated = 0?
    Is there also a cronjob for this? I did not find anything in XenForo_CronEntry_CleanUp.

    Thank you,
    Harald
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    Deleted the user or deleted the media item?

    Deleting a user does not delete their content.

    The unassociated flag gets set when the content is permanently deleted.

    The hourly cron handles the deletion (it is content agnostic do it doesn't matter whether it's an image or video in the gallery a file in the resource manager or an image attached to a post).
     
  3. Bugfix

    Bugfix Member

    Deleted the user.
    Sorry - there was missing an info: I have an addon to delete the content (but i only deleted it from xengallery_media).
    That was the info I was looking for - so I have to manually set the flag unassociated = 1 in my addon when I delete a user :)

    Thank you!
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    This happens automatically if the content is properly deleted using the Media DataWriter.
     
  5. Bugfix

    Bugfix Member

    Thank you for the hint - I really have to update my addon ;-)
    XenGallery_DataWriter_Media seems really perfect for my needs :)
     
  6. Bugfix

    Bugfix Member

    One question:
    Is it enough to use the XenGallery_DataWriter_Album?
    PHP:
            $userId $this->get('user_id');
            
    $deletedUserId$db->quote($userId);
            
    $albums $db->fetchAll('
                SELECT *
                FROM `xengallery_album`
                WHERE `album_user_id` = ?
            '
    $deletedUserId);
            foreach (
    $albums AS $album)
            {
                
    $albumWriter XenForo_DataWriter::create('XenGallery_DataWriter_Album');
                
    $albumWriter ->setExistingData($album);
                
    $albumWriter ->delete();
            }
    Because in _preDelete the media is deleted anyway and every media is in an album - right?
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    Yes that should be fine.
     
    Bugfix likes this.

Share This Page