Skip to content

[BUGFIX] Use absolute paths for SCSS cache file existence checks#1621

Open
dkd-kaehm wants to merge 1 commit intobenjaminkott:masterfrom
dkd-kaehm:bugfix/path_contexts
Open

[BUGFIX] Use absolute paths for SCSS cache file existence checks#1621
dkd-kaehm wants to merge 1 commit intobenjaminkott:masterfrom
dkd-kaehm:bugfix/path_contexts

Conversation

@dkd-kaehm
Copy link
Copy Markdown

The isCached() and needsCompile() methods use relative paths (e.g. "typo3temp/assets/bootstrappackage/css/...") for file_exists() and filemtime() calls. These relative paths are resolved against the current working directory (CWD).

In web request context, the CWD is typically the document root (public/), so the relative paths resolve correctly. However, in CLI context (e.g. TYPO3 scheduler tasks, cache warmup scripts), the CWD is the project root — one level above public/. This causes file_exists() to always return false, forcing a full SCSS recompilation on every request even when a valid cache file exists.

This is particularly impactful for extensions that trigger internal sub-requests via Application::handle() (e.g. Apache Solr indexing), where SCSS compilation runs multiple times per CLI invocation, adding ~80 seconds per compilation.

The fix resolves cache file paths to absolute paths using GeneralUtility::getFileAbsFileName() before performing filesystem checks, consistent with how ScssParser::compile() already resolves paths when writing cache files.

The isCached() and needsCompile() methods use relative paths
(e.g. "typo3temp/assets/bootstrappackage/css/...") for file_exists()
and filemtime() calls. These relative paths are resolved against the
current working directory (CWD).

In web request context, the CWD is typically the document root
(public/), so the relative paths resolve correctly. However, in CLI
context (e.g. TYPO3 scheduler tasks, cache warmup scripts), the CWD
is the project root — one level above public/. This causes
file_exists() to always return false, forcing a full SCSS
recompilation on every request even when a valid cache file exists.

This is particularly impactful for extensions that trigger internal
sub-requests via Application::handle() (e.g. Apache Solr indexing),
where SCSS compilation runs multiple times per CLI invocation,
adding ~80 seconds per compilation.

The fix resolves cache file paths to absolute paths using
GeneralUtility::getFileAbsFileName() before performing filesystem
checks, consistent with how ScssParser::compile() already resolves
paths when writing cache files.
dkd-kaehm added a commit to dkd-kaehm/ext-solr that referenced this pull request Mar 26, 2026
…onment

Sub-requests via Application::handle() run in CLI context where the
working directory is the project root, not the document root (public/).
Third-party code relying on relative paths (e.g. BootstrapPackage SCSS
cache checks using file_exists() with relative paths) fails silently,
causing full SCSS recompilation on every sub-request.

xHProf profiling revealed the impact:
- Before fix: 331s per indexing run (94% spent in SCSS recompilation)
- After fix: 10s per indexing run (95% faster)
- SCSS was compiled 4x per run (once per sub-request) instead of 0x

The fix adds chdir(Environment::getPublicPath()) around
Application::handle() in executeSubRequest(), restoring the original
CWD afterwards via try/finally. This ensures all sub-request code
behaves identically to a real web request, regardless of third-party
extension implementation details.

With this generic fix, the legacy CliEnvironment class and the
forcedWebRoot scheduler task option become obsolete and are removed:
- Classes/System/Environment/CliEnvironment.php
- Classes/System/Environment/WebRootAllReadyDefinedException.php
- IndexQueueWorkerTask: CliEnvironment usage, forcedWebRoot property
  and related methods (getWebRoot, replaceWebRootMarkers)
- IndexQueueWorkerTaskAdditionalFieldProvider: forcedWebRoot form field
- locallang.xlf: forcedWebRoot label

An integration test verifies that CWD is correctly restored after
sub-request indexing and that indexing succeeds even when CWD does
not match the public directory.

Related: benjaminkott/bootstrap_package#1621

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dkd-kaehm added a commit to dkd-kaehm/ext-solr that referenced this pull request Mar 30, 2026
…onment

Sub-requests via Application::handle() run in CLI context where the
working directory is the project root, not the document root (public/).
Third-party code relying on relative paths (e.g. BootstrapPackage SCSS
cache checks using file_exists() with relative paths) fails silently,
causing full SCSS recompilation on every sub-request.

xHProf profiling revealed the impact:
- Before fix: 331s per indexing run (94% spent in SCSS recompilation)
- After fix: 10s per indexing run (95% faster)
- SCSS was compiled 4x per run (once per sub-request) instead of 0x

The fix adds chdir(Environment::getPublicPath()) around
Application::handle() in executeSubRequest(), restoring the original
CWD afterwards via try/finally. This ensures all sub-request code
behaves identically to a real web request, regardless of third-party
extension implementation details.

With this generic fix, the legacy CliEnvironment class and the
forcedWebRoot scheduler task option become obsolete and are removed:
- Classes/System/Environment/CliEnvironment.php
- Classes/System/Environment/WebRootAllReadyDefinedException.php
- IndexQueueWorkerTask: CliEnvironment usage, forcedWebRoot property
  and related methods (getWebRoot, replaceWebRootMarkers)
