Commit e3a3c7c0 authored by Conrad Lara's avatar Conrad Lara
Browse files

Issue #3264636 by cmlara, Bladedu: S3fsImageStyleDownloadController fixup $converted_image_uri

parent 9aeb8210
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\s3fs\Controller;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\StreamWrapper\StreamWrapperManager;
use Drupal\image\Controller\ImageStyleDownloadController;
use Drupal\image\ImageStyleInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -79,8 +80,8 @@ class S3fsImageStyleDownloadController extends ImageStyleDownloadController {
      // original file, resulting in filenames like image.png.jpeg. So to find
      // the actual source image, we remove the extension and check if that
      // image exists.
      $path_info = pathinfo($image_uri);
      $converted_image_uri = $path_info['dirname'] . DIRECTORY_SEPARATOR . $path_info['filename'];
      $path_info = pathinfo(StreamWrapperManager::getTarget($image_uri));
      $converted_image_uri = sprintf('%s://%s/%s', $this->streamWrapperManager->getScheme($derivative_uri), $path_info['dirname'], $path_info['filename']);
      if (!file_exists($converted_image_uri)) {
        $this->logger->notice('Source image at %source_image_path not found while trying to generate derivative image at %derivative_path.',
          [
+37 −0
Original line number Diff line number Diff line
@@ -203,6 +203,43 @@ class S3fsTest extends S3fsTestBase {

  }

  /**
   * Tests that files stored in the root folder are converted properly.
   *
   * Imported from core.
   */
  public function testConvertFileInRoot() {
    // Create the test image style with a Convert effect.
    $image_style = ImageStyle::create([
      'name' => 'image_effect_test',
      'label' => 'Image Effect Test',
    ]);
    $this->assertEquals(SAVED_NEW, $image_style->save());
    $image_style->addImageEffect([
      'id' => 'image_convert',
      'data' => [
        'extension' => 'jpeg',
      ],
    ]);
    $this->assertEquals(SAVED_UPDATED, $image_style->save());

    // Create a copy of a test image file in root.
    $test_uri = 's3://image-test-do.png';
    $img_localpath = __DIR__ . '/../../fixtures/test.png';
    $img_data = file_get_contents($img_localpath);
    $this->saveData($img_data, $test_uri);

    $this->assertFileExists($test_uri);

    // Execute the image style on the test image via a GET request.
    $derivative_uri = 's3://styles/image_effect_test/s3/image-test-do.png.jpeg';
    $this->assertFileDoesNotExist($derivative_uri);
    $style_url_parsed = UrlHelper::parse(ImageStyle::load('image_effect_test')->buildUrl($test_uri));
    $this->drupalGet($style_url_parsed['path'], ['query' => $style_url_parsed['query']]);
    $this->assertSession()->statusCodeEquals(200);
    $this->assertFileExists($derivative_uri);
  }

  /**
   * Test the cache refresh.
   */