diff --git a/core/includes/file.inc b/core/includes/file.inc index 438fe671c0..19e03e1af7 100644 --- a/core/includes/file.inc +++ b/core/includes/file.inc @@ -852,9 +852,9 @@ function file_delete($fid) { */ function file_delete_multiple(array $fids) { @trigger_error('file_delete_multiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityStorageInterface::delete() instead. See https://www.drupal.org/node/3021663.', E_USER_DEPRECATED); - $controller = \Drupal::entityTypeManager()->getStorage('file'); - $entities = $controller->loadMultiple($fids); - $controller->delete($entities); + $storage = \Drupal::entityTypeManager()->getStorage('file'); + $entities = $storage->loadMultiple($fids); + $storage->delete($entities); } /** diff --git a/core/modules/file/tests/src/Kernel/FileLegacyTest.php b/core/modules/file/tests/src/Kernel/FileLegacyTest.php index 500a2ba8c5..6bbf3fc8f8 100644 --- a/core/modules/file/tests/src/Kernel/FileLegacyTest.php +++ b/core/modules/file/tests/src/Kernel/FileLegacyTest.php @@ -50,44 +50,30 @@ public function testFileUrlDeprecation() { /** * @expectedDeprecation file_load_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\file\Entity\File::loadMultiple(). See https://www.drupal.org/node/2266845 * @expectedDeprecation file_load() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal\file\Entity\File::load(). See https://www.drupal.org/node/2266845 + * @expectedDeprecation file_delete() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityStorageInterface::delete() instead. See https://www.drupal.org/node/3021663. + * @expectedDeprecation file_delete_multiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityStorageInterface::delete() instead. See https://www.drupal.org/node/3021663. */ public function testEntityLegacyCode() { + // Test deprecation of file_load_multiple(). file_put_contents('public://example.txt', $this->randomMachineName()); $this->assertCount(0, file_load_multiple()); File::create(['uri' => 'public://example.txt'])->save(); $this->assertCount(1, file_load_multiple()); File::create(['uri' => 'public://example.txt'])->save(); $this->assertCount(2, file_load_multiple()); + File::create(['uri' => 'public://example.txt'])->save(); + $this->assertCount(3, file_load_multiple()); + // Test deprecation of file_load(). $this->assertNull(file_load(300)); - $this->assertInstanceOf(FileInterface::class, file_load(1)); - } + $file_entity = file_load(1); + $this->assertInstanceOf(FileInterface::class, $file_entity); - /** - * @expectedDeprecation file_delete() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityStorageInterface::delete() instead. See https://www.drupal.org/node/3021663. - */ - public function testDeprecatedFileDelete() { - // Make a file. - file_put_contents('public://example.txt', $this->randomMachineName()); - // Make an entity for the file. - $file_entity = File::create(['uri' => 'public://example.txt']); - $file_entity->save(); - // Assert that this method of deleting the file is deprecated. + // Test deprecation of file_delete(). $this->assertNull(file_delete($file_entity->id())); - $this->assertFileNotExists('public://example.txt'); - } - /** - * @expectedDeprecation file_delete_multiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Entity\EntityStorageInterface::delete() instead. See https://www.drupal.org/node/3021663. - */ - public function testDeprecatedFileDeleteMultiple() { - // Make a file. - file_put_contents('public://example.txt', $this->randomMachineName()); - // Make an entity for the file. - $file_entity = File::create(['uri' => 'public://example.txt']); - $file_entity->save(); - // Assert that this method of deleting the file is deprecated. - $this->assertNull(file_delete_multiple([$file_entity->id()])); + // Test deprecation of file_delete_multiple(). + $this->assertNull(file_delete_multiple(array_keys(file_load_multiple()))); $this->assertFileNotExists('public://example.txt'); }