Commit 78558b2f authored by Nathaniel Burnett's avatar Nathaniel Burnett Committed by Jonathan Sacksick
Browse files

Issue #3263735 by Nathaniel, JProffitt, jsacksick: Add support for Flysystem S3.

parent ae5127f0
Loading
Loading
Loading
Loading
+19 −3
Changes for src/Controller/FileDownloadController.php: 19 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ use Drupal\Core\Access\AccessResult;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Drupal\file\FileInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
@@ -44,6 +45,13 @@ class FileDownloadController extends ControllerBase {
   */
  protected $streamWrapperManager;

  /**
   * The settings object.
   *
   * @var \Drupal\Core\Site\Settings
   */
  protected $settings;

  /**
   * Constructs a new FileDownloadController object.
   *
@@ -55,12 +63,15 @@ class FileDownloadController extends ControllerBase {
   *   The download logger.
   * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager
   *   The stream wrapper manager.
   * @param \Drupal\Core\Site\Settings $settings
   *   The settings object.
   */
  public function __construct(AccountInterface $current_user, LicenseFileManagerInterface $license_file_manager, DownloadLoggerInterface $download_logger, StreamWrapperManagerInterface $stream_wrapper_manager) {
  public function __construct(AccountInterface $current_user, LicenseFileManagerInterface $license_file_manager, DownloadLoggerInterface $download_logger, StreamWrapperManagerInterface $stream_wrapper_manager, Settings $settings) {
    $this->currentUser = $current_user;
    $this->licenseFileManager = $license_file_manager;
    $this->downloadLogger = $download_logger;
    $this->streamWrapperManager = $stream_wrapper_manager;
    $this->settings = $settings;
  }

  /**
@@ -71,7 +82,8 @@ class FileDownloadController extends ControllerBase {
      $container->get('current_user'),
      $container->get('commerce_file.license_file_manager'),
      $container->get('commerce_file.download_logger'),
      $container->get('stream_wrapper_manager')
      $container->get('stream_wrapper_manager'),
      $container->get('settings')
    );
  }

@@ -92,8 +104,12 @@ class FileDownloadController extends ControllerBase {
    $uri = $file->getFileUri();
    $scheme = $this->streamWrapperManager->getScheme($uri);

    // Check if Flysystem settings exist. If $scheme uses the S3 driver and has
    // the public option set to TRUE redirect to the external S3 URL.
    $flysystem_settings = $this->settings->get('flysystem', []);
    // Special handling for Amazon S3.
    if ($scheme === 's3') {
    if (($scheme === 's3' && !isset($flysystem_settings[$scheme])) || 
      (isset($flysystem_settings[$scheme]) && $flysystem_settings[$scheme]['driver'] == 's3' && !empty($flysystem_settings[$scheme]['config']['public']))) {
      $licenses = $this->licenseFileManager->getActiveLicenses($file);

      // This should not happen since we're already checking for an active