Skip to content

Adds bot-parsers as injectionable objects #5712

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

Merged
merged 3 commits into from
Mar 5, 2018

Conversation

NanneHuiges
Copy link
Contributor

Handles the botparser equivalent to the client/device parsers. This way
users of the library can add their own botparser that might not be
usefull for the library, but are needed in their own situation. (for instance:
add a botparser that can recognize internal bots with specific user-agents,
that would never be encountered in the wild and therefore not very usefull
in the library)

Notes:

  • The methods have been made to be as equivalent to their client/device counterparts.
  • The parseBot() function uses the same logic as the parsClient() and parseDevice() functions.
  • The addBotParser() function is simpeler as there is only a single botparser in the library: we don't need the string version and/or a separate directory with multiple botparsers
  • The new call in the construct looks like it breaks the current standard, but creating an object here isn't much different from calling the function with a string and creating that object in the function. As we don't need the string-method for the bot, it seems best to just call it like this.

Handles the botparser equivalent to the client/device parsers. This way
users of the library can add their own botparser that might not be
usefull for the library, but are needed in their own situation.

As there does not seem to be any usecase for adding multple bot-parsers
in this project, there is no separte directory with bot-parsers, nor can
we add a botparser by string.
@NanneHuiges
Copy link
Contributor Author

I wasn't sure if it was better to start a discussion (issue?) first before just doing a pull-request for this, but as the amount of code is small and most is based upon code that's in different equivalent functions, this seemed to be the best way :)

$botParser->setYamlParser($this->getYamlParser());
$botParser->setCache($this->getCache());
if ($this->discardBotInformation) {
$botParser->discardDetails();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes the special discardDetails for the bot parser. This is quite important, as it speeds up the detection for bots a lot if no detailed bot information is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ow, that's really bad, sorry for that! I'll write a fix for that tomorrow, tried to make it too much te same as the other 2 functions, and then I stopped paying attention.

Are you open for the concept of this MR though?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, why not allowing multiple / custom bot parsers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test that picks up this bug (again, that was careless, sorry), and added a fix. Needed to add an abstract class to define the discardDetails() method for the bots.

Re-adds the discardDetails() that accidently got removed in the refactor.
To be able to do this on all added bots, an abstract is created. It could
have been an interface, but all other (client, device) do this with an
abstract, so that pattern is followed

Adds a test that catches the problem in previous commit, and passes now
@NanneHuiges
Copy link
Contributor Author

Have you had time to look at the update? Is there anything else I could/should update?

@sgiehl
Copy link
Member

sgiehl commented Mar 2, 2018

will have a closer look on Monday

@sgiehl sgiehl merged commit 25e11d1 into matomo-org:master Mar 5, 2018
@NanneHuiges NanneHuiges deleted the inject_bot_parser branch March 5, 2018 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants