Skip to content
Snippets Groups Projects
Commit a53f8b0d authored by Lisa Harrison's avatar Lisa Harrison Committed by Lisa Ridley
Browse files

Issue #3361958 by lhridley: Drupal 9.3+ compatibility

parent 94ac4f8a
No related branches found
No related tags found
4 merge requests!43Issue #3292158 by bbombachini, DieterHolvoet, hkirsman, Amanda95, alcalvo,...,!38Issue #3292158 by bbombachini, DieterHolvoet, hkirsman, Amanda95, alcalvo,...,!37Issue #3292158 by bbombachini, DieterHolvoet, hkirsman, Amanda95, alcalvo,...,!15Issue #3361958 by lhridley: Drupal 9.3+ compatibility
Showing
with 63 additions and 29 deletions
......@@ -4,7 +4,8 @@
"require": {
"league/flysystem": "^1.0.3",
"league/flysystem-replicate-adapter": "~1.0",
"twistor/flysystem-stream-wrapper": "^1.0.5"
"twistor/flysystem-stream-wrapper": "^1.0.5",
"php": ">=8.1"
},
"require-dev": {
......
......@@ -2,4 +2,4 @@ name: Flysystem
description: 'Provides access to various filesystem backends using Flysystem.'
package: Flysystem
type: module
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9.3
......@@ -4,6 +4,7 @@ flysystem.files:
_controller: 'Drupal\system\FileDownloadController::download'
_disable_route_normalizer: 'TRUE'
requirements:
# Permissions are handled through Drupal file create / update permissions
_access: 'TRUE'
scheme: '^[a-zA-Z0-9+.-]+$'
......@@ -13,6 +14,7 @@ flysystem.serve:
_controller: 'Drupal\system\FileDownloadController::download'
_disable_route_normalizer: 'TRUE'
requirements:
# Permissions are handled through Drupal access content permissions
_access: 'TRUE'
scheme: '^[a-zA-Z0-9+.-]+$'
filepath: .+
......
......@@ -7,7 +7,7 @@ use Drupal\Component\Annotation\Plugin;
/**
* Defines a Flysystem adapter plguin.
*
* Plugin Namespace: Flysystem
* Plugin Namespace: Flysystem.
*
* For a working example, see \Drupal\flysystem\Flysystem\Local.
*
......
......@@ -26,7 +26,8 @@ class CssCollectionOptimizer extends DrupalCssCollectionOptimizer {
if (\Drupal::time()->getRequestTime() - filemtime($uri) > $stale_file_threshold) {
try {
$file_system->delete($uri);
} catch (\Exception $e) {
}
catch (\Exception $e) {
$this->getLogger('flysystem')->error($e->getMessage());
}
}
......
......@@ -14,6 +14,7 @@ class CssOptimizer extends DrupalCssOptimizer {
/**
* {@inheritdoc}
*/
// phpcs:ignore
public function rewriteFileURI($matches) {
// Prefix with base and remove '../' segments where possible.
$path = $this->rewriteFileURIBasePath . $matches[1];
......
......@@ -26,7 +26,8 @@ class JsCollectionOptimizer extends DrupalJsCollectionOptimizer {
if (\Drupal::time()->getRequestTime() - filemtime($uri) > $stale_file_threshold) {
try {
$file_system->delete($uri);
} catch (\Exception $e) {
}
catch (\Exception $e) {
$this->getLogger('flysystem')->error($e->getMessage());
}
}
......
......@@ -60,6 +60,7 @@ class EnsureEvent extends Event {
* Returns the context.
*
* @return array
* Context.
*/
public function getContext() {
return $this->context;
......@@ -69,6 +70,7 @@ class EnsureEvent extends Event {
* Returns the message.
*
* @return string
* The message text.
*/
public function getMessage() {
return $this->message;
......@@ -78,6 +80,7 @@ class EnsureEvent extends Event {
* Returns the scheme.
*
* @return string
* The scheme identifier.
*/
public function getScheme() {
return $this->scheme;
......@@ -87,6 +90,7 @@ class EnsureEvent extends Event {
* Returns the severity.
*
* @return int
* The severity.
*/
public function getSeverity() {
return $this->severity;
......
......@@ -31,6 +31,8 @@ class CacheItemBackend {
/**
* Constructs a new CacheItemBackend.
*
* @param string $scheme
* The scheme being managed by the cache.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
* The Drupal cache backend to store items in.
*/
......
......@@ -178,7 +178,7 @@ class DrupalCacheAdapter implements AdapterInterface {
}
// Always check the upstream adapter for new files.
// TODO: This could be a good place for a microcache?
// @todo This could be a good place for a microcache?
return $this->adapter->has($path);
}
......@@ -202,7 +202,7 @@ class DrupalCacheAdapter implements AdapterInterface {
public function listContents($directory = '', $recursive = FALSE) {
// Don't cache directory listings to avoid having to keep track of
// incomplete cache entries.
// TODO: This could be a good place for a microcache?
// @todo This could be a good place for a microcache?
return $this->adapter->listContents($directory, $recursive);
}
......
......@@ -26,10 +26,10 @@ class FlysystemBridge extends FlysystemStreamWrapper implements StreamWrapperInt
*/
public function getName() {
$scheme = $this->getProtocol();
$name = (string) $this->getFactory()->getSettings($scheme)['name'];
$name = $this->getFactory()->getSettings($scheme)['name'];
$default = $this->t('Flysystem: @scheme', ['@scheme' => $scheme]);
return $name !== '' ? $this->t($name) : $default;
return $name !== '' ? $name : $default;
}
/**
......@@ -37,10 +37,10 @@ class FlysystemBridge extends FlysystemStreamWrapper implements StreamWrapperInt
*/
public function getDescription() {
$scheme = $this->getProtocol();
$description = (string) $this->getFactory()->getSettings($scheme)['description'];
$description = $this->getFactory()->getSettings($scheme)['description'];
$default = $this->t('Flysystem: @scheme', ['@scheme' => $scheme]);
return $description !== '' ? $this->t($description) : $default;
return $description !== '' ? $description : $default;
}
/**
......@@ -82,7 +82,7 @@ class FlysystemBridge extends FlysystemStreamWrapper implements StreamWrapperInt
$uri = $this->uri;
}
list($scheme, $target) = explode('://', $uri, 2);
[$scheme, $target] = explode('://', $uri, 2);
return $scheme . '://' . ltrim(Util::dirname($target), '\/');
}
......
......@@ -4,7 +4,6 @@ namespace Drupal\flysystem;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\flysystem\Event\EnsureEvent;
......@@ -163,7 +162,7 @@ class FlysystemFactory {
* The settings array from settings.php.
*/
public function getSettings($scheme) {
return isset($this->settings[$scheme]) ? $this->settings[$scheme] : $this->defaults;
return $this->settings[$scheme] ?? $this->defaults;
}
/**
......
......@@ -153,7 +153,9 @@ class ConfigForm extends FormBase {
if (!is_resource($read_handle)) {
$args = ['%scheme' => $scheme_from, '%file' => $filepath];
$context['results']['errors'][] = ['The file %scheme://%file could not be opened.', $args];
$context['results']['errors'][] = [
'The file %scheme://%file could not be opened.', $args,
];
return;
}
......@@ -161,14 +163,18 @@ class ConfigForm extends FormBase {
if (!$success) {
$args = ['%scheme' => $scheme_to, '%file' => $filepath];
$context['results']['errors'][] = ['The file %scheme://%file could not be saved.', $args];
$context['results']['errors'][] = [
'The file %scheme://%file could not be saved.', $args,
];
}
}
// Catch all exceptions so we don't break batching. The types of exceptions
// that adapters can throw varies greatly.
catch (\Exception $e) {
$context['results']['errors'][] = ['An eror occured while copying %file.', ['%file' => $filepath]];
$context['results']['errors'][] = [
'An eror occured while copying %file.', ['%file' => $filepath],
];
$context['results']['errors'][] = $e->getMessage();
watchdog_exception('flysystem', $e);
......
......@@ -32,7 +32,7 @@ class FlysystemPathProcessor implements InboundPathProcessorInterface {
// Support image styles.
if (strpos($rest, 'styles/') === 0 && substr_count($rest, '/') >= 3) {
list(, $image_style, $scheme, $file) = explode('/', $rest, 4);
[, $image_style, $scheme, $file] = explode('/', $rest, 4);
// Set the file as query parameter.
$request->query->set('file', $file);
......
......@@ -7,8 +7,7 @@ use Drupal\Core\Site\Settings;
use Symfony\Component\HttpFoundation\Request;
/**
* Defines a path processor to serve public files directly for the local
* adapter.
* Defines a path processor to serve public files for the local adapter.
*
* As the route system does not allow arbitrary amount of parameters convert
* the file path to a query parameter on the request.
......@@ -52,7 +51,7 @@ class LocalPathProcessor implements InboundPathProcessorInterface {
$rest = substr($path, strlen($this->root) + 2);
if (strpos($rest, 'styles/') === 0 && substr_count($rest, '/') >= 3) {
list(, $image_style, $scheme, $file) = explode('/', $rest, 4);
[, $image_style, $scheme, $file] = explode('/', $rest, 4);
// Set the file as query parameter.
$request->query->set('file', $file);
......
......@@ -2,6 +2,9 @@
namespace Drupal\flysystem\Plugin;
/**
* Interface definition for Flysystem plugins.
*/
interface FlysystemPluginInterface {
/**
......
......@@ -24,7 +24,7 @@ trait ImageStyleGenerationTrait {
return FALSE;
}
list(, $style, $scheme, $file) = explode('/', $target, 4);
[, $style, $scheme, $file] = explode('/', $target, 4);
if (!$image_style = ImageStyle::load($style)) {
return FALSE;
......
......@@ -19,7 +19,7 @@ class ModuleInstallUninstallWebTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['flysystem'];
protected static $modules = ['flysystem'];
/**
* Tests installation and uninstallation.
......
......@@ -23,15 +23,28 @@ class CollectionOptimizerTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
protected static $modules = ['file'];
/**
* The file URL generator.
*
* @var \Drupal\Core\File\FileUrlGeneratorInterface
*/
protected $fileUrlGenerator;
/**
* {@inheritdoc}
*/
public function setUp(): void {
parent::setUp();
$this->fileUrlGenerator = $this->container->get('file_url_generator');
$this->cleanUp();
}
/**
* {@inheritdoc}
*/
public function tearDown() {
public function tearDown(): void {
$this->cleanUp();
parent::tearDown();
}
......@@ -68,7 +81,7 @@ class CollectionOptimizerTest extends KernelTestBase {
foreach ($this->jsFilesUnderTest() as $js_file => $expired) {
if ($expired === TRUE) {
$this->assertFileNotExists($js_file);
$this->assertFileDoesNotExist($js_file);
continue;
}
$this->assertFileExists($js_file);
......@@ -103,12 +116,12 @@ class CollectionOptimizerTest extends KernelTestBase {
$dumper = $this->prophesize(AssetDumper::class);
$state = $this->prophesize(StateInterface::class);
$optimizer = new CssCollectionOptimizer($grouper->reveal(), new CssOptimizer(), $dumper->reveal(), $state->reveal(), $this->container->get('file_system'));
$optimizer = new CssCollectionOptimizer($grouper->reveal(), new CssOptimizer($this->fileUrlGenerator), $dumper->reveal(), $state->reveal(), $this->container->get('file_system'));
$optimizer->deleteAll();
foreach ($this->cssFilesUnderTest() as $css_file => $expired) {
if ($expired === TRUE) {
$this->assertFileNotExists($css_file);
$this->assertFileDoesNotExist($css_file);
continue;
}
$this->assertFileExists($css_file);
......
......@@ -8,6 +8,8 @@ use Drupal\flysystem\Flysystem\Adapter\CacheItem;
use Drupal\flysystem\Flysystem\Adapter\CacheItemBackend;
/**
* Tests \Drupal\flysystem\Flysystem\Adapter\CacheItemBackend.
*
* @group flysystem
*
* @coversDefaultClass \Drupal\flysystem\Flysystem\Adapter\CacheItemBackend
......@@ -32,7 +34,7 @@ class CacheItemBackendTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
public function setup() {
public function setup(): void {
$this->cacheBackend = new MemoryBackend('foo');
$this->cacheItemBackend = new CacheItemBackend('test-scheme', $this->cacheBackend);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment