Fixes Error: Workflows with triggers, which have more than 65.535 parameters (or course IDs) throw an error (in all versions) #258
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.
v2
v1 (Issue: #243)
🔀 Purpose of this PR:
📝 Description:
The core issue is that all triggers are "calculated" in one database query to produce a single moodle_recordset as the result. If the combined triggers of a workflow contain more than 65.535 parameters (or course IDs) an error is thrown. The following screenshot shows the error when a workflow (with more than 65.535 parameters) is shown with version v4.4-r1.
A moodle_recordset can only be used or iterated through once. After that the results are no longer available and there is no way to merge multiple moodle_recordsets.
v1: (Issue: #243)
To address this I created a "helper class" that behaves like a moodle_recordset and allows moodle_recordsets to be added to it. If a moodle_recordset is added an intersection is created between the existing and the new moodle_recordset and this intersection is stored in the class. The exception is the first added moodle_recordset, which is entirely stored as the starting point.
This makes it possible to execute a separate database query for each trigger while still obtaining a single moodle_recordset as the final result. However, the issue reoccurs if a single trigger exceeds the 65.535 parameters (or course IDs) limit. This is the reason why this bugfix is an interim solution only and i didn't make a pull request so far. A complete solution would involve splitting all parameters from all triggers into chunks smaller or equal to 65.535 and then performing a database query for each of these chunks.
v2:
This extension of v1 addresses the issue of the bugfix where the original error reoccurs if a single trigger exceeds 65.535 parameters or course IDs. Now, the variable
$maxparams
defines the upper limit for the parameters. If this limit is exceeded for a trigger, the parameters are split into smaller chunks (, based on the upper limit). Additionally, the (partial) query of the affected trigger is reconstructed and filled with the corresponding "chunk parameters." These new "chunk pairs" then replace the original (partial) query and parameters of the trigger in the form of sub-arrays. Subsequently, a separate query is executed for each element of the sub-array and the results are stored in the same structure.Similarly, the constructor of the "helper class" (, which is required to simulate a final moodle_recordset) has been extended to recognize these sub-arrays with "chunk results." If this is the case, all results or moodle_recordsets of a "chunk result" are first aggregated into a single result, which is then added to build (and store) the intersection with the existing result of the triggers. This should be the final solution for this problem. The current solution has only been implemented for tool_lifecycle v4.5.
In short: If the parameter limit per trigger is exceeded, these queries are split into smaller queries and their results are reassembled before determining the intersection with the remaining triggers.
This error occurs in older versions as well as in the new 4.5 version. I have adapted the method get_course_recordset() in the file classes/processor.php and added a new class called intersectedRecordset in the classes/local/ dir.
📋 Checklist
phpunit
and/orbehat
tests that cover my changes or additions.var_dump()
orvar_export
or any other debugging statements (or commented out code) thatshould not appear on the productive branch.
db/upgrade.php
andupdated the
version.php
..min
files with thegrunt amd
command.version.php
and theCHANGES.md
.I ran all tests thoroughly checking for errors. I checked if bootstrap had any changes/deprecations that require
changes in the plugins UI.
🔍 Related Issues