Goal pattern type and pattern regexes will now be validated in API when creating or updating goals.
Looks good and worked for me locally. Few tests are failing though such as https://travis-ci.org/matomo-org/matomo/jobs/372795044
Ah. Empty pattern types need to be allowed
Would it be a good idea to make these validations https://github.com/matomo-org/matomo/blob/3.x-dev/core/Validators/BaseValidator.php instances?
Don't have a strong opinion on that, but not sure if it's something that should / needs to be reusible
I'm thinking "is valid regex" could be reusable and "is one of values" could also be reusable (though this might already exist? not sure).
I think in this code might not be needed as it really depends on the way the
preg_match is executed later see this PR. If a developer doesn't surround the regex in
/ but for example a tilde, then the validation might not 100% work or if the developer doesn't do the
str_replace('/', '\/') etc
If a developer doesn't surround the regex in / but for example a tilde, then the validation might not 100% work or if the developer doesn't do the str_replace('/', '\/') etc
This functionality could always be added when the need comes up (ie, a developer who uses the validation w/ a different delimiter will eventually notice the issue). But having the place to put this functionality (ie, a validator class) makes it possible. Otherwise these checks could get lost when someone eventually does add a regex validator and the same logic will be replicated in different places. That said, it's just validation, not a life or death issue. It's not like not using a validator will make matomo collapse with complexity :)
Anything left here, or is that ready to merge?