Fix possible error when generating reports for custom dimensions #18614
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
I have been able to reproduce #18608 with the dataset provided in #18608 (comment)
On PHP 7.2 I actually get a
PHP 8 throws the error describe in the issue.
I took a deep dive through the code and the issue now appears to be clear to me.
The report generator uses the API Proxy to fetch API results. Therefor the parameters are determined using this method:
matomo/core/API/Proxy.php
Lines 409 to 441 in a01eea3
The API definition for CustomDimensions is this one:
matomo/plugins/CustomDimensions/API.php
Line 54 in a01eea3
So the default value for
$idSubtable
is actuallynull
. In the request variablesidSubtable
is set to an empty string.This causes the method to fetch the parameter value here:
matomo/core/API/Proxy.php
Line 422 in a01eea3
to throw an exception as the
$defaultValue
isnull
.See
matomo/core/Common.php
Lines 507 to 515 in 4f5cda9
Note:
$requestArrayToUse[$varName]
is set to the empty string herewhich then causes the value to be set to an empty string here:
matomo/core/API/Proxy.php
Lines 426 to 430 in a01eea3
The
idSubtable
is then passed through various methods, finally causing the issue here:matomo/core/Archive/Chunk.php
Lines 31 to 33 in 1155273
Regarding the solution there are actually two ways to fix that.
One way is to simply handle an empty string for the
idSubtable
asnull
, likefalse
is already handled.Another fix would be to change the definition of the API method to
$idSubtable = false
instead ofnull
.The reason why that would work is, as this part
matomo/core/API/Proxy.php
Line 422 in a01eea3
will no longer throw an exception. The
false
is a valid default value, which will simply be returned. Andfalse
is already handled correctly foridSubtable
in the code.This PR actually applies both adjustments. In all places I could find, we are currently using
$idSubtable = false
, so there is no good reason to usenull
in that one case. On the other side it can happen any time again, that someone definesnull
as default value again, which then could cause the same issue again.fixes #18608
Review