Make sure to always trigger site event when creating a new site instance #11001
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #10990 I already tried to achieve this but noticed there are still case when this is not working. For example any request to
SitesManager.getSiteFromId
will overwrite any site information inSite::$infoSites
.Meaning a controller might do
new Site()
, then further down an API request, or the archiver doesSitesManager.getSiteFromId
and overwrites a previously enriched site. It is even more messy that at any point the data withinnew Site()
might be changed by another API request or method that callsSites::set*
.It is much better to instead keep the site in a non-static property when an instance is created and to always work on that data. This is much more reliable and what consumers expect. In theory, there could be a case that a site is deleted or updated via an API request, and then the data within
Site->site
is not updated automatically but this is not a problem for us.Having this PR merged will make sure that when you change eg the name of a website with the event
Site.setSites
, it will appear correctly in the website selector and in the mobile app.There are still more inconsistencies to tackle eventually. Eg all
SitesManager.get*
methods might trigger theSite.getSites
event letting consumers change the site objects, but none of the APIs actually return the changed value. This is much harder to solve though and therefore not included in this PR