Skip to content

Commit

Permalink
MDL-71390 core: raise max_input_vars requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed May 5, 2021
1 parent 1c9837a commit d42fd64
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 49 deletions.
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: max_input_vars=5000
coverage: none

- name: Checking out code from ${{ env.GITHUB_REF_SLUG }}
Expand Down
2 changes: 2 additions & 0 deletions admin/environment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3527,6 +3527,8 @@
<ON_CHECK message="sixtyfourbitswarning" />
</FEEDBACK>
</CUSTOM_CHECK>
<CUSTOM_CHECK file="lib/upgradelib.php" function="check_max_input_vars" level="optional">
</CUSTOM_CHECK>
</CUSTOM_CHECKS>
</MOODLE>
</COMPATIBILITY_MATRIX>
2 changes: 2 additions & 0 deletions lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,8 @@
$string['sessiontimeoutwarning'] = 'Timeout Warning';
$string['settingdependenton'] = 'This setting may be hidden, based on the value of <strong>{$a}</strong>.';
$string['settingfileuploads'] = 'File uploading is required for normal operation, please enable it in PHP configuration.';
$string['settingmaxinputvars'] = 'PHP setting max_input_vars is recommended to be at least 5000.';
$string['settingmaxinputvarsrequired'] = 'PHP setting max_input_vars must be at least 5000.';
$string['settingmemorylimit'] = 'Insufficient memory detected, please set higher memory limit in PHP settings.';
$string['settingsafemode'] = 'Moodle is not fully compatible with safe mode, please ask server administrator to turn it off. Running Moodle under safe mode is not supported, please expect various problems if you do so.';
$string['setupsearchengine'] = 'Setup search engine';
Expand Down
44 changes: 0 additions & 44 deletions lib/tests/behat/largeforms.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,6 @@ Feature: Forms with a large number of fields
And I should see "submitbutton=Submit here!"
And I should see "Bulk checkbox success: true"

@javascript
Scenario: Medium length form with checkboxes (needs workaround)
When I follow "Advanced checkboxes / Below limit"
And I press "Submit here!"
Then I should see "_qf__core_max_input_vars_form=1"
And I should see "mform_isexpanded_id_general=1"
And I should see "arraytest=[13,42]"
And I should see "array2test=[13,42]"
And I should see "submitbutton=Submit here!"
And I should see "Bulk checkbox success: true"

@javascript
Scenario: Exact PHP limit length form with checkboxes (uses workaround but doesn't need it)
When I follow "Advanced checkboxes / Exact PHP limit"
And I press "Submit here!"
Then I should see "_qf__core_max_input_vars_form=1"
And I should see "mform_isexpanded_id_general=1"
And I should see "arraytest=[13,42]"
And I should see "array2test=[13,42]"
And I should see "submitbutton=Submit here!"
And I should see "Bulk checkbox success: true"

@javascript
Scenario: Longer than the limit with checkboxes (needs workaround)
When I follow "Advanced checkboxes / Above limit"
And I press "Submit here!"
Then I should see "_qf__core_max_input_vars_form=1"
And I should see "mform_isexpanded_id_general=1"
And I should see "arraytest=[13,42]"
And I should see "array2test=[13,42]"
And I should see "submitbutton=Submit here!"
And I should see "Bulk checkbox success: true"

@javascript
Scenario: Small form with array fields (not using workaround)
When I follow "Select options / Small"
Expand Down Expand Up @@ -93,14 +60,3 @@ Feature: Forms with a large number of fields
And I should see "array2test=[13,42]"
And I should see "submitbutton=Submit here!"
And I should see "Bulk array success: true"

@javascript
Scenario: Longer than the limit with array fields (needs workaround)
When I follow "Select options / Above limit"
And I press "Submit here!"
Then I should see "_qf__core_max_input_vars_form=1"
And I should see "mform_isexpanded_id_general=1"
And I should see "arraytest=[13,42]"
And I should see "array2test=[13,42]"
And I should see "submitbutton=Submit here!"
And I should see "Bulk array success: true"
6 changes: 1 addition & 5 deletions lib/tests/fixtures/max_input_vars.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ public function definition() {
} else {
$fieldcount = (int)ini_get('max_input_vars') - 11;
}
} else if ($type[1] === 'l') {
// Just over the limit.
$fieldcount = (int)ini_get('max_input_vars') + 100;
}

$mform = new core_max_input_vars_form('max_input_vars.php',
Expand Down Expand Up @@ -220,8 +217,7 @@ public function definition() {
echo html_writer::start_tag('ul');
foreach (array('c' => 'Advanced checkboxes',
'a' => 'Select options') as $control => $controlname) {
foreach (array('s' => 'Small', 'm' => 'Below limit', 'e' => 'Exact PHP limit',
'l' => 'Above limit') as $size => $sizename) {
foreach (array('s' => 'Small', 'm' => 'Below limit', 'e' => 'Exact PHP limit') as $size => $sizename) {
echo html_writer::tag('li', html_writer::link('max_input_vars.php?type=' .
$control . $size, $controlname . ' / ' . $sizename));
}
Expand Down
24 changes: 24 additions & 0 deletions lib/upgradelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2624,3 +2624,27 @@ function check_libcurl_version(environment_results $result) {

return null;
}

/**
* Environment check for the php setting max_input_vars
*
* @param environment_results $result
* @return environment_results|null
*/
function check_max_input_vars(environment_results $result) {
$max = (int)ini_get('max_input_vars');
if ($max < 5000) {
$result->setInfo('max_input_vars');
$result->setStatus(false);
if (PHP_VERSION_ID >= 80000) {
// For PHP8 this check is required.
$result->setLevel('required');
$result->setFeedbackStr('settingmaxinputvarsrequired');
} else {
// For PHP7 this check is optional (recommended).
$result->setFeedbackStr('settingmaxinputvars');
}
return $result;
}
return null;
}

0 comments on commit d42fd64

Please sign in to comment.