diff -u b/core/modules/file/config/install/file.settings.yml b/core/modules/file/config/install/file.settings.yml --- b/core/modules/file/config/install/file.settings.yml +++ b/core/modules/file/config/install/file.settings.yml @@ -6 +6 @@ -file_usage_temporary: false +make_unused_managed_files_temporary: false diff -u b/core/modules/file/config/schema/file.schema.yml b/core/modules/file/config/schema/file.schema.yml --- b/core/modules/file/config/schema/file.schema.yml +++ b/core/modules/file/config/schema/file.schema.yml @@ -21,7 +21,7 @@ directory: type: path label: 'Directory' - file_usage_temporary: + make_unused_managed_files_temporary: type: boolean label: 'Controls if unused files should be marked temporary' diff -u b/core/modules/file/file.install b/core/modules/file/file.install --- b/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -132,7 +132,7 @@ function file_update_8201() { // Disable deletion of temporary files. \Drupal::configFactory()->getEditable('file.settings') - ->set('file_usage_temporary', FALSE) + ->set('make_unused_managed_files_temporary', FALSE) ->save(); return t('Files that have no remaining usages are no longer marked temporary by default.'); diff -u b/core/modules/file/file.module b/core/modules/file/file.module --- b/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1566,12 +1566,12 @@ */ function file_form_system_file_system_settings_alter(&$form, FormStateInterface $form_state) { $config = \Drupal::configFactory()->getEditable('file.settings'); - $form['file_usage_temporary'] = array( - '#type' => 'checkbox', - '#title' => t('Mark unused files as temporary'), - '#default_value' => $config->get('file_usage_temporary'), - '#description' => t('If checked, files for which all usages are removed are marked as temporary and then later on removed. Warning: There are currently known bugs with file usage counting, it is recommended to leave this disabled to prevent the loss of files.'), - ); + $form['make_unused_managed_files_temporary'] = [ + '#type' => 'checkbox', + '#title' => t('Mark unused files as temporary'), + '#default_value' => $config->get('make_unused_managed_files_temporary'), + '#description' => t('If checked, files for which all usages are removed are marked as temporary and then later on removed. Warning: There are currently known bugs with file usage counting, it is recommended to leave this disabled to prevent the loss of files.'), + ]; $form['#submit'][] = 'file_system_file_settings_submit'; } @@ -1584,5 +1584,5 @@ function file_system_file_settings_submit($form, FormStateInterface $form_state) { \Drupal::configFactory()->getEditable('file.settings') - ->set('file_usage_temporary', $form_state->getValue('file_usage_temporary')) + ->set('make_unused_managed_files_temporary', $form_state->getValue('make_unused_managed_files_temporary')) ->save(); } diff -u b/core/modules/file/src/FileUsage/FileUsageBase.php b/core/modules/file/src/FileUsage/FileUsageBase.php --- b/core/modules/file/src/FileUsage/FileUsageBase.php +++ b/core/modules/file/src/FileUsage/FileUsageBase.php @@ -21,7 +21,11 @@ * Creates a FileUsageBase object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The config factory. + * (optional) The config factory. Defaults to NULL and will use + * \Drupal::configFactory() instead. + * + * @deprecated The $config_factory parameter will become required in Drupal + * 9.0.0. */ public function __construct(ConfigFactoryInterface $config_factory = NULL) { $this->configFactory = $config_factory ?: \Drupal::configFactory(); @@ -43,7 +47,7 @@ */ public function delete(FileInterface $file, $module, $type = NULL, $id = NULL, $count = 1) { // Do not actually mark files as temporary when the behavior is disabled. - if (!$this->configFactory->get('file.settings')->get('file_usage_temporary')) { + if (!$this->configFactory->get('file.settings')->get('make_unused_managed_files_temporary')) { return; } diff -u b/core/modules/file/src/Tests/FileFieldRevisionTest.php b/core/modules/file/src/Tests/FileFieldRevisionTest.php --- b/core/modules/file/src/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/src/Tests/FileFieldRevisionTest.php @@ -22,8 +22,9 @@ * should be deleted also. */ function testRevisions() { - - $this->config('file.settings')->set('file_usage_temporary', TRUE)->save(); + // This test expects unused managed files to be marked as a temporary file + // and then deleted up by file_cron(). + $this->config('file.settings')->set('make_unused_managed_files_temporary', TRUE)->save(); $node_storage = $this->container->get('entity.manager')->getStorage('node'); $type_name = 'article'; diff -u b/core/modules/file/src/Tests/FileListingTest.php b/core/modules/file/src/Tests/FileListingTest.php --- b/core/modules/file/src/Tests/FileListingTest.php +++ b/core/modules/file/src/Tests/FileListingTest.php @@ -30,7 +30,8 @@ protected function setUp() { parent::setUp(); - $this->config('file.settings')->set('file_usage_temporary', TRUE)->save(); + // This test expects unused managed files to be marked as a temporary file. + $this->config('file.settings')->set('make_unused_managed_files_temporary', TRUE)->save(); $this->adminUser = $this->drupalCreateUser(array('access files overview', 'bypass node access')); $this->baseUser = $this->drupalCreateUser(); diff -u b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php --- b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php +++ b/core/modules/file/src/Tests/FileOnTranslatedEntityTest.php @@ -29,7 +29,8 @@ protected function setUp() { parent::setUp(); - $this->config('file.settings')->set('file_usage_temporary', TRUE)->save(); + // This test expects unused managed files to be marked as temporary a file. + $this->config('file.settings')->set('make_unused_managed_files_temporary', TRUE)->save(); // Create the "Basic page" node type. // @todo Remove the disabling of new revision creation in diff -u b/core/modules/file/src/Tests/FilePrivateTest.php b/core/modules/file/src/Tests/FilePrivateTest.php --- b/core/modules/file/src/Tests/FilePrivateTest.php +++ b/core/modules/file/src/Tests/FilePrivateTest.php @@ -26,7 +26,8 @@ node_access_test_add_field(NodeType::load('article')); node_access_rebuild(); \Drupal::state()->set('node_access_test.private', TRUE); - $this->config('file.settings')->set('file_usage_temporary', TRUE)->save(); + // This test expects unused managed files to be marked as a temporary file. + $this->config('file.settings')->set('make_unused_managed_files_temporary', TRUE)->save(); } /** diff -u b/core/modules/file/tests/src/Kernel/DeleteTest.php b/core/modules/file/tests/src/Kernel/DeleteTest.php --- b/core/modules/file/tests/src/Kernel/DeleteTest.php +++ b/core/modules/file/tests/src/Kernel/DeleteTest.php @@ -28,7 +28,10 @@ * Tries deleting a file that is in use. */ function testInUse() { - $this->config('file.settings')->set('file_usage_temporary', TRUE)->save(); + // This test expects unused managed files to be marked as a temporary file + // and then deleted up by file_cron(). + $this->config('file.settings')->set('make_unused_managed_files_temporary', TRUE)->save(); + $file = $this->createFile(); $file_usage = $this->container->get('file.usage'); $file_usage->add($file, 'testing', 'test', 1); diff -u b/core/modules/file/tests/src/Kernel/UsageTest.php b/core/modules/file/tests/src/Kernel/UsageTest.php --- b/core/modules/file/tests/src/Kernel/UsageTest.php +++ b/core/modules/file/tests/src/Kernel/UsageTest.php @@ -78,7 +78,7 @@ * Tests file usage deletion when files are made temporary. */ function testRemoveUsageTemporary() { - $this->config('file.settings')->set('file_usage_temporary', TRUE)->save(); + $this->config('file.settings')->set('make_unused_managed_files_temporary', TRUE)->save(); $file = $this->doTestRemoveUsage(); $this->assertTrue($file->isTemporary()); } @@ -87,7 +87,7 @@ * Tests file usage deletion when files are made temporary. */ function testRemoveUsageNonTemporary() { - $this->config('file.settings')->set('file_usage_temporary', FALSE)->save(); + $this->config('file.settings')->set('make_unused_managed_files_temporary', FALSE)->save(); $file = $this->doTestRemoveUsage(); $this->assertFalse($file->isTemporary()); } diff -u b/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php b/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php --- b/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php +++ b/core/modules/image/src/Tests/ImageOnTranslatedEntityTest.php @@ -29,7 +29,8 @@ protected function setUp() { parent::setUp(); - $this->config('file.settings')->set('file_usage_temporary', TRUE)->save(); + // This test expects unused managed files to be marked as a temporary file. + $this->config('file.settings')->set('make_unused_managed_files_temporary', TRUE)->save(); // Create the "Basic page" node type. // @todo Remove the disabling of new revision creation in diff -u b/core/modules/user/src/Tests/UserPictureTest.php b/core/modules/user/src/Tests/UserPictureTest.php --- b/core/modules/user/src/Tests/UserPictureTest.php +++ b/core/modules/user/src/Tests/UserPictureTest.php @@ -33,7 +33,9 @@ protected function setUp() { parent::setUp(); - $this->config('file.settings')->set('file_usage_temporary', TRUE)->save(); + // This test expects unused managed files to be marked temporary and then + // cleaned up by file_cron(). + $this->config('file.settings')->set('make_unused_managed_files_temporary', TRUE)->save(); $this->webUser = $this->drupalCreateUser(array( 'access content', only in patch2: unchanged: --- /dev/null +++ b/core/modules/file/src/Tests/FileAdminTest.php @@ -0,0 +1,31 @@ +drupalLogin($this->drupalCreateUser(['administer site configuration'])); + $this->assertFalse($this->config('file.settings')->get('make_unused_managed_files_temporary'), 'The file.settings:make_unused_managed_files_temporary is set to FALSE.'); + $this->drupalPostForm('admin/config/media/file-system', ['make_unused_managed_files_temporary' => TRUE], t('Save configuration')); + $this->assertTrue($this->config('file.settings')->get('make_unused_managed_files_temporary'), 'The file.settings:make_unused_managed_files_temporary has been set to TRUE.'); + } + +}