diff --git a/core/modules/media/media.install b/core/modules/media/media.install index 823116418cf5c020ba81b0426065d413321d11ef..ef95793b9d8fe5c12c1647e7c80165edc8649f76 100644 --- a/core/modules/media/media.install +++ b/core/modules/media/media.install @@ -17,7 +17,15 @@ function media_install() { $files = file_scan_directory($source, '/.*\.(svg|png|jpg|jpeg|gif)$/'); foreach ($files as $file) { - file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_ERROR); + // When reinstalling the media module we don't want to copy the icons when + // they already exist. The icons could be replaced (by a contrib module or + // manually), so we don't want to replace the existing files. Removing the + // files when we uninstall could also be a problem if the files are + // referenced somewhere else. Since showing an error that it was not + // possible to copy the files is also confusing, we silently do nothing. + if (!file_exists($destination . DIRECTORY_SEPARATOR . $file->filename)) { + file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_ERROR); + } } // Grant the "view media" permission to all users by default. diff --git a/core/modules/media/tests/src/Functional/MediaInstallTest.php b/core/modules/media/tests/src/Functional/MediaInstallTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1d7fcbb791d9b1d80e93ef33bd9d54ce738faf77 --- /dev/null +++ b/core/modules/media/tests/src/Functional/MediaInstallTest.php @@ -0,0 +1,43 @@ +<?php + +namespace Drupal\Tests\media\Functional; + +use Drupal\Tests\BrowserTestBase; + +/** + * Tests media Install / Uninstall logic. + * + * @group media + */ +class MediaInstallTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['media']; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->drupalLogin($this->drupalCreateUser(['administer modules'])); + } + + /** + * Tests reinstalling after being uninstalled. + */ + public function testReinstallAfterUninstall() { + $page = $this->getSession()->getPage(); + $this->container->get('module_installer')->uninstall(['media'], FALSE); + $this->drupalGet('/admin/modules'); + $page->checkField('modules[media][enable]'); + $page->pressButton('Install'); + // @todo Remove this if-statement in https://www.drupal.org/node/2895059 + if ($page->find('css', 'h1')->getText() == 'Are you sure you wish to enable experimental modules?') { + $page->pressButton('Continue'); + } + $this->assertSession()->pageTextNotContains('could not be moved/copied because a file by that name already exists in the destination directory'); + } + +}