core/modules/file/src/FileUsage/FileUsageBase.php | 8 +------- core/modules/file/src/Tests/FileFieldRevisionTest.php | 16 ++++++++++++---- core/modules/file/src/Tests/FileListingTest.php | 3 +++ .../file/src/Tests/FileOnTranslatedEntityTest.php | 12 +++++++++--- core/modules/file/src/Tests/FilePrivateTest.php | 12 +++++++++--- core/modules/file/tests/src/Kernel/DeleteTest.php | 18 +++++++++++++----- .../image/src/Tests/ImageOnTranslatedEntityTest.php | 12 +++++++++--- core/modules/system/src/Form/FileSystemForm.php | 11 ----------- core/modules/user/src/Tests/UserPictureTest.php | 8 ++++++-- 9 files changed, 62 insertions(+), 38 deletions(-) diff --git a/core/modules/file/src/FileUsage/FileUsageBase.php b/core/modules/file/src/FileUsage/FileUsageBase.php index c90359b..3fa2436 100644 --- a/core/modules/file/src/FileUsage/FileUsageBase.php +++ b/core/modules/file/src/FileUsage/FileUsageBase.php @@ -24,13 +24,7 @@ public function add(FileInterface $file, $module, $type, $id, $count = 1) { * {@inheritdoc} */ public function delete(FileInterface $file, $module, $type = NULL, $id = NULL, $count = 1) { - // If there are no more remaining usages of this file, mark it as temporary, - // which result in a delete through system_cron(). - $usage = \Drupal::service('file.usage')->listUsage($file); - if (empty($usage)) { - $file->setTemporary(); - $file->save(); - } + // @todo Fix this in https://www.drupal.org/node/2821423. } } diff --git a/core/modules/file/src/Tests/FileFieldRevisionTest.php b/core/modules/file/src/Tests/FileFieldRevisionTest.php index 7b7b4d3..53519bb 100644 --- a/core/modules/file/src/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/src/Tests/FileFieldRevisionTest.php @@ -120,8 +120,12 @@ public function testRevisions() { ->execute(); \Drupal::service('cron')->run(); - $this->assertFileNotExists($node_file_r3, 'Second file is now deleted after deleting third revision, since it is no longer being used by any other nodes.'); - $this->assertFileEntryNotExists($node_file_r3, 'Second file entry is now deleted after deleting third revision, since it is no longer being used by any other nodes.'); + // @todo Fix this in https://www.drupal.org/node/2821423. + //$this->assertFileNotExists($node_file_r3, 'Second file is now deleted after deleting third revision, since it is no longer being used by any other nodes.'); + //$this->assertFileEntryNotExists($node_file_r3, 'Second file entry is now deleted after deleting third revision, since it is no longer being used by any other nodes.'); + $this->assertFileExists($node_file_r3); + $this->assertFileEntryExists($node_file_r3); + $this->assertFileIsPermanent($node_file_r3); // Delete the entire node and check that the original file is deleted. $this->drupalPostForm('node/' . $nid . '/delete', [], t('Delete')); @@ -135,8 +139,12 @@ public function testRevisions() { ->condition('fid', $node_file_r1->id()) ->execute(); \Drupal::service('cron')->run(); - $this->assertFileNotExists($node_file_r1, 'Original file is deleted after deleting the entire node with two revisions remaining.'); - $this->assertFileEntryNotExists($node_file_r1, 'Original file entry is deleted after deleting the entire node with two revisions remaining.'); + // @todo Fix this in https://www.drupal.org/node/2821423. + //$this->assertFileNotExists($node_file_r1, 'Original file is deleted after deleting the entire node with two revisions remaining.'); + //$this->assertFileEntryNotExists($node_file_r1, 'Original file entry is deleted after deleting the entire node with two revisions remaining.'); + $this->assertFileExists($node_file_r1); + $this->assertFileEntryExists($node_file_r1); + $this->assertFileIsPermanent($node_file_r1); } } diff --git a/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/src/Tests/FileListingTest.php index e348949..6594ae5 100644 --- a/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -113,6 +113,8 @@ public function testFileListingPages() { $nodes[1]->file->target_id = $used_file; $nodes[1]->save(); + // @todo Fix this in https://www.drupal.org/node/2821423. + /* $this->drupalGet('admin/content/files'); $file = File::load($orphaned_file); $usage = $this->sumUsages($file_usage->listUsage($file)); @@ -124,6 +126,7 @@ public function testFileListingPages() { $result = $this->xpath("//td[contains(@class, 'views-field-status') and contains(text(), :value)]", [':value' => t('Temporary')]); $this->assertEqual(1, count($result), 'Unused file marked as temporary.'); + */ // Test file usage page. foreach ($nodes as $node) { diff --git a/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php index 5f1e707..b497a41 100644 --- a/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php +++ b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php @@ -182,7 +182,9 @@ public function testSyncedFiles() { // Ensure the file status of the third file is now temporary. $file = File::load($third_fid); - $this->assertTrue($file->isTemporary()); + // @todo Fix this in https://www.drupal.org/node/2821423. + //$this->assertTrue($file->isTemporary()); + $this->assertTrue($file->isPermanent()); // Delete the all translations. $this->drupalPostForm('node/' . $default_language_node->id() . '/delete', [], t('Delete all translations')); @@ -191,10 +193,14 @@ public function testSyncedFiles() { // Ensure the file status of the all files are now temporary. $file = File::load($first_fid); - $this->assertTrue($file->isTemporary(), 'First file still exists and is temporary.'); + // @todo Fix this in https://www.drupal.org/node/2821423. + //$this->assertTrue($file->isTemporary(), 'First file still exists and is temporary.'); + $this->assertTrue($file->isPermanent()); $file = File::load($replaced_second_fid); - $this->assertTrue($file->isTemporary()); + // @todo Fix this in https://www.drupal.org/node/2821423. + //$this->assertTrue($file->isTemporary()); + $this->assertTrue($file->isPermanent()); } } diff --git a/core/modules/file/src/Tests/FilePrivateTest.php b/core/modules/file/src/Tests/FilePrivateTest.php index 6808a47..9f8438f 100644 --- a/core/modules/file/src/Tests/FilePrivateTest.php +++ b/core/modules/file/src/Tests/FilePrivateTest.php @@ -99,7 +99,9 @@ public function testPrivateFile() { $node->delete(); // Ensure the file can still be downloaded by the owner. $this->drupalGet($file_url); - $this->assertResponse(200, 'Confirmed that the owner still has access to the temporary file.'); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertResponse(200, 'Confirmed that the owner still has access to the temporary file.'); + $this->assertResponse(403); // Ensure the file cannot be downloaded by an anonymous user. $this->drupalLogout(); @@ -161,12 +163,16 @@ public function testPrivateFile() { $new_node->{$field_name} = []; $new_node->save(); $file = File::load($file_id); - $this->assertTrue($file->isTemporary(), 'File is temporary.'); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertTrue($file->isTemporary(), 'File is temporary.'); + $this->assertTrue($file->isPermanent()); $usage = $this->container->get('file.usage')->listUsage($file); $this->assertFalse($usage, 'No file usage found.'); $file_url = file_create_url($file->getFileUri()); $this->drupalGet($file_url); - $this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the file whose references were removed.'); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertResponse(200, 'Confirmed that the anonymous uploader has access to the file whose references were removed.'); + $this->assertResponse(403); // Close the prior connection and remove the session cookie. $this->curlClose(); $this->curlCookies = []; diff --git a/core/modules/file/tests/src/Kernel/DeleteTest.php b/core/modules/file/tests/src/Kernel/DeleteTest.php index 3b868c0..2efa886 100644 --- a/core/modules/file/tests/src/Kernel/DeleteTest.php +++ b/core/modules/file/tests/src/Kernel/DeleteTest.php @@ -44,12 +44,16 @@ public function testInUse() { $file_usage->delete($file, 'testing', 'test', 1); $usage = $file_usage->listUsage($file); - $this->assertFileHooksCalled(['load', 'update']); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertFileHooksCalled(['load', 'update']); + $this->assertFileHooksCalled([]); $this->assertTrue(empty($usage), 'File usage data was removed.'); $this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.'); $file = File::load($file->id()); $this->assertTrue($file, 'File still exists in the database.'); - $this->assertTrue($file->isTemporary(), 'File is temporary.'); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertTrue($file->isTemporary(), 'File is temporary.'); + $this->assertTrue($file->isPermanent()); file_test_reset(); // Call file_cron() to clean up the file. Make sure the changed timestamp @@ -64,9 +68,13 @@ public function testInUse() { \Drupal::service('cron')->run(); // file_cron() loads - $this->assertFileHooksCalled(['delete']); - $this->assertFalse(file_exists($file->getFileUri()), 'File has been deleted after its last usage was removed.'); - $this->assertFalse(File::load($file->id()), 'File was removed from the database.'); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertFileHooksCalled(['delete']); +// $this->assertFalse(file_exists($file->getFileUri()), 'File has been deleted after its last usage was removed.'); +// $this->assertFalse(File::load($file->id()), 'File was removed from the database.'); + $this->assertFileHooksCalled([]); + $this->assertTrue(file_exists($file->getFileUri())); + $this->assertTrue(File::load($file->id())); } } diff --git a/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php b/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php index e1f70d7..2cd4ae8 100644 --- a/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php +++ b/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php @@ -207,7 +207,9 @@ public function testSyncedImages() { // Ensure the file status of the third file is now temporary. $file = File::load($third_fid); - $this->assertTrue($file->isTemporary()); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertTrue($file->isTemporary()); + $this->assertTrue($file->isPermanent()); // Delete the all translations. $this->drupalPostForm('node/' . $default_language_node->id() . '/delete', [], t('Delete all translations')); @@ -216,10 +218,14 @@ public function testSyncedImages() { // Ensure the file status of the all files are now temporary. $file = File::load($first_fid); - $this->assertTrue($file->isTemporary(), 'First file still exists and is temporary.'); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertTrue($file->isTemporary(), 'First file still exists and is temporary.'); + $this->assertTrue($file->isPermanent()); $file = File::load($replaced_second_fid); - $this->assertTrue($file->isTemporary()); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertTrue($file->isTemporary()); + $this->assertTrue($file->isPermanent()); } } diff --git a/core/modules/system/src/Form/FileSystemForm.php b/core/modules/system/src/Form/FileSystemForm.php index ff0b792..88e7bdf 100644 --- a/core/modules/system/src/Form/FileSystemForm.php +++ b/core/modules/system/src/Form/FileSystemForm.php @@ -120,17 +120,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { ]; } - $intervals = [0, 21600, 43200, 86400, 604800, 2419200, 7776000]; - $period = array_combine($intervals, array_map([$this->dateFormatter, 'formatInterval'], $intervals)); - $period[0] = t('Never'); - $form['temporary_maximum_age'] = [ - '#type' => 'select', - '#title' => t('Delete orphaned files after'), - '#default_value' => $config->get('temporary_maximum_age'), - '#options' => $period, - '#description' => t('Orphaned files are not referenced from any content but remain in the file system and may appear in administrative listings. Warning: If enabled, orphaned files will be permanently deleted and may not be recoverable.'), - ]; - return parent::buildForm($form, $form_state); } diff --git a/core/modules/user/src/Tests/UserPictureTest.php b/core/modules/user/src/Tests/UserPictureTest.php index 6d546f0..eb0dd11 100644 --- a/core/modules/user/src/Tests/UserPictureTest.php +++ b/core/modules/user/src/Tests/UserPictureTest.php @@ -72,10 +72,14 @@ public function testCreateDeletePicture() { \Drupal::service('cron')->run(); // Verify that the image has been deleted. - $this->assertFalse(File::load($file->id()), 'File was removed from the database.'); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertFalse(File::load($file->id()), 'File was removed from the database.'); + $this->assertTrue(File::load($file->id())); // Clear out PHP's file stat cache so we see the current value. clearstatcache(TRUE, $file->getFileUri()); - $this->assertFalse(is_file($file->getFileUri()), 'File was removed from the file system.'); + // @todo Fix this in https://www.drupal.org/node/2821423. +// $this->assertFalse(is_file($file->getFileUri()), 'File was removed from the file system.'); + $this->assertTrue(is_file($file->getFileUri())); } /**