Skip to content
Snippets Groups Projects
Commit 00319d8e authored by Angie Byron's avatar Angie Byron
Browse files

#618654 by Steven Merrill, justinrandell, jim0203, quicksketch, and...

#618654 by Steven Merrill, justinrandell, jim0203, quicksketch, and David_Rothstein: Fixed File and image fields are treated as temporary files and automatically deleted after six hours.
parent 94a0bb3a
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -241,6 +241,22 @@ function file_field_prepare_view($entity_type, $entities, $field, $instances, $l
}
}
/**
* Implements hook_field_presave().
*/
function file_field_presave($obj_type, $object, $field, $instance, $langcode, &$items) {
// 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) {
$file = file_load($item['fid']);
if (($file->status & FILE_STATUS_PERMANENT) == 0) {
$file->status |= FILE_STATUS_PERMANENT;
file_save($file);
}
}
}
/**
* Implements hook_field_update().
*
......
......@@ -172,6 +172,14 @@ class FileFieldTestCase extends DrupalWebTestCase {
$message = isset($message) ? $message : t('File %file exists in database at the correct path.', array('%file' => $file->uri));
$this->assertFalse(file_load($file->fid), $message);
}
/**
* Assert that a file's status is set to permanent in the database.
*/
function assertFileIsPermanent($file, $message = NULL) {
$message = isset($message) ? $message : t('File %file is permanent.', array('%file' => $file->uri));
$this->assertTrue($file->status == FILE_STATUS_PERMANENT, $message);
}
}
/**
......@@ -215,6 +223,7 @@ class FileFieldRevisionTestCase extends FileFieldTestCase {
$node_vid_r1 = $node->vid;
$this->assertFileExists($node_file_r1, t('New file saved to disk on node creation.'));
$this->assertFileEntryExists($node_file_r1, t('File entry exists in database on node creation.'));
$this->assertFileIsPermanent($node_file_r1, t('File is permanent.'));
// Upload another file to the same node in a new revision.
$this->replaceNodeFile($test_file, $field_name, $nid);
......@@ -223,12 +232,14 @@ class FileFieldRevisionTestCase extends FileFieldTestCase {
$node_vid_r2 = $node->vid;
$this->assertFileExists($node_file_r2, t('Replacement file exists on disk after creating new revision.'));
$this->assertFileEntryExists($node_file_r2, t('Replacement file entry exists in database after creating new revision.'));
$this->assertFileIsPermanent($node_file_r2, t('Replacement file is permanent.'));
// Check that the original file is still in place on the first revision.
$node = node_load($nid, $node_vid_r1, TRUE);
$this->assertEqual($node_file_r1, (object) $node->{$field_name}[LANGUAGE_NONE][0], t('Original file still in place after replacing file in new revision.'));
$this->assertFileExists($node_file_r1, t('Original file still in place after replacing file in new revision.'));
$this->assertFileEntryExists($node_file_r1, t('Original file entry still in place after replacing file in new revision'));
$this->assertFileIsPermanent($node_file_r1, t('Original file is still permanent.'));
// Save a new version of the node without any changes.
// Check that the file is still the same as the previous revision.
......@@ -237,6 +248,7 @@ class FileFieldRevisionTestCase extends FileFieldTestCase {
$node_file_r3 = (object) $node->{$field_name}[LANGUAGE_NONE][0];
$node_vid_r3 = $node->vid;
$this->assertEqual($node_file_r2, $node_file_r3, t('Previous revision file still in place after creating a new revision without a new file.'));
$this->assertFileIsPermanent($node_file_r3, t('New revision file is permanent.'));
// Revert to the first revision and check that the original file is active.
$this->drupalPost('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert'));
......@@ -244,12 +256,14 @@ class FileFieldRevisionTestCase extends FileFieldTestCase {
$node_file_r4 = (object) $node->{$field_name}[LANGUAGE_NONE][0];
$node_vid_r4 = $node->vid;
$this->assertEqual($node_file_r1, $node_file_r4, t('Original revision file still in place after reverting to the original revision.'));
$this->assertFileIsPermanent($node_file_r4, t('Original revision file still permanent after reverting to the original revision.'));
// Delete the second revision and check that the file is kept (since it is
// still being used by the third revision).
$this->drupalPost('node/' . $nid . '/revisions/' . $node_vid_r2 . '/delete', array(), t('Delete'));
$this->assertFileExists($node_file_r3, t('Second file is still available after deleting second revision, since it is being used by the third revision.'));
$this->assertFileEntryExists($node_file_r3, t('Second file entry is still available after deleting second revision, since it is being used by the third revision.'));
$this->assertFileIsPermanent($node_file_r3, t('Second file entry is still permanent after deleting second revision, since it is being used by the third revision.'));
// Delete the third revision and check that the file is deleted also.
$this->drupalPost('node/' . $nid . '/revisions/' . $node_vid_r3 . '/delete', array(), t('Delete'));
......
......@@ -225,6 +225,13 @@ function image_field_prepare_view($entity_type, $entities, $field, $instances, $
}
}
/**
* Implements hook_field_presave().
*/
function image_field_presave($obj_type, $object, $field, $instance, $langcode, &$items) {
file_field_presave($obj_type, $object, $field, $instance, $langcode, $items);
}
/**
* Implements hook_field_insert().
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment