You are here

function webform_protected_downloads_remove_deleted_files in Webform Protected Downloads 6

Removes any erroneous rows from {wpd_protected_files} that can be left over when files are deleted from a webform-enabled node whilst it was previously NOT webform-enabled

Parameters

int $nid:

1 call to webform_protected_downloads_remove_deleted_files()
webform_protected_downloads_nodeapi in ./webform_protected_downloads.module
Implementation of hook_nodeapi().

File

./webform_protected_downloads.module, line 520
This file contains hook declarations and functions for the Webform Protected Downloads module.

Code

function webform_protected_downloads_remove_deleted_files($nid) {
  $files = webform_protected_downloads_get_attached_files($nid);
  if (count($files)) {
    $sql = "DELETE FROM {wpd_protected_files} WHERE nid = %d AND fid NOT IN (%s)";
    $args = array(
      $nid,
      implode(',', array_keys($files)),
    );
    db_query($sql, $args);
  }
  else {
    $sql = "DELETE FROM {wpd_protected_files} WHERE nid = %d";
    $args = array(
      $nid,
    );
    db_query($sql, $args);
  }
}