-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Full refactor of site content detection and no data page logic #21029
Conversation
cb8dd85
to
82bbb45
Compare
10a3a28
to
c9d72aa
Compare
3afddbb
to
bd06a31
Compare
This comment was marked as outdated.
This comment was marked as outdated.
bd06a31
to
ac8c09f
Compare
21c0a21
to
0fd36cd
Compare
391111f
to
4906275
Compare
a4cca21
to
bc0181a
Compare
bc0181a
to
080c622
Compare
597db6a
to
3e2199f
Compare
* | ||
* @return string | ||
*/ | ||
public static function getId(): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say simplify this and have the inheritor manually define the ID, the reason is because the ID is now coupled directly to the classname, and I can see this value is used in things like cache.
It could make refactoring class names difficult in future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd agree here, the inheriting class could define the id. It can even be a public static $id
property so that we can directly use it instead of calling a method (probably minor to no performance difference).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like using static properties for stuff that needs to be defined/overwritten in each subclass. This makes it a lot harder for a developer to understand it, without adding comments. Abstraction is meant to be used for this purpose. So either we leave it the way it is, or we make that method abstract and have it defined in each subclass.
And the purpose of having it automatically defined based on the class name ensures that the id is unique - at least for the stuff defined in core. Non unique IDs would cause a detection to be overwritten and to become unavailable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for me as it is, we can always iterate on it if we feel strongly about some other approach. I guess I'm just used to it as Silverstripe CMS is all based on static configs, so it's a habit for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used to use that a lot in the past as well. But at some point I tried starting to use abstract methods instead, so others that need to reuse the code have it easier and can't create problems by accident without even knowing it. If there would be something like abstract attributes, that would be what I would prefer most 😆
plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php
Outdated
Show resolved
Hide resolved
* @param SiteContentDetector|null $detector | ||
* @return string|null | ||
*/ | ||
public function renderOthersInstruction(SiteContentDetector $detector = null): ?string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the return value of this be nullable? Shouldn't there always be instructions?
Same question for the $detector param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in the 'Others' tab, so a detector can return content for both the tab and the Others tab, but we won't want to display in the Others if it's detected and the tab displayed, so I'd say this is correct as nullable.
plugins/SitesManager/SiteContentDetection/SiteContentDetectionAbstract.php
Outdated
Show resolved
Hide resolved
core/SiteContentDetector.php
Outdated
* Reset the detection properties | ||
* @return array<string, SiteContentDetectionAbstract[]> | ||
*/ | ||
public static function getSiteContentDetectionsByType() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason this is static? Also might be good to add a return type while you are here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. It's a stateless method, that doesn't work with any instance attributes. So there is actually no reason for having it non static. Could change that, but that would also mean changing getKnownConsentManagers
to non static as it uses that method. What would be your argument for having it non static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only reason for non-static is in it's current state it can't be mocked making testing difficult, no strong opinion, up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should still be possible to simply use a full mock class whereever needed. The class is loaded using StaticContainer everywhere, so it could be replaced in testing.
Hi @sgiehl , @caddoo @michalkleiner there may be some bug in there. Not sure if I'm seeing it correctly. For a lot of tech it passes the classname to check if it was detected but the actual ID is only the last part of the name. |
Passing the object id is correct. Already came across that problem when working on #21247 and fixed it in that PR. |
Thanks @sgiehl . We'll then need a new RC after the fix is applied so we can make our tests work and also test overall |
Description:
The site detection logic as well as the no data page has grown too rapidly with random new change requests resulting in an unmaintainable, mostly untested code, having direct dependencies to certain plugins with tons of technical dept.
This PR fully refactors all the logic around site content detection as well as the full handling of the no data page.
Everything should now be easier adjustable, reusable, replaceable and extendable by plugins (without having to add changes in core)
The site content detection will the have two major parts:
Piwik\SiteContentDetector
this one will handle the overall detection as it was before
Piwik\Plugins\SitesManager\SiteContentDetection\SiteContentDetectionAbstract
Those files define the detections we provide. e.g. WordPress, Cloudflare, Osano, ...
In additional those classes can provide methods to render additional tabs or entries for the others tab on the no data page
The no data page basically still uses the SiteContentDetector to check what was detected or not. But all detection classes might now provide the own tab content. The order of the tabs is defined by a priority each class can provide. That way we can easily define which tab should be displayed if it was detected.
fixes #21200
Review