diff options
-rw-r--r-- | CHANGELOG.txt | 4 | ||||
-rw-r--r-- | modules/file/file.field.inc | 10 |
2 files changed, 13 insertions, 1 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 082efb254..947a8e2b1 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,10 @@ Drupal 7.25, xxxx-xx-xx (development version) ----------------------- +- Made the File and Image modules more robust when saving entities that have + deleted files attached. The code in file_field_presave() will now remove the + record of the deleted file from the entity before saving (minor data + structure change). - Standardized menu callback functions throughout Drupal core to return MENU_NOT_FOUND and MENU_ACCESS_DENIED rather than printing their own "page not found" or "access denied" pages (minor API change in the return value of diff --git a/modules/file/file.field.inc b/modules/file/file.field.inc index c841f60ee..d540c0aa5 100644 --- a/modules/file/file.field.inc +++ b/modules/file/file.field.inc @@ -215,8 +215,16 @@ function file_field_presave($entity_type, $entity, $field, $instance, $langcode, // Make sure that each file which will be saved with this object has a // permanent status, so that it will not be removed when temporary files are // cleaned up. - foreach ($items as $item) { + foreach ($items as $delta => $item) { + if (empty($item['fid'])) { + unset($items[$delta]); + continue; + } $file = file_load($item['fid']); + if (empty($file)) { + unset($items[$delta]); + continue; + } if (!$file->status) { $file->status = FILE_STATUS_PERMANENT; file_save($file); |