Skip to content

Fix Cp helper class for frankendphp worker mode #16848

Merged
brandonkelly merged 1 commit intocraftcms:5.7from
giorgiopogliani:fix/static-site-for-worker-mode
Mar 7, 2025
Merged

Fix Cp helper class for frankendphp worker mode #16848
brandonkelly merged 1 commit intocraftcms:5.7from
giorgiopogliani:fix/static-site-for-worker-mode

Conversation

@giorgiopogliani
Copy link
Copy Markdown
Contributor

Description

I was testing frankenphp worker mode with Craft CMS and I found a problem that I don't think has a solution without some changes to Craft.

Basically the craft\helpers\Cp class has a static property of the requested site and it's only set once. If it's already set the property is returned. This is causing the sites dropdown to basically not work without restarting the worker.

The property It's also private and not nullable, so I can't do much from outside.

The changes:
• Static properties cannot be unset, so I updated the type hint of the $_requestedSite to be nullable. The function requestedSite() returns a nullable anyway, so maybe, it might even make sense.
• Then I updated the if in the requestedSite() function to set the variable only when it's null instead of uninitialized.
• I added a public function to clear the requested site, setting it to null. In this way I can call the function from outside at the start of each request to be sure that the correct site will be used.

Thanks.

@giorgiopogliani giorgiopogliani changed the title update Cp class Fix Cp helper class for worker mode Mar 7, 2025
@giorgiopogliani giorgiopogliani changed the title Fix Cp helper class for worker mode Fix Cp helper class for frankendphp worker mode Mar 7, 2025
@brandonkelly brandonkelly changed the base branch from 5.x to 5.7 March 7, 2025 22:59
@brandonkelly brandonkelly merged commit a8ad2ca into craftcms:5.7 Mar 7, 2025
@brandonkelly
Copy link
Copy Markdown
Member

Thanks! Renamed to reset() and merged into the 5.7 branch via c379f83.

@giorgiopogliani giorgiopogliani deleted the fix/static-site-for-worker-mode branch March 8, 2025 09:24
@brandonkelly
Copy link
Copy Markdown
Member

Craft 5.7.0 is out with that change.

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.

2 participants