Issue #1125368 by tacituseu: hook_file_delete() called without valid
authorNathan Haug
Wed, 27 Apr 2011 22:33:22 +0000 (16:33 -0600)
committerNathan Haug
Wed, 27 Apr 2011 22:33:22 +0000 (16:33 -0600)
$file object.

filefield_field.inc

index 1917644..736e57e 100644 (file)
@@ -205,11 +205,13 @@ function filefield_field_update($node, $field, &$items, $teaser, $page) {
  */
 function filefield_field_delete_revision($node, $field, &$items, $teaser, $page) {
   foreach ($items as $delta => $item) {
-    // For hook_file_references, remember that this is being deleted.
-    $item['field_name'] = $field['field_name'];
-    $item['delete_vid'] = $node->vid;
-    if (filefield_field_delete_file($item, $field)) {
-      $items[$delta] = NULL;
+    if (isset($item['fid'])) {
+      // For hook_file_references, remember that this is being deleted.
+      $item['field_name'] = $field['field_name'];
+      $item['delete_vid'] = $node->vid;
+      if (filefield_field_delete_file($item, $field)) {
+        $items[$delta] = NULL;
+      }
     }
   }
 }
@@ -219,12 +221,14 @@ function filefield_field_delete_revision($node, $field, &$items, $teaser, $page)
  */
 function filefield_field_delete($node, $field, &$items, $teaser, $page) {
   foreach ($items as $delta => $item) {
-    // For hook_file_references(), remember that this is being deleted.
-    $item['field_name'] = $field['field_name'];
-    // Pass in the nid of the node that is being removed so all references can
-    // be counted in hook_file_references().
-    $item['delete_nid'] = $node->nid;
-    filefield_field_delete_file($item, $field);
+    if (isset($item['fid'])) {
+      // For hook_file_references(), remember that this is being deleted.
+      $item['field_name'] = $field['field_name'];
+      // Pass in the nid of the node that is being removed so all references can
+      // be counted in hook_file_references().
+      $item['delete_nid'] = $node->nid;
+      filefield_field_delete_file($item, $field);
+    }
   }
 
   // Delete all the remaining items present only in older revisions.