- IndexQueueWorkerTaskAdditionalFieldProvider: forcedWebRoot form field
- locallang.xlf: forcedWebRoot label

An integration test verifies that CWD is correctly restored after
sub-request indexing and that indexing succeeds even when CWD does
not match the public directory.

Related: benjaminkott/bootstrap_package#1621

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dkd-kaehm added a commit to dkd-kaehm/ext-solr that referenced this pull request Mar 31, 2026
…onment

Sub-requests via Application::handle() run in CLI context where the
working directory is the project root, not the document root (public/).
Third-party code relying on relative paths (e.g. BootstrapPackage SCSS
cache checks using file_exists() with relative paths) fails silently,
causing full SCSS recompilation on every sub-request.

xHProf profiling revealed the impact:
- Before fix: 331s per indexing run (94% spent in SCSS recompilation)
- After fix: 10s per indexing run (95% faster)
- SCSS was compiled 4x per run (once per sub-request) instead of 0x

The fix adds chdir(Environment::getPublicPath()) around
Application::handle() in executeSubRequest(), restoring the original
CWD afterwards via try/finally. This ensures all sub-request code
behaves identically to a real web request, regardless of third-party
extension implementation details.

With this generic fix, the legacy CliEnvironment class and the
forcedWebRoot scheduler task option become obsolete and are removed:
- Classes/System/Environment/CliEnvironment.php
- Classes/System/Environment/WebRootAllReadyDefinedException.php
- IndexQueueWorkerTask: CliEnvironment usage, forcedWebRoot property
  and related methods (getWebRoot, replaceWebRootMarkers)
- IndexQueueWorkerTaskAdditionalFieldProvider: forcedWebRoot form field
- locallang.xlf: forcedWebRoot label

An integration test verifies that CWD is correctly restored after
sub-request indexing and that indexing succeeds even when CWD does
not match the public directory.

Related: benjaminkott/bootstrap_package#1621

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dkd-kaehm added a commit to dkd-kaehm/ext-solr that referenced this pull request Mar 31, 2026
…onment

Sub-requests via Application::handle() run in CLI context where the
working directory is the project root, not the document root (public/).
Third-party code relying on relative paths (e.g. BootstrapPackage SCSS
cache checks using file_exists() with relative paths) fails silently,
causing full SCSS recompilation on every sub-request.

xHProf profiling revealed the impact:
- Before fix: 331s per indexing run (94% spent in SCSS recompilation)
- After fix: 10s per indexing run (95% faster)
- SCSS was compiled 4x per run (once per sub-request) instead of 0x

The fix adds chdir(Environment::getPublicPath()) around
Application::handle() in executeSubRequest(), restoring the original
CWD afterwards via try/finally. This ensures all sub-request code
behaves identically to a real web request, regardless of third-party
extension implementation details.

With this generic fix, the legacy CliEnvironment class and the
forcedWebRoot scheduler task option become obsolete and are removed:
- Classes/System/Environment/CliEnvironment.php
- Classes/System/Environment/WebRootAllReadyDefinedException.php
- IndexQueueWorkerTask: CliEnvironment usage, forcedWebRoot property
  and related methods (getWebRoot, replaceWebRootMarkers)
- IndexQueueWorkerTaskAdditionalFieldProvider: forcedWebRoot form field
- locallang.xlf: forcedWebRoot label

An integration test verifies that CWD is correctly restored after
sub-request indexing and that indexing succeeds even when CWD does
not match the public directory.

Related: benjaminkott/bootstrap_package#1621

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dkd-kaehm added a commit to TYPO3-Solr/ext-solr that referenced this pull request Mar 31, 2026
…onment

Sub-requests via Application::handle() run in CLI context where the
working directory is the project root, not the document root (public/).
Third-party code relying on relative paths (e.g. BootstrapPackage SCSS
cache checks using file_exists() with relative paths) fails silently,
causing full SCSS recompilation on every sub-request.

xHProf profiling revealed the impact:
- Before fix: 331s per indexing run (94% spent in SCSS recompilation)
- After fix: 10s per indexing run (95% faster)
- SCSS was compiled 4x per run (once per sub-request) instead of 0x

The fix adds chdir(Environment::getPublicPath()) around
Application::handle() in executeSubRequest(), restoring the original
CWD afterwards via try/finally. This ensures all sub-request code
behaves identically to a real web request, regardless of third-party
extension implementation details.

With this generic fix, the legacy CliEnvironment class and the
forcedWebRoot scheduler task option become obsolete and are removed:
- Classes/System/Environment/CliEnvironment.php
- Classes/System/Environment/WebRootAllReadyDefinedException.php
- IndexQueueWorkerTask: CliEnvironment usage, forcedWebRoot property
  and related methods (getWebRoot, replaceWebRootMarkers)
- IndexQueueWorkerTaskAdditionalFieldProvider: forcedWebRoot form field
- locallang.xlf: forcedWebRoot label

An integration test verifies that CWD is correctly restored after
sub-request indexing and that indexing succeeds even when CWD does
not match the public directory.

Related: benjaminkott/bootstrap_package#1621

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant