Commit 76e7fb4a authored by Jonathan Hunt's avatar Jonathan Hunt

#4 Update File Entity to 7.x-2.22.

parent c9d91ad0
......@@ -116,14 +116,24 @@ function file_entity_file_update($file) {
_file_entity_update_image_field_dimensions($file);
}
// Flush image style derivatives whenever an image is updated.
image_path_flush($file->uri);
// Flush image style derivatives whenever an image is replaced.
if (empty($file->file_entity_skip_image_flush) && file_entity_has_file_changed($file)) {
image_path_flush($file->uri);
}
}
// Clear any related field caches.
file_entity_invalidate_field_caches($file);
}
/**
* Returns whether the file has changed
*/
function file_entity_has_file_changed($file) {
return empty($file->is_new) || empty($file->original) || $file->filesize != $file->original->filesize || $file->uri != $file->original->uri;
}
/**
* Implements hook_file_delete().
*/
......
......@@ -32,8 +32,8 @@ configure = admin/config/media/file-settings
; We have to add a fake version so Git checkouts do not fail Media dependencies
version = 7.x-2.x-dev
; Information added by Drupal.org packaging script on 2018-05-02
version = "7.x-2.21"
; Information added by Drupal.org packaging script on 2018-06-14
version = "7.x-2.22"
core = "7.x"
project = "file_entity"
datestamp = "1525293788"
datestamp = "1528996427"
......@@ -835,34 +835,27 @@ function file_entity_edit_submit($form, &$form_state) {
if (!empty($form_state['values']['replace_upload'])) {
$replacement = $form_state['values']['replace_upload'];
// Move file from temp to permanent home.
if (pathinfo($replacement->uri, PATHINFO_EXTENSION) == pathinfo($file->uri, PATHINFO_EXTENSION)) {
if ($new_file_uri = file_unmanaged_copy($replacement->uri, $file->uri, FILE_EXISTS_REPLACE)) {
// Remove temporary file.
file_delete($replacement);
}
} else {
if (!empty($form_state['values']['replace_keep_original_filename'])
&& $form_state['values']['replace_keep_original_filename']) {
$destination_uri = rtrim($file->uri, drupal_basename($file->uri)) . drupal_basename($file->uri);
}
else {
$destination_uri = rtrim($file->uri, drupal_basename($file->uri)) . drupal_basename($replacement->uri);
}
$replace_mode = $destination_uri == $file->uri ? FILE_EXISTS_REPLACE : FILE_EXISTS_RENAME;
if ($new_file_uri = file_unmanaged_copy($replacement->uri, $destination_uri, $replace_mode)) {
// @todo Add watchdog() about replaced file here?
if (!empty($form_state['values']['replace_keep_original_filename'])
&& $form_state['values']['replace_keep_original_filename']) {
$destination_uri = rtrim($file->uri, drupal_basename($file->uri)) . drupal_basename($file->uri);
}
else {
$destination_uri = rtrim($file->uri, drupal_basename($file->uri)) . drupal_basename($replacement->uri);
}
$replace_mode = $destination_uri == $file->uri ? FILE_EXISTS_REPLACE : FILE_EXISTS_RENAME;
if ($new_file_uri = file_unmanaged_copy($replacement->uri, $destination_uri, $replace_mode)) {
// @todo Add watchdog() about replaced file here?
// Remove temporary file.
file_delete($replacement);
// Remove temporary file.
file_delete($replacement);
// Update if the uri target has changed.
if ($new_file_uri != $file->uri) {
// Store the original file uri to delete if save is successful.
$orphaned_uri = $file->uri;
// Update if the uri target has changed.
if ($new_file_uri != $file->uri) {
// Store the original file uri to delete if save is successful.
$orphaned_uri = $file->uri;
// Update file entity uri.
$file->uri = $new_file_uri;
}
// Update file entity uri.
$file->uri = $new_file_uri;
}
}
}
......
......@@ -5,8 +5,8 @@ core = 7.x
dependencies[] = file_entity
hidden = TRUE
; Information added by Drupal.org packaging script on 2018-05-02
version = "7.x-2.21"
; Information added by Drupal.org packaging script on 2018-06-14
version = "7.x-2.22"
core = "7.x"
project = "file_entity"
datestamp = "1525293788"
datestamp = "1528996427"
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