Project

General

Profile

Actions

Bug #87979

open

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

Added by Ralf Hübner over 5 years ago. Updated 5 months ago.

Status:
Needs Feedback
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2019-03-22
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

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

Actions #1

Updated by Bastian Bringenberg over 5 years ago

  • Tracker changed from Support to Bug
  • Project changed from 9 to TYPO3 Core
  • TYPO3 Version set to 9

Moved to correct Project.

Actions #2

Updated by Michal Cygankiewicz almost 5 years ago

Hi,
did you found any solution for that?

Actions #3

Updated by Gerrit Code Review over 4 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63929

Actions #4

Updated by Gerrit Code Review over 4 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63929

Actions #5

Updated by Gerrit Code Review over 4 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/63929

Actions #6

Updated by Susanne Moog over 4 years ago

  • Status changed from Under Review to Needs Feedback

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.

Actions #7

Updated by Ralf Hübner over 4 years ago

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']; 
}

Actions #8

Updated by Rémy DANIEL over 2 years ago

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();

Actions #9

Updated by Benni Mack 5 months ago

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

Actions #10

Updated by Rémy DANIEL 5 months ago

Hi Benni

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

Actions

Also available in: Atom PDF