Skip to content

Commit

Permalink
Merge branch 'moodle:main' into solrrag
Browse files Browse the repository at this point in the history
  • Loading branch information
mhughes2k authored Mar 26, 2024
2 parents 05d9fbc + c895def commit df9ecfa
Show file tree
Hide file tree
Showing 266 changed files with 8,578 additions and 2,606 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/.patches/
/.idea/
.phpstorm.*
!.phpstorm.meta.php
/nbproject/
CVS
.DS_Store
Expand Down
40 changes: 40 additions & 0 deletions .phpstorm.meta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Helper file for PhpStorm, and other IDEs, to provide better code completion.
*
* @package core
* @copyright 2024 Andrew Lyons <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace PHPSTORM_META;

// Assume that anything returned by \core\di::get('...') is an instance of the first argument.
override(\core\di::get(0), map([
'' => '@',
]));

// Assume that anything returned by \Psr\Container\ContainerInterface::get('...') is an instance of the first argument.
override(\Psr\Container\ContainerInterface::get(0), map([
'' => '@',
]));

// Assume that anything returned by \DI\Container::get('...') is an instance of the first argument.
override(\DI\Container::get(0), map([
'' => '@',
]));
2 changes: 1 addition & 1 deletion admin/tool/policy/tests/api_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function test_policy_document_life_cycle() {

// Prepare the form data for adding a new policy document.
$formdata = api::form_policydoc_data(new policy_version(0));
$this->assertObjectHasAttribute('name', $formdata);
$this->assertObjectHasProperty('name', $formdata);
$this->assertArrayHasKey('text', $formdata->summary_editor);
$this->assertArrayHasKey('format', $formdata->content_editor);

Expand Down
52 changes: 52 additions & 0 deletions admin/tool/uploadcourse/tests/behat/enrolments.feature
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,55 @@ Feature: An admin can update courses enrolments using a CSV file
Then I should see "Course updated"
And I am on the "Course 1" "enrolment methods" page
And I should not see "Guest access" in the "generaltable" "table"

@javascript
Scenario: Re-upload a file using CSV data only after deleting the enrolments method
Given I navigate to "Plugins > Enrolments > Manage enrol plugins" in site administration
And I click on "Enable" "link" in the "Course meta link" "table_row"
And the following "cohort" exists:
| name | Cohort1 |
| idnumber | Cohort1 |
And the following "category" exists:
| name | Cat 1 |
| category | 0 |
| idnumber | CAT1 |
And I navigate to "Courses > Upload courses" in site administration
And I upload "admin/tool/uploadcourse/tests/fixtures/enrolment_multiple.csv" file to "File" filemanager
And I click on "Preview" "button"
And I click on "Upload courses" "button"
And I am on the "Course 2" "enrolment methods" page
And I should see "Self enrolment (Student)" in the "generaltable" "table"
And I should see "Cohort sync (Cohort1 - Student)" in the "generaltable" "table"
And I should see "Guest access" in the "generaltable" "table"
And I should see "Manual enrolments" in the "generaltable" "table"
And I should see "Course meta link (Course 1)" in the "generaltable" "table"
And I navigate to "Courses > Upload courses" in site administration
# Delete all enrolment methods.
And I upload "admin/tool/uploadcourse/tests/fixtures/enrolment_multiple_delete.csv" file to "File" filemanager
And I set the field "Upload mode" to "Only update existing courses"
And I set the field "Update mode" to "Update with CSV data only"
And I set the field "Allow deletes" to "Yes"
And I click on "Preview" "button"
And I click on "Upload courses" "button"
And I should see "Course updated"
And I am on the "Course 2" "enrolment methods" page
And I should not see "Self enrolment (Student)" in the "generaltable" "table"
And I should not see "Cohort sync (Cohort1 - Student)" in the "generaltable" "table"
And I should not see "Guest access" in the "generaltable" "table"
And I should not see "Manual enrolments" in the "generaltable" "table"
And I should not see "Course meta link (Course 1)" in the "generaltable" "table"
# Re-upload again the CSV file, to add again the enrolment methods.
And I navigate to "Courses > Upload courses" in site administration
When I upload "admin/tool/uploadcourse/tests/fixtures/enrolment_multiple.csv" file to "File" filemanager
And I set the field "Upload mode" to "Only update existing courses"
And I set the field "Update mode" to "Update with CSV data only"
And I set the field "Allow deletes" to "Yes"
And I click on "Preview" "button"
And I click on "Upload courses" "button"
And I am on the "Course 2" "enrolment methods" page
Then I should see "Self enrolment (Student)" in the "generaltable" "table"
And I should see "Cohort sync (Cohort1 - Student)" in the "generaltable" "table"
And I should see "Guest access" in the "generaltable" "table"
And I should see "Manual enrolments" in the "generaltable" "table"
And I should see "Course meta link (Course 1)" in the "generaltable" "table"
And I navigate to "Courses > Upload courses" in site administration
2 changes: 2 additions & 0 deletions admin/tool/uploadcourse/tests/fixtures/enrolment_multiple.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shortname,fullname,category_idnumber,enrolment_1,enrolment_1_role,enrolment_2,enrolment_2_role,enrolment_2_cohortidnumber,enrolment_3,enrolment_4,enrolment_4_role,enrolment_5,enrolment_5_metacoursename
C2,Course 2,CAT1,self,student,cohort,student,Cohort1,guest,manual,student,meta,C1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
shortname,fullname,category_idnumber,enrolment_1,enrolment_1_delete,enrolment_2,enrolment_2_role,enrolment_2_cohortidnumber,enrolment_2_delete,enrolment_3,enrolment_3_delete,enrolment_4,enrolment_4_delete,enrolment_5,enrolment_5_metacoursename,enrolment_5_delete
C2,Course 2,CAT1,self,1,cohort,student,Cohort1,1,guest,1,manual,1,meta,C1,1
2 changes: 1 addition & 1 deletion admin/tool/uploaduser/tests/cli_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function test_upload_with_profile_fields() {
// Created users have data in the profile fields.
$user1 = \core_user::get_user_by_username('reznort');
$profilefields1 = profile_user_record($user1->id);
$this->assertObjectHasAttribute('superfield', $profilefields1);
$this->assertObjectHasProperty('superfield', $profilefields1);
$this->assertEquals('Loves cats', $profilefields1->superfield);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ function invoke() {
$comment = trim($comment);

$type = required_param('type', PARAM_INT);
$length = strtolower(optional_param('length', NULL, PARAM_ALPHANUM));
$length = optional_param('length', null, PARAM_INT);
$decimals = optional_param('decimals', NULL, PARAM_INT);
$notnull = optional_param('notnull', false, PARAM_BOOL);
$sequence = optional_param('sequence', false, PARAM_BOOL);
$default = optional_param('default', NULL, PARAM_PATH);
$default = trim($default);
$default = is_null($default) ? $default : trim($default);

$editeddir = $XMLDB->editeddirs[$dirpath];
$structure = $editeddir->xml_file->getStructure();
Expand Down
10 changes: 5 additions & 5 deletions auth/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public function test_export_user_preferences() {
$prefs = writer::with_context($sysctx)->get_user_preferences('core_auth');
$this->assertEquals(transform::yesno(false), $prefs->auth_forcepasswordchange->value);
$this->assertEquals(transform::yesno(false), $prefs->create_password->value);
$this->assertObjectNotHasAttribute('login_failed_count', $prefs);
$this->assertObjectNotHasAttribute('login_failed_count_since_success', $prefs);
$this->assertObjectNotHasAttribute('login_failed_last', $prefs);
$this->assertObjectNotHasAttribute('login_lockout', $prefs);
$this->assertObjectNotHasProperty('login_failed_count', $prefs);
$this->assertObjectNotHasProperty('login_failed_count_since_success', $prefs);
$this->assertObjectNotHasProperty('login_failed_last', $prefs);
$this->assertObjectNotHasProperty('login_lockout', $prefs);
$this->assertEquals(transform::yesno(true), $prefs->login_lockout_ignored->value);
$this->assertObjectNotHasAttribute('login_lockout_secret', $prefs);
$this->assertObjectNotHasProperty('login_lockout_secret', $prefs);
}
}
4 changes: 2 additions & 2 deletions badges/tests/badgeslib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ public function test_badge_awards() {
$message = array_pop($messages);
// Check we have the expected data.
$customdata = json_decode($message->customdata);
$this->assertObjectHasAttribute('notificationiconurl', $customdata);
$this->assertObjectHasAttribute('hash', $customdata);
$this->assertObjectHasProperty('notificationiconurl', $customdata);
$this->assertObjectHasProperty('hash', $customdata);

$user2 = $this->getDataGenerator()->create_user();
$badge->issue($user2->id, true);
Expand Down
4 changes: 2 additions & 2 deletions blocks/tests/privacy/provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,12 @@ public function test_export_data_for_user() {
$this->assertEquals($yes, $prefs->block_is_hidden->value);

$prefs = writer::with_context($bprivatefiles->context)->get_user_context_preferences('core_block');
$this->assertObjectNotHasAttribute('block_is_docked', $prefs);
$this->assertObjectNotHasProperty('block_is_docked', $prefs);
$this->assertEquals($no, $prefs->block_is_hidden->value);

$prefs = writer::with_context($bmyprofile->context)->get_user_context_preferences('core_block');
$this->assertEquals($yes, $prefs->block_is_docked->value);
$this->assertObjectNotHasAttribute('block_is_hidden', $prefs);
$this->assertObjectNotHasProperty('block_is_hidden', $prefs);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions cache/classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,4 +873,13 @@ public static function warnings(array $stores = null) {
public static function result_found($value): bool {
return $value !== false;
}

/**
* Checks whether the cluster mode is available in PHP.
*
* @return bool Return true if the PHP supports redis cluster, otherwise false.
*/
public static function is_cluster_available(): bool {
return class_exists('RedisCluster');
}
}
9 changes: 7 additions & 2 deletions cache/stores/redis/addinstanceform.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot.'/cache/forms.php');
require_once($CFG->dirroot . '/cache/forms.php');

/**
* Form for adding instance of Redis Cache Store.
Expand All @@ -39,7 +39,12 @@ class cachestore_redis_addinstance_form extends cachestore_addinstance_form {
protected function configuration_definition() {
$form = $this->_form;

$form->addElement('text', 'server', get_string('server', 'cachestore_redis'), array('size' => 24));
$form->addElement('advcheckbox', 'clustermode', get_string('clustermode', 'cachestore_redis'), '',
cache_helper::is_cluster_available() ? '' : 'disabled');
$form->addHelpButton('clustermode', 'clustermode', 'cachestore_redis');
$form->setType('clustermode', PARAM_BOOL);

$form->addElement('textarea', 'server', get_string('server', 'cachestore_redis'), ['cols' => 6, 'rows' => 10]);
$form->setType('server', PARAM_TEXT);
$form->addHelpButton('server', 'server', 'cachestore_redis');
$form->addRule('server', get_string('required'), 'required');
Expand Down
42 changes: 28 additions & 14 deletions cache/stores/redis/lang/en/cachestore_redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@

defined('MOODLE_INTERNAL') || die();

$string['ca_file'] = 'CA file path';
$string['ca_file_help'] = 'Location of Certificate Authority file on local filesystem';
$string['clustermode'] = 'Cluster Mode';
$string['clustermode_help'] = 'Enabling it will run the Redis cluster function, allowing your server to serve multiple servers to handle concurrent requests simultaneously.';
$string['clustermodeunavailable'] = 'Redis Cluster is currently unavailable. Please ensure that the PHP Redis extension supports Redis Cluster functionality.';
$string['compressor_none'] = 'No compression.';
$string['compressor_php_gzip'] = 'Use gzip compression.';
$string['compressor_php_zstd'] = 'Use Zstandard compression.';
$string['encrypt_connection'] = 'Use TLS encryption.';
$string['encrypt_connection_help'] = 'Use TLS to connect to Redis. Do not use \'tls://\' in the hostname for Redis, use this option instead.';
$string['ca_file'] = 'CA file path';
$string['ca_file_help'] = 'Location of Certificate Authority file on local filesystem';
$string['password'] = 'Password';
$string['password_help'] = 'This sets the password of the Redis server.';
$string['pluginname'] = 'Redis';
$string['prefix'] = 'Key prefix';
$string['prefix_help'] = 'This prefix is used for all key names on the Redis server.
Expand All @@ -41,8 +46,8 @@
$string['privacy:metadata:redis:data'] = 'The various data stored in the cache';
$string['serializer_igbinary'] = 'The igbinary serializer.';
$string['serializer_php'] = 'The default PHP serializer.';
$string['server'] = 'Server';
$string['server_help'] = 'This sets the hostname, IP address or Unix socket path of the Redis server to use.
$string['server'] = 'Server(s)';
$string['server_help'] = 'Redis server to use for testing.
Some example values:
Expand All @@ -52,12 +57,20 @@
* 1.2.3.4:1234 - To connect to a Redis server by IP address with a specific port.
* unix:///var/redis.sock - To connect to a Redis server using a Unix socket.
* /var/redis.sock - To connect to a Redis server using a Unix socket (alternative format).
* If cluster mode is enabled, please specify servers separated by a new line:<br>
172.23.0.11<br>
172.23.0.12<br>
172.23.0.13<br>
Refer to the above examples to write a server.
See <a href="https://redis.io/docs/reference/clients/#accepting-client-connections" target="_new">Accepting Client Connections</a> and <a href="https://redis.io/resources/clients/#php" target="_new">Redis PHP clients</a> for more information.
';
$string['password'] = 'Password';
$string['password_help'] = 'This sets the password of the Redis server.';
See <a href="https://redis.io/docs/reference/clients/#accepting-client-connections" target="_new">Accepting Client Connections</a> and <a href="https://redis.io/resources/clients/#php" target="_new">Redis PHP clients</a> for more information.';
$string['task_ttl'] = 'Free up memory used by expired entries in Redis caches';
$string['test_clustermode'] = 'Cluster Mode';
$string['test_clustermode_desc'] = 'Enable Test in Redis cluster mode.';
$string['test_password'] = 'Test server password';
$string['test_password_desc'] = 'Redis test server password.';
$string['test_serializer'] = 'Serializer';
$string['test_serializer_desc'] = 'Serializer to use for testing.';
$string['test_server'] = 'Test server';
$string['test_server_desc'] = 'Redis server to use for testing.
Expand All @@ -69,17 +82,18 @@
* 1.2.3.4:1234 - To connect to a Redis server by IP address with a specific port.
* unix:///var/redis.sock - To connect to a Redis server using a Unix socket.
* /var/redis.sock - To connect to a Redis server using a Unix socket (alternative format).
* If cluster mode is enabled, please specify servers separated by a new line:<br>
172.23.0.11<br>
172.23.0.12<br>
172.23.0.13<br>
Refer to the above examples to write a server.
See <a href="https://redis.io/docs/reference/clients/#accepting-client-connections" target="_new">Accepting Client Connections</a> and <a href="https://redis.io/resources/clients/#php" target="_new">Redis PHP clients</a> for more information.';
$string['test_password'] = 'Test server password';
$string['test_password_desc'] = 'Redis test server password.';
$string['test_serializer'] = 'Serializer';
$string['test_serializer_desc'] = 'Serializer to use for testing.';
$string['test_ttl'] = 'Testing TTL';
$string['test_ttl_desc'] = 'Run the performance test using a cache that requires TTL (slower sets).';
$string['usecompressor'] = 'Use compressor';
$string['usecompressor_help'] = 'Specifies the compressor to use after serializing. It is done at Moodle Cache API level, not at php-redis level.';
$string['useserializer'] = 'Use serializer';
$string['useserializer_help'] = 'Specifies the serializer to use for serializing.
The valid serializers are Redis::SERIALIZER_PHP or Redis::SERIALIZER_IGBINARY.
The latter is supported only when phpredis is configured with --enable-redis-igbinary option and the igbinary extension is loaded.';
$string['usecompressor'] = 'Use compressor';
$string['usecompressor_help'] = 'Specifies the compressor to use after serializing. It is done at Moodle Cache API level, not at php-redis level.';
Loading

0 comments on commit df9ecfa

Please sign in to comment.