Fix label filter does not work on all reports or depending on used parameters #7463
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.
I noticed sometimes a label filter does not work. This is because the DataTable thinks the
IndexFromLabelToId
is up to date but it is not. It will then fail to get the row by label.Here it [https://github.com/piwik/piwik/blob/2.12.0-b5/core/API/DataTableManipulator/LabelFilter.php#L72](tries to get the row by label) and [https://github.com/piwik/piwik/blob/2.12.0-b5/core/DataTable.php#L610](here it thinks the index is up to date which it is not).
How can this happen?
When we update the label on a row directly eg via
$row->setColumn('labe'l, 'newvalue')
the dataTable won't notice that the index has to be updated. Same when doing eg$table->queueFilter('ColumnCallbackReplace', array('label', 'Piwik\Plugins\Referrers\getPathFromUrl'));
or$table->queueFilter('GroupBy', array('label', 'Piwik\Plugins\Referrers\getPathFromUrl'));
for example here: https://github.com/piwik/piwik/blob/2.12.0-b5/plugins/Referrers/DataTable/Filter/UrlsFromWebsiteId.phpFor now the only way to make sure the index is up date when applying the label filter is to rebuild it. In another pull request I will on top invalidate the index for those 2 filters but this does not actually solve all problems. Only by rebuilding the index we can be sure to have the correct index.