summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Hojtsy2017-07-20 15:46:26 +0200
committerGabor Hojtsy2017-07-20 15:46:26 +0200
commite018da508245c41345d969c106ff57f0e43e4b1d (patch)
tree86cc49a096756095824c9b53c748e4a3100ed4c2
parent337963d19352bba3ef82cd9cfe3683ae0e33021d (diff)
Issue #2889438 by chr.fritsch, seanB, marcoscano, Wim Leers, rogerpfaff, phenaproxima, larowlan: Delete media delivered icons on uninstall
-rw-r--r--core/modules/media/media.install10
-rw-r--r--core/modules/media/tests/src/Functional/MediaInstallTest.php43
2 files changed, 52 insertions, 1 deletions
diff --git a/core/modules/media/media.install b/core/modules/media/media.install
index 8231164..ef95793 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 0000000..1d7fcbb
--- /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');
+ }
+
+}