Skip to content

[Bug] Create the snapshot temp directory when missing; drop checks PHPStan 2.1 rejects - #521

Merged
mcop1 merged 3 commits into
2.5from
fix/snapshot-temp-dir-and-phpstan
Sep 24, 2026
Merged

mcop1 merged 3 commits into
2.5from
fix/snapshot-temp-dir-and-phpstan

Conversation

@mcop1

@mcop1 mcop1 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Changes in this pull request

Aligns 2.5 with the adaptations the forward merge of #513 needed on the 2026 lines (merge commit d314f13 on 2026.2), so 2.5 and the 2026 lines stay identical for the next forward merge.

  • Temp directory: DocumentFileWriter::temporaryDirectory() now creates Pimcore's system temp directory (PIMCORE_SYSTEM_TEMP_DIRECTORY) when it does not exist yet, and falls back to the system temp directory only if that fails. Without it, tempnam() silently falls back and raises a notice; in a fresh PHP 8.4 test environment on 2026.2 that failed 19 snapshot unit tests.

  • PHPStan 2.1: removes three redundant checks that PHPStan 2.1 reports (is_array() on a value that is always an array, ?? on an explode() offset that always exists). Behaviour is unchanged; PHPStan 1.12 on 2.5 accepts both forms.

  • Flaky test: AssetMetadataFilterTest's relation filters used the literal id 123 as a non-matching id; once enough elements were created earlier in the run, the test's own element gets that id and matches (failed two CI legs on this PR). It now uses an id above the freshly created element, as [Test] Fix flaky functional tests caused by numeric fixtures colliding with element ids #464 did for the other filter tests.

Additional info

Verified locally on 2.5: PHPStan clean, snapshot unit suite 68, command suite 19 and snapshot functional suite 37 OK. The same changes were verified on 2026.2 and 2026.3 during the forward merge (full suite 746 OK on 2026.3).

🤖 Generated with Claude Code

…PStan 2.1 rejects

Aligns 2.5 with the adaptations the forward merge of #513 needed on the
2026 lines, so the next forward merge does not diverge:

- DocumentFileWriter::temporaryDirectory() creates Pimcore's system temp
  directory when it does not exist yet. tempnam() otherwise falls back to
  the system temp directory and raises a notice, which PHP 8.4 test runs
  turn into errors (19 unit tests failed in a fresh environment).
- Remove three redundant checks (is_array() on an array, ?? on an
  explode() offset that always exists) that PHPStan 2.1 reports.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings September 24, 2026 10:22
@mcop1 mcop1 added this to the 2.5.13 milestone Sep 24, 2026
@mcop1 mcop1 self-assigned this Sep 24, 2026
@mcop1 mcop1 added the Bug label Sep 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The temp-directory bug fix needs a deterministic regression test.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Aligns snapshot handling with newer branches by ensuring Pimcore’s temporary directory exists and satisfying PHPStan 2.1.

Changes:

  • Creates the configured snapshot temp directory when missing.
  • Removes redundant array and explode() checks.
File Description
DocumentFileWriter.php Creates or falls back from the configured temp directory.
ReplayIndexSettings.php Removes a redundant array check.
WorkerPoolBulkDispatcher.php Simplifies guaranteed explode() offset access.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Service/SearchIndex/Snapshot/DocumentFileWriter.php
The create-or-fall-back logic moves into DocumentFileWriter::usableDirectory(),
which takes the directory as a parameter so it can be tested without the Pimcore
constant: a missing nested directory is created and used, an existing one is used
as is, an uncreatable one and no configured one fall back to the system temp.
(Copilot, #521)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copilot AI previously approved these changes Sep 24, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approved

The focused fixes are correct, adequately tested, and introduce no unresolved issues.

Review effort: Balanced
Findings: None

Resolved since last review (1)

The relation filters used 123 as an id that does not match. Once enough elements
were created earlier in the run, the test's own asset, document or object gets id
123 and matches, failing the "no hit" assertion (seen in CI on #521). Use an id
above the freshly created element instead, as #464 did for the other filter tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mcop1
mcop1 requested a balanced review from Copilot September 24, 2026 10:46
Copilot AI dismissed their stale review, a newer Copilot review was requested September 24, 2026 10:46
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approved

The changes are focused, behaviorally sound, and adequately covered by regression tests.

Review effort: Balanced
Findings: None

@mcop1
mcop1 merged commit 4bc9ba0 into 2.5 Sep 24, 2026
24 of 25 checks passed
@mcop1
mcop1 deleted the fix/snapshot-temp-dir-and-phpstan branch September 24, 2026 11:02
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants