1 file.file.inc | file_file_update($file) |
Implements hook_file_update().
File
- core/
modules/ file/ file.file.inc, line 60 - File hooks implemented by the File module.
Code
function file_file_update($file) {
// Ensure field data is saved since file_save() does not in Drupal 7.
field_attach_update('file', $file);
// Save file metadata.
db_delete('file_metadata')->condition('fid', $file->fid)->execute();
if (!empty($file->metadata)) {
$query = db_insert('file_metadata')->fields(array('fid', 'name', 'value'));
foreach ($file->metadata as $name => $value) {
$query->values(array(
'fid' => $file->fid,
'name' => $name,
'value' => serialize($value),
));
}
$query->execute();
}
if (module_exists('image') && file_get_mimetype_type($file) == 'image' && $file->filesize && isset($file->original)) {
if (!isset($file->metadata)) {
$file->metadata = array();
}
if (!isset($file->original->metadata)) {
if (!is_object($file->original)) {
$file->original = new stdClass();
}
$file->original->metadata = array();
}
// If the file has changed dimensions or a new file has been uploaded,
// update any image field reference to this file and flush image style
// derivatives.
$file->metadata += array('width' => NULL, 'height' => NULL);
$file->original->metadata += array('width' => NULL, 'height' => NULL);
if ($file->filesize != $file->original->filesize || $file->metadata['width'] != $file->original->metadata['width'] || $file->metadata['height'] != $file->original->metadata['height']) {
_file_update_image_field_dimensions($file);
}
// Flush image style derivatives whenever an image is updated.
image_path_flush($file->uri);
}
// Clear any related field caches.
file_invalidate_field_caches($file);
}