Commit 711decb5 authored by alexpott's avatar alexpott

Issue #3101299 by dww, alexpott: Install module from .zip URL fails

(cherry picked from commit de27c163)
parent 915bf601
......@@ -641,6 +641,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']
......
......@@ -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']));
}
/**
......
......@@ -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',
],
];
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment