Commit 93c5556a authored by quicksketch's avatar quicksketch

#834018: Data serialized in a field's data column is lost after...

#834018: Data serialized in a field's data column is lost after field_file_load if filefield_meta in use.
parent 6d3740d7
...@@ -38,7 +38,7 @@ function field_file_load($fid, $reset = NULL) { ...@@ -38,7 +38,7 @@ function field_file_load($fid, $reset = NULL) {
} }
if (!$file) { if (!$file) {
$file = array('fid' => 0, 'filepath' => '', 'filename' => '', 'filemime' => '', 'filesize' => 0); $file = (object) array('fid' => 0, 'filepath' => '', 'filename' => '', 'filemime' => '', 'filesize' => 0);
} }
foreach (module_implements('file_load') as $module) { foreach (module_implements('file_load') as $module) {
......
...@@ -272,25 +272,26 @@ function filefield_field_sanitize($node, $field, &$items, $teaser, $page) { ...@@ -272,25 +272,26 @@ function filefield_field_sanitize($node, $field, &$items, $teaser, $page) {
continue; continue;
} }
} }
// Load the complete file if a filepath is not available.
if (!empty($item['fid']) && empty($item['filepath'])) {
$items[$delta] = array_merge($item, field_file_load($item['fid']));
}
// Add nid so formatters can create a link to the node. // Add nid so formatters can create a link to the node.
$items[$delta]['nid'] = $node->nid; $items[$delta]['nid'] = $node->nid;
// TODO: This is only necessary for Views, which doesn't call the "load" // Get the 'data' column stored by CCK into an array. This is necessary
// $op. It might be preferable to move this to Views integration somehow. // for Views, which doesn't call the "load" $op and to fix an issue with
if (!empty($items['data']) && is_string($items[$delta]['data'])) { // CCK double-serializing data.
$item['data'] = unserialize($item['data']);
}
// Temporary fix to unserialize data serialized multiple times.
// See the FileField issue http://drupal.org/node/402860. // See the FileField issue http://drupal.org/node/402860.
// And the CCK issue http://drupal.org/node/407446. // And the CCK issue http://drupal.org/node/407446.
while (!empty($items[$delta]['data']) && is_string($items[$delta]['data'])) { while (!empty($items[$delta]['data']) && is_string($items[$delta]['data'])) {
$items[$delta]['data'] = unserialize($items[$delta]['data']); $items[$delta]['data'] = unserialize($items[$delta]['data']);
} }
// Load the complete file if a filepath is not available.
if (!empty($item['fid']) && empty($item['filepath'])) {
$file = (array) field_file_load($item['fid']);
$items[$delta]['data'] = array_merge($item['data'], $file['data']);
$items[$delta] = array_merge($item, $file);
}
// Verify the file exists on the server. // Verify the file exists on the server.
if (!empty($item['filepath']) && !file_exists($item['filepath'])) { if (!empty($item['filepath']) && !file_exists($item['filepath'])) {
watchdog('filefield', 'FileField was trying to display the file %file, but it does not exist.', array('%file' => $item['filepath']), WATCHDOG_WARNING); watchdog('filefield', 'FileField was trying to display the file %file, but it does not exist.', array('%file' => $item['filepath']), WATCHDOG_WARNING);
......
...@@ -76,7 +76,7 @@ function filefield_meta_file_load(&$file) { ...@@ -76,7 +76,7 @@ function filefield_meta_file_load(&$file) {
function filefield_meta_file_insert(&$file) { function filefield_meta_file_insert(&$file) {
if (!empty($file->fid)) { if (!empty($file->fid)) {
filefield_meta($file); filefield_meta($file);
$record = array_merge(array('fid' => $file->fid), $file->data); $record = array_merge($file->data, array('fid' => $file->fid));
drupal_write_record('filefield_meta', $record); drupal_write_record('filefield_meta', $record);
} }
} }
......
...@@ -204,7 +204,7 @@ function filefield_widget_value($element, $edit = FALSE) { ...@@ -204,7 +204,7 @@ function filefield_widget_value($element, $edit = FALSE) {
$item = $element['#default_value']; $item = $element['#default_value'];
} }
else { else {
$item = array_merge($element['#default_value'], $edit); $item = $edit;
$field = content_fields($element['#field_name'], $element['#type_name']); $field = content_fields($element['#field_name'], $element['#type_name']);
// Uploads take priority over value of fid text field. // Uploads take priority over value of fid text field.
...@@ -236,6 +236,9 @@ function filefield_widget_value($element, $edit = FALSE) { ...@@ -236,6 +236,9 @@ function filefield_widget_value($element, $edit = FALSE) {
} }
} }
// Merge file and item data so it is available to all widgets. // Merge file and item data so it is available to all widgets.
if (isset($item['data']) && isset($file['data'])) {
$file['data'] = array_merge($item['data'], $file['data']);
}
$item = array_merge($item, $file); $item = array_merge($item, $file);
return $item; return $item;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment