User tests: Successful: Unsuccessful:
Pull Request for Issue #41183 .
The banners module supports using banners by tag search or keywords. When the banners model is building the query for it, there is a reg-expression to search for words. This regex seems not be compatible with MySql version 8.0.4 and newer.
The SQL query, which is created, is something like: Where metakey regexp('[[:<:]]Mo[[:>:]]')
"Mo" is the keyword to search for.
Executing it on MySql 8.0.4 or any newer version, it throws the error "Illegal argument to a regular expression.".
I think the correct reg-expression must be: Where metakey regexp('\\bMo\\b')
In the MySql manual https://dev.mysql.com/doc/refman/8.0/en/regexp.html there is the explanation about the switch from the Henry Spencer's implementation to the ICU compatible implementation:
MySQL implements regular expression support using International Components for Unicode (ICU), which provides full Unicode support and is multibyte safe. (Prior to MySQL 8.0.4, MySQL used Henry Spencer's implementation of regular expressions, which operates in byte-wise fashion and is not multibyte safe.
Further information in the web can for example be found here:
https://bugs.mysql.com/bug.php?id=106504
https://stackoverflow.com/questions/59998409/error-code-3685-illegal-argument-to-a-regular-expression
System information:
Joomla: The site which had/has those issues had version 5 and is in the meantime migrated to 6 (where the errors still appear).
DB type: mysql
DB version: 8.0.42
PHP-Version: 8.4.7
Background information:
I use a custom component which calls in a view $this->getDocument()->setMetaData('keywords', $currentKeywords);
With this approach, the banners module gets those keywords in its BannersHelper method getBanners() line 45 with:
$keywords = explode(',', $app->getDocument()->getMetaData('keywords'));
With this Pull Request the reg-expression will be surrounded with a db type and version check, which makes sure the correct expression is used for both versions.
In the same part of the banners model there is
another fix for a null ref deprecation warning from PHP 8:
Deprecated
: str_starts_with(): Passing null to parameter #2 ($needle) of type string is deprecated in
[root]\components\com_banners\src\Model\BannersModel.php on line 219
a fix for a PHP 8 warning:
Warning
: foreach() argument must be of type array|object, false given in
[root]\components\com_banners\src\Model\BannersModel.php on line 275
Honestly, I don't know how I can provide the keywords with the Joomla standard components. So the easiest way to reproduce is:
$keywords = explode(',', $app->getDocument()->getMetaData('keywords'));$keywords = ['Mo'];#2 ($needle) of type string is deprecated..." is displayed.Please select:
Documentation link for docs.joomla.org:
No documentation changes for docs.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed
| Status | New | ⇒ | Pending |
| Category | ⇒ | Front End com_banners |
| Labels |
Added:
PR-5.4-dev
|
||
Good point, I didn't saw it. Yes, indeed, the word boundary part is the same. Although the related issue 41183 mentioned MariaDb as well and there is a discussion about a more generic/clean implementation. It seems that my PR is more like a quick fix.
@richard67 Since you were involved in the discussion of issue 41183, what do you think: Is my quick fix acceptable? I don't believe I'm capable of implementing the clean approach of extending the database providers.
| Title |
|
||||||
@richard67 Since you were involved in the discussion of issue 41183, what do you think: Is my quick fix acceptable? I don't believe I'm capable of implementing the clean approach of extending the database providers.
@beni71 If you accept my code change suggestions (can be done with buttons on GitHub), the PR is ok and can be changed from draft to ready for review.
I have now a general question:
It seems that this PR is based on an old way to pass keywords to the banners module, throught the document, which was removed from the Joomla components with #25258. Joomla components no longer support it. Does it mean that it is deprecated anyway? If so, I will close the PR.
To be honest: I have no idea if it is deprecated. Let's see if other comments come it.
The reason why I haven't made a PR yet for fixing the issue was because I was not able to find out how and when keywords were used in the banner module.
As far as I know keywords of articles are used for the related articles module.
Thanks, I will give it a try.
@beni71 - first off, thank you for your contribution, unfortunately, I am not getting exactly what you are intending:
(just a small, perhaps obvious instruction update , you need to set a position for the module ;))
I set mine to Below_Top (and then Main_Bottom to see if that would change things... only difference is that with Main_Bottom I saw the Chrome with the title: Site Module Banner which isn't present in Below_top).
BEFORE CONDITION, I only match 2 out of 4 of your conditions,
I get "No banners are visualized." - I do NOT have the error message: The getItems method has catched the error "Illegal argument to a regular expression." but returned
The PHP 8 deprecation warning "...Passing null to parameter #2 ($needle) of type string is deprecated..." is displayed.
I get:
Deprecated
: str_starts_with(): Passing null to parameter #2 ($needle) of type string is deprecated in
/home/lights/public_html/_j540/components/com_banners/src/Model/BannersModel.php
on line
219
which seems to be a match!
AFTER CONDITION: no more error message BUT no banner displayed. NO errors in Console in either case ;)
Hope that helps you!
Related issue #41183 ?