Commit facb8350 authored by Loredan Szocs's avatar Loredan Szocs Committed by Greg Knaddison
Browse files

Issue #3139001 by szloredan: Remove deprecated code for Drupal 9

parent df1ae7d3
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\stage_file_proxy\EventSubscriber;

use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Drupal\Core\Url;
use Drupal\stage_file_proxy\EventDispatcher\AlterExcludedPathsEvent;
use Drupal\stage_file_proxy\FetchManagerInterface;
@@ -150,7 +151,7 @@ class ProxySubscriber implements EventSubscriberInterface {
      }
      if ($config->get('use_imagecache_root')) {
        // Config says: Fetch the original.
        $fetch_path = file_uri_target($original_path);
        $fetch_path = StreamWrapperManager::getTarget($original_path);
      }
    }

+14 −4
Original line number Diff line number Diff line
@@ -3,8 +3,10 @@
namespace Drupal\stage_file_proxy;

use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Log\LoggerInterface;
@@ -35,13 +37,21 @@ class FetchManager implements FetchManagerInterface {
   */
  protected $logger;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * {@inheritdoc}
   */
  public function __construct(Client $client, FileSystemInterface $file_system, LoggerInterface $logger) {
  public function __construct(Client $client, FileSystemInterface $file_system, LoggerInterface $logger, ConfigFactoryInterface $config_factory) {
    $this->client = $client;
    $this->fileSystem = $file_system;
    $this->logger = $logger;
    $this->configFactory = $config_factory;
  }

  /**
@@ -108,13 +118,13 @@ class FetchManager implements FetchManagerInterface {
   * {@inheritdoc}
   */
  public function styleOriginalPath($uri, $style_only = TRUE) {
    $scheme = $this->fileSystem->uriScheme($uri);
    $scheme = StreamWrapperManager::getScheme($uri);
    if ($scheme) {
      $path = file_uri_target($uri);
      $path = StreamWrapperManager::getTarget($uri);
    }
    else {
      $path = $uri;
      $scheme = file_default_scheme();
      $scheme = $this->configFactory->get('system.file')->get('default_scheme');
    }

    // It is a styles path, so we extract the different parts.
+4 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\stage_file_proxy;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\File\FileSystemInterface;
use GuzzleHttp\Client;
use Psr\Log\LoggerInterface;
@@ -20,8 +21,10 @@ interface FetchManagerInterface {
   *   The file system.
   * @param \Psr\Log\LoggerInterface $logger
   *   The logger interface.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The configuration factory.
   */
  public function __construct(Client $client, FileSystemInterface $file_system, LoggerInterface $logger);
  public function __construct(Client $client, FileSystemInterface $file_system, LoggerInterface $logger, ConfigFactoryInterface $config_factory);

  /**
   * Downloads a remote file and saves it to the local files directory.
+1 −1
Original line number Diff line number Diff line
services:
  stage_file_proxy.fetch_manager:
    class: Drupal\stage_file_proxy\FetchManager
    arguments: ['@http_client', '@file_system', '@logger.channel.stage_file_proxy']
    arguments: ['@http_client', '@file_system', '@logger.channel.stage_file_proxy', '@config.factory']

  stage_file_proxy.subscriber:
    class: Drupal\stage_file_proxy\EventSubscriber\ProxySubscriber
+9 −1
Original line number Diff line number Diff line
@@ -50,6 +50,13 @@ class FetchManagerTest extends KernelTestBase {
   */
  protected $fileSystem;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Before a test method is run, setUp() is invoked.
   *
@@ -62,8 +69,9 @@ class FetchManagerTest extends KernelTestBase {
    $this->config('system.file')->set('default_scheme', 'public')->save();
    $this->client = new Client();
    $this->logger = \Drupal::logger('test_logger');
    $this->configFactory = $this->container->get('config.factory');

    $this->fetchManager = new FetchManager($this->client, $this->fileSystem, $this->logger);
    $this->fetchManager = new FetchManager($this->client, $this->fileSystem, $this->logger, $this->configFactory);
  }

  /**