diff options
author | David Rothstein <drothstein@gmail.com> | 2015-03-30 21:23:12 -0400 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2015-03-30 21:23:12 -0400 |
commit | 277ae50e8be4adb6a74aada6f341b2fdc38d6b20 (patch) | |
tree | 2b0e9e61ded9640ccd08ba92e15b5f420f32c4f9 /modules | |
parent | d6ae9e6dc393366f79cb54420fb808f20ed3df9c (diff) | |
download | brdo-277ae50e8be4adb6a74aada6f341b2fdc38d6b20.tar.gz brdo-277ae50e8be4adb6a74aada6f341b2fdc38d6b20.tar.bz2 |
Issue #1483736 by stefan.r, bfcam, jrigby: field_attach_update deletes file fields (content & file) in entity regardless of if they are included in the entity object
Diffstat (limited to 'modules')
-rw-r--r-- | modules/file/file.field.inc | 6 | ||||
-rw-r--r-- | modules/file/tests/file.test | 9 |
2 files changed, 15 insertions, 0 deletions
diff --git a/modules/file/file.field.inc b/modules/file/file.field.inc index b26d7e457..794f16e67 100644 --- a/modules/file/file.field.inc +++ b/modules/file/file.field.inc @@ -252,6 +252,12 @@ function file_field_insert($entity_type, $entity, $field, $instance, $langcode, * Checks for files that have been removed from the object. */ function file_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) { + // Check whether the field is defined on the object. + if (!isset($entity->{$field['field_name']})) { + // We cannot check for removed files if the field is not defined. + return; + } + list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity); // On new revisions, all files are considered to be a new usage and no diff --git a/modules/file/tests/file.test b/modules/file/tests/file.test index e2c5737f4..33d7afd1b 100644 --- a/modules/file/tests/file.test +++ b/modules/file/tests/file.test @@ -474,6 +474,15 @@ class FileFieldWidgetTestCase extends FileFieldTestCase { $node_file = (object) $node->{$field_name}[LANGUAGE_NONE][0]; $this->assertFileExists($node_file, 'New file saved to disk on node creation.'); + // Test that running field_attach_update() leaves the file intact. + $field = new stdClass(); + $field->type = $type_name; + $field->nid = $nid; + field_attach_update('node', $field); + $node = node_load($nid); + $node_file = (object) $node->{$field_name}[LANGUAGE_NONE][0]; + $this->assertFileExists($node_file, 'New file still saved to disk on field update.'); + // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->uri)); $this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.'); |