You are here

function filefield_update_6101 in FileField 6.3

Set fid to NULL where files have been deleted.

This is a double-cleanup from Drupal 5 versions, where fid used to be 0 for empty rows or sometimes referred to a nonexistent FID altogether.

File

./filefield.install, line 235

Code

function filefield_update_6101() {
  $ret = array();
  module_load_include('inc', 'content', 'includes/content.crud');
  $fields = content_fields();
  foreach ($fields as $field) {
    if ($field['type'] == 'filefield') {
      $db_info = content_database_info($field);
      if (isset($db_info['columns']['fid'])) {
        $table = $db_info['table'];
        $fid_column = $db_info['columns']['fid']['column'];
        $list_column = $db_info['columns']['list']['column'];
        $ret[] = update_sql("UPDATE {" . $table . "} SET {$fid_column} = NULL, {$list_column} = NULL WHERE {$fid_column} NOT IN (SELECT fid FROM {files})");
      }
    }
  }
  return $ret;
}