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

Full refactor of site content detection and no data page logic #21029

Merged
merged 35 commits into from
Sep 15, 2023

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Jul 18, 2023

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:

  • class Piwik\SiteContentDetector
    this one will handle the overall detection as it was before
  • multiple classes extending 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

@sgiehl sgiehl force-pushed the refactornodatapage branch 3 times, most recently from cb8dd85 to 82bbb45 Compare July 24, 2023 12:25
@sgiehl sgiehl added this to the 5.0.0 milestone Jul 24, 2023
@sgiehl sgiehl force-pushed the refactornodatapage branch 4 times, most recently from 10a3a28 to c9d72aa Compare July 31, 2023 08:50
@sgiehl sgiehl force-pushed the refactornodatapage branch 4 times, most recently from 3afddbb to bd06a31 Compare August 3, 2023 13:42
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Aug 18, 2023
@sgiehl sgiehl force-pushed the refactornodatapage branch from bd06a31 to ac8c09f Compare August 29, 2023 05:15
@sgiehl sgiehl force-pushed the refactornodatapage branch 3 times, most recently from 21c0a21 to 0fd36cd Compare September 1, 2023 12:56
@michalkleiner michalkleiner removed the Stale The label used by the Close Stale Issues action label Sep 4, 2023
@sgiehl sgiehl force-pushed the refactornodatapage branch from 391111f to 4906275 Compare September 4, 2023 13:55
@sgiehl sgiehl force-pushed the refactornodatapage branch from a4cca21 to bc0181a Compare September 4, 2023 20:16
@sgiehl sgiehl force-pushed the refactornodatapage branch from bc0181a to 080c622 Compare September 7, 2023 12:34
@sgiehl sgiehl force-pushed the refactornodatapage branch from 597db6a to 3e2199f Compare September 8, 2023 09:47
@sgiehl sgiehl marked this pull request as ready for review September 8, 2023 13:14
@sgiehl sgiehl added the Needs Review PRs that need a code review label Sep 8, 2023
*
* @return string
*/
public static function getId(): string
Copy link
Contributor

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

Copy link
Contributor

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).

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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 😆

* @param SiteContentDetector|null $detector
* @return string|null
*/
public function renderOthersInstruction(SiteContentDetector $detector = null): ?string
Copy link
Contributor

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

Copy link
Contributor

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.

* Reset the detection properties
* @return array<string, SiteContentDetectionAbstract[]>
*/
public static function getSiteContentDetectionsByType()
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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.

@sgiehl sgiehl merged commit 77b4d09 into 5.x-dev Sep 15, 2023
@sgiehl sgiehl deleted the refactornodatapage branch September 15, 2023 15:03
@tsteur
Copy link
Member

tsteur commented Sep 18, 2023

Hi @sgiehl , @caddoo @michalkleiner there may be some bug in there. Not sure if I'm seeing it correctly.

image

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.

@sgiehl
Copy link
Member Author

sgiehl commented Sep 18, 2023

Passing the object id is correct. Already came across that problem when working on #21247 and fixed it in that PR.
Will push a fix on 5.x-dev directly.

@tsteur
Copy link
Member

tsteur commented Sep 18, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error message while accessing tracking code when Tour plugin is disabled
4 participants