diff --git a/core/core.services.yml b/core/core.services.yml index 34e0de6c0bd81f084216a33be619a9959a856cd3..ed139f79ba54ad2861902daf27f4962c74e79f5d 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -631,6 +631,7 @@ services: plugin.manager.archiver: class: Drupal\Core\Archiver\ArchiverManager parent: default_plugin_manager + arguments: ['@file_system'] plugin.manager.action: class: Drupal\Core\Action\ActionManager arguments: ['@container.namespaces', '@cache.discovery', '@module_handler'] diff --git a/core/lib/Drupal/Core/Archiver/ArchiverManager.php b/core/lib/Drupal/Core/Archiver/ArchiverManager.php index 2ae021d73957876ce136d1bf9e581f64976b62b0..e5545d74d79accf71f4d5b8973e4c5395906dc52 100644 --- a/core/lib/Drupal/Core/Archiver/ArchiverManager.php +++ b/core/lib/Drupal/Core/Archiver/ArchiverManager.php @@ -5,6 +5,7 @@ use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Plugin\DefaultPluginManager; /** @@ -16,6 +17,13 @@ */ class ArchiverManager extends DefaultPluginManager { + /** + * The file system service. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + /** * Constructs a ArchiverManager object. * @@ -26,11 +34,18 @@ class ArchiverManager extends DefaultPluginManager { * Cache backend instance to use. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler to invoke the alter hook with. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The file handler. */ - public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { + public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, FileSystemInterface $file_system = NULL) { parent::__construct('Plugin/Archiver', $namespaces, $module_handler, 'Drupal\Core\Archiver\ArchiverInterface', 'Drupal\Core\Archiver\Annotation\Archiver'); $this->alterInfo('archiver_info'); $this->setCacheBackend($cache_backend, 'archiver_info_plugins'); + if (!isset($file_system)) { + @trigger_error('Not defining the final $file_system argument to ' . __METHOD__ . ' is deprecated in drupal:8.8.3 and will throw an error in drupal:10.0.0.', E_USER_DEPRECATED); + $file_system = \Drupal::service('file_system'); + } + $this->fileSystem = $file_system; } /** @@ -39,7 +54,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac public function createInstance($plugin_id, array $configuration = []) { $plugin_definition = $this->getDefinition($plugin_id); $plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition, 'Drupal\Core\Archiver\ArchiverInterface'); - return new $plugin_class($configuration['filepath']); + return new $plugin_class($this->fileSystem->realpath($configuration['filepath'])); } /** diff --git a/core/modules/update/tests/src/Functional/FileTransferAuthorizeFormTest.php b/core/modules/update/tests/src/Functional/FileTransferAuthorizeFormTest.php index f2c82a0bb2ce0cbdf4409edac1d4c9cd18ca96ac..2d7d7805197de50cce05dfa055c5942d1bd36bf7 100644 --- a/core/modules/update/tests/src/Functional/FileTransferAuthorizeFormTest.php +++ b/core/modules/update/tests/src/Functional/FileTransferAuthorizeFormTest.php @@ -28,14 +28,21 @@ protected function setUp() { // Create a local cache so the module is not downloaded from drupal.org. $cache_directory = _update_manager_cache_directory(TRUE); - $validArchiveFile = __DIR__ . '/../../update_test_new_module/8.x-1.0/update_test_new_module.tar.gz'; - copy($validArchiveFile, $cache_directory . '/update_test_new_module.tar.gz'); + foreach (['.tar.gz', '.zip'] as $extension) { + $filename = 'update_test_new_module' . $extension; + copy( + __DIR__ . '/../../update_test_new_module/8.x-1.0/' . $filename, + $cache_directory . '/' . $filename + ); + } } /** * Tests the Update Manager module upload via authorize.php functionality. + * + * @dataProvider archiveFileUrlProvider */ - public function testViaAuthorize() { + public function testViaAuthorize($url) { // Ensure the that we can select which file transfer backend to use. \Drupal::state()->set('test_uploaders_via_prompt', TRUE); @@ -44,8 +51,7 @@ public function testViaAuthorize() { $this->assertNoText('Update test new module'); $edit = [ - // This project has been cached in the test's setUp() method. - 'project_url' => 'https://ftp.drupal.org/files/projects/update_test_new_module.tar.gz', + 'project_url' => $url, ]; $this->drupalPostForm('admin/modules/install', $edit, t('Install')); $edit = [ @@ -60,4 +66,20 @@ public function testViaAuthorize() { $this->assertText('Update test new module'); } + /** + * Data provider method for testViaAuthorize(). + * + * Each of these release URLs has been cached in the setUp() method. + */ + public function archiveFileUrlProvider() { + return [ + 'tar.gz' => [ + 'url' => 'https://ftp.drupal.org/files/projects/update_test_new_module.tar.gz', + ], + 'zip' => [ + 'url' => 'https://ftp.drupal.org/files/projects/update_test_new_module.zip', + ], + ]; + } + } diff --git a/core/modules/update/tests/update_test_new_module/8.x-1.0/update_test_new_module.zip b/core/modules/update/tests/update_test_new_module/8.x-1.0/update_test_new_module.zip new file mode 100644 index 0000000000000000000000000000000000000000..ad59b948e9005d878bf44fea322c9a9a4e66b57a Binary files /dev/null and b/core/modules/update/tests/update_test_new_module/8.x-1.0/update_test_new_module.zip differ diff --git a/core/modules/update/tests/update_test_new_module/8.x-1.1/update_test_new_module.zip b/core/modules/update/tests/update_test_new_module/8.x-1.1/update_test_new_module.zip new file mode 100644 index 0000000000000000000000000000000000000000..6daa04d85cf1bd66702f40a855b9d1698e3e2254 Binary files /dev/null and b/core/modules/update/tests/update_test_new_module/8.x-1.1/update_test_new_module.zip differ