Issue Bug Needs Feedback Stale

#87979TYPO3\CMS\Extbase\Service::getImageUri in CLI Mode

Ralf Hübner 03/22/19, 09:30 updated 05/26/26, 15:27

Description

Hi,

i´ve the follwoing problem in TYPO3 v9.5.5 / Composer-Mode, Public-Root is “web”:

I use this TYPO3-Service “TYPO3\CMS\Extbase\Service::getImageUri” to retrieve the image path´s, e.g. for a Json-File.

But there is some confusion with the “uriPrefix”:

If this is called from the frontend, always fine – the path will be correct: _fileadmin/…_
but I run this service also in a Command/CLI and it seems the calculated “doc-root” is the composer-dir”: _*/web/*fileadmin/…_
This path is wrong against the frontend because the doc-Root itself is “web”.

My question is now:
Where ever I have to set a special “TYPO3_SITE_PATH” manually for CLI-Mode or is it a normal behavior or maybe a bug?

Kind regards
Ralf

Reviews 1

Fix this issue

Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". The changes above were merged or abandoned: read them before you start. How to create a patch

Commit message
[BUGFIX] TYPO3\CMS\Extbase\Service::getImageUri in CLI Mode Resolves: #87979 Releases: main

Files 1

History 1316

  1. Bastian Bringenberg commented and changed tracker Support Bug project id TYPO3 Version 9 <span data-processor="relativetime" data-value="2019-03-22T09:32:04+00:00" > 03/22/19, 09:32 </span>

    Moved to correct Project.

  2. Michal Cygankiewicz commented <span data-processor="relativetime" data-value="2020-01-07T09:55:13+00:00" > 01/07/20, 09:55 </span>

    Hi,
    did you found any solution for that?

  3. Gerrit Code Review pushed patch set 1 for master to change 63929 status New Under Review <span data-processor="relativetime" data-value="2020-03-26T10:21:11+00:00" > 03/26/20, 10:21 </span>

  4. Susanne Moog commented and changed status Under Review Needs Feedback <span data-processor="relativetime" data-value="2020-03-26T18:09:28+00:00" > 03/26/20, 18:09 </span>

    Hmm, we need to specify what exactly one would expect in CLI context, as we don’t really have the public path as far as I can see.

  5. Ralf Hübner commented <span data-processor="relativetime" data-value="2020-07-23T10:14:26+00:00" > 07/23/20, 10:14 </span>

    Susanne Moog wrote:
    > Hmm, we need to specify what exactly one would expect in CLI context, as we don’t really have the public path as far as I can see.

    Ok, a bit confusing:

    The function getImageUri should determine the public (uri)path of a image.
    Why should TYPO3_SITE_PATH the uriPrefix?

      if (isset($parsedUrl['host'])) {
                $uriPrefix = '';
            } elseif ($this->environmentService->isEnvironmentInFrontendMode()) {
                $uriPrefix = $GLOBALS['TSFE']->absRefPrefix;
            } else {
                $uriPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
            }

    This prefix is not part of the public url, it is the internal path or the “document-root”. Imo this is wrong:

     else {
                $uriPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
            }

    For the CLI-Mode it should work with a site-config call, maybe with a given site root page id?

     public function getImageUri(FileInterface $image, $absolute = false, $siteRootPid = false)
     [...]
     if (is_numeric($siteRootPid)) {
       $sitefinder = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Site\\SiteFinder');
       $uriPrefix = $sitefinder->getSiteByRootPageId($siteRootPid)->getConfiguration()['base']; 
    }
  6. Rémy DANIEL commented <span data-processor="relativetime" data-value="2022-03-07T14:57:54+00:00" > 03/07/22, 14:57 </span>

    Hi

    Another usecase where it fails: a scheduler command send a email with a fluid standalone view.
    The email template contains this:

      <f:image src="EXT:site/Resources/Public/Frontend/images/logo.png" absolute="1" />

    The rendered image src is:

    src="https://vendor/bin/typo3conf/ext/site/Resources/Public/Frontend/images/logo.png"

    My dirty workaround was:

    
    // Flush GeneralUtility $indpEnvCache 
    GeneralUtility::flushInternalRuntimeCaches();
    
    // Hack to get imageService generate absolute url in mail template
    $site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByIdentifier('my-site');
    $_SERVER['SCRIPT_NAME'] = '/index.php';
    $_SERVER['HTTP_HOST'] = $site->getRouter()->generateUri('/')->getHost();
  7. Benni Mack commented <span data-processor="relativetime" data-value="2024-06-24T15:38:28+00:00" > 06/24/24, 15:38 </span>

    We’ve made quite a lot of improvements since v9 in that area. Can you check if this still occurs in v12?

  8. Rémy DANIEL commented <span data-processor="relativetime" data-value="2024-06-25T15:13:14+00:00" > 06/25/24, 15:13 </span>

    Hi Benni

    Yes, I can reproduce the issue on TYPO3 12. The hack I provided still works.

  9. Rémy DANIEL commented and changed attached WithFeRequestTrait.php <span data-processor="relativetime" data-value="2026-05-26T14:22:28+00:00" > 05/26/26, 14:22 </span>

    Hi

    I still reproduce the issue on a v13.

    Simulating a FE request like in the doc don’t help, and introduce a new issue.
    If the template contains a f:translate VH, Extbase’s configuration manager (called by LocalizationUtility) crashes because no typoscript is loaded.

    I’ve spent several hours (again) on this topic, and here is the complete workaround I need to do on a v13: see attached WithFeRequestTrait.php

  10. Rémy DANIEL commented <span data-processor="relativetime" data-value="2026-05-26T14:26:12+00:00" > 05/26/26, 14:26 </span>

    While I’ve been working migrating a Command from v11 to v13, I also needed to:
    - avoid the use of typoscript, use Site set and Site settings instead
    - avoid the use of Extbase and especially its ConfigurationManager

    Workaround to fake a FE request or load typoscript in CLI used to worked in the past, but not anymore.
    CLI commands must be handled carefully when upgrading.

  11. Rémy DANIEL commented and changed TYPO3 Version 9 13 <span data-processor="relativetime" data-value="2026-05-26T14:31:38+00:00" > 05/26/26, 14:31 </span>

    I don’t know if it is possible: an acceptance test which send and assert the content of the following FluidEmail could be a good thing:

    <html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
          xmlns:site="http://typo3.org/ns/Site/Site/ViewHelpers"
          data-namespace-typo3-fluid="true">
    <f:layout name="FrontendEmail" />
    <f:section name="Main">
    This is a test email.
    Absolute url: {f:uri.typolink(parameter: '13', absolute: '1')}
    Image url: {f:uri.resource(path: 'Frontend/assets/images/pix.gif', extensionName: 'site', absolute: '1')}
    Translated text: {f:translate(key: 'external_link.title', extensionName: 'site')}
    </f:section>
    </html>

    This is the FluidEmail I use to test my setup.