Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Site.php #16999

Open
wants to merge 3 commits into
base: 11.2
Choose a base branch
from
Open

Update Site.php #16999

wants to merge 3 commits into from

Conversation

AlternateIf
Copy link
Contributor

Upon Calling sites that don't exist a user is forwarded to error pages set on site.

In Pimcore 11 this leads to an error:
Uncaught PHP Exception Error: "Typed property Pimcore\Model\Site::$localizedErrorDocuments must not be accessed before initialization" at Site.php line 300 {"exception":"[object] (Error(code: 0): Typed property Pimcore\Model\Site::$localizedErrorDocuments must not be accessed before initialization at /home/frischeis/www/vendor/pimcore/pimcore/models/Site.php:300)"} []

This PR should solve the problem by initializing the property

Copy link

Review Checklist

  • Target branch (11.2 for bug fixes, others 11.x)
  • Tests (if it's testable code, there should be a test for it - get help)
  • Docs (every functionality needs to be documented, see here)
  • Migration incl. install.sql (e.g. if the database schema changes, ...)
  • Upgrade notes (deprecations, important information, migration hints, ...)
  • Label
  • Milestone

@blankse
Copy link
Contributor

blankse commented Apr 29, 2024

@AlternateIf We should fix it also for the domain attribute.

Also the typehints of the setters of both should be changed from mixed to array|string

The rootId attribute should be nullable and initialised with null. Also the return typehint of the getter of rootId should be nullable.

@AlternateIf
Copy link
Contributor Author

@blankse included your suggestions to this PR

@blankse
Copy link
Contributor

blankse commented Apr 30, 2024

@AlternateIf Thank you. One more thing I see: The setRootDocument method doesn't set the rootId attribute.

I think we should change setRootId/setRootDocument to this:

    /**
     * @return $this
     */
    public function setRootId(int $rootId): static
    {
        $this->rootId = $rootId;
        $this->rootDocument = Document\Page::getById($this->rootId);

        return $this;
    }

    /**
     * @return $this
     */
    public function setRootDocument(?Document\Page $rootDocument): static
    {
        $this->rootDocument = $rootDocument;
        $this->rootId = $rootDocument?->getId();

        return $this;
    }

Copy link

sonarcloud bot commented Apr 30, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants