mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
Merge branch 'MDL-73953-master' of https://github.com/aanabit/moodle
This commit is contained in:
commit
facf5cbcd0
@ -32,7 +32,7 @@ class helper {
|
||||
* - name. To define the preset name.
|
||||
* - comments. To change the comments field.
|
||||
* - author. To update the author field.
|
||||
* - iscore. Whether the preset is a core preset or not.
|
||||
* - iscore. Whether the preset is a core preset or not. Valid values on \core_adminpresets\manager class.
|
||||
* @return int The identifier of the preset created.
|
||||
*/
|
||||
public static function create_preset(array $data): int {
|
||||
@ -41,7 +41,13 @@ class helper {
|
||||
$name = array_key_exists('name', $data) ? $data['name'] : '';
|
||||
$comments = array_key_exists('comments', $data) ? $data['comments'] : '';
|
||||
$author = array_key_exists('author', $data) ? $data['author'] : fullname($USER);
|
||||
$iscore = array_key_exists('iscore', $data) ? $data['iscore'] : 0;
|
||||
$iscore = array_key_exists('iscore', $data) ? $data['iscore'] : manager::NONCORE_PRESET;
|
||||
|
||||
// Validate iscore value.
|
||||
$allowed = [manager::NONCORE_PRESET, manager::STARTER_PRESET, manager::FULL_PRESET];
|
||||
if (!in_array($iscore, $allowed)) {
|
||||
$iscore = manager::NONCORE_PRESET;
|
||||
}
|
||||
|
||||
$preset = [
|
||||
'userid' => $USER->id,
|
||||
@ -168,7 +174,7 @@ class helper {
|
||||
$data = [
|
||||
'name' => get_string('starterpreset', 'core_adminpresets'),
|
||||
'comments' => get_string('starterpresetdescription', 'core_adminpresets'),
|
||||
'iscore' => 1,
|
||||
'iscore' => manager::STARTER_PRESET,
|
||||
];
|
||||
$presetid = static::create_preset($data);
|
||||
|
||||
@ -279,7 +285,7 @@ class helper {
|
||||
$data = [
|
||||
'name' => get_string('fullpreset', 'core_adminpresets'),
|
||||
'comments' => get_string('fullpresetdescription', 'core_adminpresets'),
|
||||
'iscore' => 1,
|
||||
'iscore' => manager::FULL_PRESET,
|
||||
];
|
||||
$presetid = static::create_preset($data);
|
||||
|
||||
|
@ -124,6 +124,15 @@ class manager {
|
||||
'moodlerelease' => 'MOODLE_RELEASE'
|
||||
];
|
||||
|
||||
/** @var int Non-core preset */
|
||||
public const NONCORE_PRESET = 0;
|
||||
|
||||
/** @var int Starter preset */
|
||||
public const STARTER_PRESET = 1;
|
||||
|
||||
/** @var int Full preset */
|
||||
public const FULL_PRESET = 2;
|
||||
|
||||
/**
|
||||
* Gets the system settings
|
||||
*
|
||||
|
@ -64,6 +64,14 @@ class core_adminpresets_generator extends \component_generator_base {
|
||||
if (!isset($data['author'])) {
|
||||
$data['author'] = 'Default author';
|
||||
}
|
||||
if (!isset($data['iscore'])) {
|
||||
$data['iscore'] = manager::NONCORE_PRESET;
|
||||
}
|
||||
// Validate iscore value.
|
||||
$allowed = [manager::NONCORE_PRESET, manager::STARTER_PRESET, manager::FULL_PRESET];
|
||||
if (!in_array($data['iscore'], $allowed)) {
|
||||
$data['iscore'] = manager::NONCORE_PRESET;
|
||||
}
|
||||
|
||||
$preset = [
|
||||
'userid' => $USER->id,
|
||||
@ -75,6 +83,7 @@ class core_adminpresets_generator extends \component_generator_base {
|
||||
'moodlerelease' => $CFG->release,
|
||||
'timecreated' => time(),
|
||||
'timeimported' => 0,
|
||||
'iscore' => $data['iscore'],
|
||||
];
|
||||
|
||||
$presetid = $DB->insert_record('adminpresets', $preset);
|
||||
|
@ -37,9 +37,11 @@ class generator_test extends \advanced_testcase {
|
||||
* @param string|null $comments Preset comments field.
|
||||
* @param string|null $author Preset author field.
|
||||
* @param bool $applypreset Whether the preset should be applied or not.
|
||||
* @param int|null $iscore Whether the preset is a core preset or not.
|
||||
* @param int|null $iscoreresult Expected iscore value for the result preset.
|
||||
*/
|
||||
public function test_create_preset(?string $name = null, ?string $comments = null, ?string $author = null,
|
||||
bool $applypreset = false): void {
|
||||
bool $applypreset = false, ?int $iscore = null, ?int $iscoreresult = null): void {
|
||||
global $CFG, $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
@ -66,6 +68,12 @@ class generator_test extends \advanced_testcase {
|
||||
if ($applypreset) {
|
||||
$data['applypreset'] = $applypreset;
|
||||
}
|
||||
if (isset($iscore)) {
|
||||
$data['iscore'] = $iscore;
|
||||
}
|
||||
if (!isset($iscoreresult)) {
|
||||
$iscoreresult = manager::NONCORE_PRESET;
|
||||
}
|
||||
|
||||
// Create a preset.
|
||||
$presetid = $this->getDataGenerator()->get_plugin_generator('core_adminpresets')->create_preset($data);
|
||||
@ -76,6 +84,7 @@ class generator_test extends \advanced_testcase {
|
||||
$this->assertEquals($name, $preset->name);
|
||||
$this->assertEquals($comments, $preset->comments);
|
||||
$this->assertEquals($author, $preset->author);
|
||||
$this->assertEquals($iscoreresult, $preset->iscore);
|
||||
$this->assertEquals($CFG->version, $preset->moodleversion);
|
||||
$this->assertEquals($CFG->release, $preset->moodlerelease);
|
||||
$this->assertEquals($CFG->wwwroot, $preset->site);
|
||||
@ -197,7 +206,31 @@ class generator_test extends \advanced_testcase {
|
||||
'comments' => null,
|
||||
'author' => null,
|
||||
'applypreset' => true,
|
||||
]
|
||||
],
|
||||
'Starter preset' => [
|
||||
'name' => 'Starter',
|
||||
'comments' => null,
|
||||
'author' => null,
|
||||
'applypreset' => false,
|
||||
'iscore' => manager::STARTER_PRESET,
|
||||
'iscoreresult' => manager::STARTER_PRESET,
|
||||
],
|
||||
'Full preset' => [
|
||||
'name' => 'Full',
|
||||
'comments' => null,
|
||||
'author' => null,
|
||||
'applypreset' => false,
|
||||
'iscore' => manager::FULL_PRESET,
|
||||
'iscoreresult' => manager::FULL_PRESET,
|
||||
],
|
||||
'Invalid iscore' => [
|
||||
'name' => 'Invalid iscore value',
|
||||
'comments' => null,
|
||||
'author' => null,
|
||||
'applypreset' => false,
|
||||
'iscore' => -1,
|
||||
'iscoreresult' => manager::NONCORE_PRESET,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,11 @@ class helper_test extends \advanced_testcase {
|
||||
*
|
||||
* @param string|null $name Preset name field.
|
||||
* @param string|null $comments Preset comments field.
|
||||
* @param int|null $iscore Preset iscore field.
|
||||
* @param int|null $iscoreresult Expected iscore value for the result preset.
|
||||
*/
|
||||
public function test_create_preset(?string $name = null, ?string $comments = null): void {
|
||||
public function test_create_preset(?string $name = null, ?string $comments = null, ?int $iscore = null,
|
||||
?int $iscoreresult = null): void {
|
||||
global $CFG, $DB, $USER;
|
||||
|
||||
$this->resetAfterTest();
|
||||
@ -48,6 +51,12 @@ class helper_test extends \advanced_testcase {
|
||||
if (isset($comments)) {
|
||||
$data['comments'] = $comments;
|
||||
}
|
||||
if (isset($iscore)) {
|
||||
$data['iscore'] = $iscore;
|
||||
}
|
||||
if (!isset($iscoreresult)) {
|
||||
$iscoreresult = manager::NONCORE_PRESET;
|
||||
}
|
||||
|
||||
// Create a preset.
|
||||
$presetid = helper::create_preset($data);
|
||||
@ -58,6 +67,7 @@ class helper_test extends \advanced_testcase {
|
||||
$this->assertEquals($name, $preset->name);
|
||||
$this->assertEquals($comments, $preset->comments);
|
||||
$this->assertEquals(fullname($USER), $preset->author);
|
||||
$this->assertEquals($iscoreresult, $preset->iscore);
|
||||
$this->assertEquals($CFG->version, $preset->moodleversion);
|
||||
$this->assertEquals($CFG->release, $preset->moodlerelease);
|
||||
$this->assertEquals($CFG->wwwroot, $preset->site);
|
||||
@ -89,6 +99,24 @@ class helper_test extends \advanced_testcase {
|
||||
'name' => 'Preset with a super-nice name',
|
||||
'comments' => 'This is a comment different from the previous one',
|
||||
],
|
||||
'Starter preset' => [
|
||||
'name' => 'Starter',
|
||||
'comments' => null,
|
||||
'iscore' => manager::STARTER_PRESET,
|
||||
'iscoreresult' => manager::STARTER_PRESET,
|
||||
],
|
||||
'Full preset' => [
|
||||
'name' => 'Full',
|
||||
'comments' => null,
|
||||
'iscore' => manager::FULL_PRESET,
|
||||
'iscoreresult' => manager::FULL_PRESET,
|
||||
],
|
||||
'Invalid iscore' => [
|
||||
'name' => 'Invalid iscore value',
|
||||
'comments' => null,
|
||||
'iscore' => -1,
|
||||
'iscoreresult' => manager::NONCORE_PRESET,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ class manager_test extends \advanced_testcase {
|
||||
$this->assertArrayHasKey($presetid, $presets);
|
||||
$preset = $presets[$presetid];
|
||||
$this->assertEquals($presetname, $preset->name);
|
||||
$this->assertEquals(0, $preset->iscore);
|
||||
$this->assertEquals(manager::NONCORE_PRESET, $preset->iscore);
|
||||
|
||||
// Check the preset includes settings and plugins.
|
||||
$this->assertTrue($settingsfound);
|
||||
@ -448,7 +448,7 @@ class manager_test extends \advanced_testcase {
|
||||
$this->assertEquals($expectedpresetname, $preset->name);
|
||||
$this->assertEquals('http://demo.moodle', $preset->site);
|
||||
$this->assertEquals('Ada Lovelace', $preset->author);
|
||||
$this->assertEquals(0, $preset->iscore);
|
||||
$this->assertEquals(manager::NONCORE_PRESET, $preset->iscore);
|
||||
|
||||
if ($expectedsettings) {
|
||||
// Check the items have been created.
|
||||
|
@ -23,6 +23,7 @@
|
||||
*/
|
||||
namespace tool_admin_presets\output;
|
||||
|
||||
use core_adminpresets\manager;
|
||||
use renderable;
|
||||
use templatable;
|
||||
use renderer_base;
|
||||
@ -105,7 +106,7 @@ class presets_list implements renderable, templatable {
|
||||
));
|
||||
|
||||
// Delete button won't be displayed for the pre-installed core "Starter" and "Full" presets.
|
||||
if (!$preset->iscore) {
|
||||
if ($preset->iscore == manager::NONCORE_PRESET) {
|
||||
$deletelink = new \moodle_url('/admin/tool/admin_presets/index.php',
|
||||
['action' => 'delete', 'id' => $preset->id]
|
||||
);
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
namespace tool_admin_presets\local\action;
|
||||
|
||||
use core_adminpresets\manager;
|
||||
|
||||
/**
|
||||
* Tests for the export class.
|
||||
*
|
||||
@ -86,7 +88,7 @@ class export_test extends \advanced_testcase {
|
||||
$this->assertArrayHasKey($presetid, $presets);
|
||||
$preset = $presets[$presetid];
|
||||
$this->assertEquals($presetname, $preset->name);
|
||||
$this->assertEquals(0, $preset->iscore);
|
||||
$this->assertEquals(manager::NONCORE_PRESET, $preset->iscore);
|
||||
|
||||
// Check the items, advanced attributes and plugins have been created.
|
||||
$this->assertGreaterThan(0, $DB->count_records('adminpresets_it', ['adminpresetid' => $presetid]));
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
namespace tool_admin_presets\local\action;
|
||||
|
||||
use core_adminpresets\manager;
|
||||
|
||||
/**
|
||||
* Tests for the import class.
|
||||
*
|
||||
@ -104,7 +106,7 @@ class import_test extends \advanced_testcase {
|
||||
$this->assertEquals($expectedpresetname, $preset->name);
|
||||
$this->assertEquals('http://demo.moodle', $preset->site);
|
||||
$this->assertEquals('Ada Lovelace', $preset->author);
|
||||
$this->assertEquals(0, $preset->iscore);
|
||||
$this->assertEquals(manager::NONCORE_PRESET, $preset->iscore);
|
||||
|
||||
if ($expectedsettings) {
|
||||
// Check the items have been created.
|
||||
|
@ -4563,7 +4563,7 @@
|
||||
<FIELD NAME="author" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
|
||||
<FIELD NAME="moodleversion" TYPE="char" LENGTH="20" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="moodlerelease" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="iscore" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Whether this is a core preset or not"/>
|
||||
<FIELD NAME="iscore" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Whether this is a core preset or not, and which core preset"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
<FIELD NAME="timeimported" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
|
||||
</FIELDS>
|
||||
|
@ -3544,6 +3544,22 @@ privatefiles,moodle|/user/files.php';
|
||||
$params = ['name' => get_string('fullpreset', 'core_adminpresets'), 'iscore' => 1];
|
||||
$fullpreset = $DB->get_record('adminpresets', $params);
|
||||
|
||||
if (!$fullpreset) {
|
||||
// Full admin preset might have been created using the English name.
|
||||
$name = get_string_manager()->get_string('fullpreset', 'core_adminpresets', null, 'en');
|
||||
$params['name'] = $name;
|
||||
$fullpreset = $DB->get_record('adminpresets', $params);
|
||||
}
|
||||
if (!$fullpreset) {
|
||||
// We tried, but we didn't find full by name. Let's find a core preset that sets 'usecomments' setting to 1.
|
||||
$sql = "SELECT preset.*
|
||||
FROM {adminpresets} preset
|
||||
INNER JOIN {adminpresets_it} it ON preset.id = it.adminpresetid
|
||||
WHERE it.name = :name AND it.value = :value AND preset.iscore = 1";
|
||||
$params = ['name' => 'usecomments', 'value' => '1'];
|
||||
$fullpreset = $DB->get_record_sql($sql, $params);
|
||||
}
|
||||
|
||||
if ($fullpreset) {
|
||||
$blocknames = ['course_summary', 'feedback', 'rss_client', 'selfcompletion'];
|
||||
list($blocksinsql, $blocksinparams) = $DB->get_in_or_equal($blocknames);
|
||||
@ -3964,12 +3980,39 @@ privatefiles,moodle|/user/files.php';
|
||||
}
|
||||
|
||||
if ($oldversion < 2022021100.01) {
|
||||
$sql = "SELECT preset.*
|
||||
FROM {adminpresets} preset
|
||||
INNER JOIN {adminpresets_it} it ON preset.id = it.adminpresetid
|
||||
WHERE it.name = :name AND it.value = :value AND preset.iscore = 1";
|
||||
// Some settings and plugins have been added/removed to the Starter and Full preset. Add them to the core presets if
|
||||
// they haven't been included yet.
|
||||
$params = ['name' => get_string('starterpreset', 'core_adminpresets'), 'iscore' => 1];
|
||||
$starterpreset = $DB->get_record('adminpresets', $params);
|
||||
if (!$starterpreset) {
|
||||
// Starter admin preset might have been created using the English name.
|
||||
$name = get_string_manager()->get_string('starterpreset', 'core_adminpresets', null, 'en');
|
||||
$params['name'] = $name;
|
||||
$starterpreset = $DB->get_record('adminpresets', $params);
|
||||
}
|
||||
if (!$starterpreset) {
|
||||
// We tried, but we didn't find starter by name. Let's find a core preset that sets 'usecomments' setting to 0.
|
||||
$params = ['name' => 'usecomments', 'value' => '0'];
|
||||
$starterpreset = $DB->get_record_sql($sql, $params);
|
||||
}
|
||||
|
||||
$params = ['name' => get_string('fullpreset', 'core_adminpresets'), 'iscore' => 1];
|
||||
$fullpreset = $DB->get_record('adminpresets', $params);
|
||||
if (!$fullpreset) {
|
||||
// Full admin preset might have been created using the English name.
|
||||
$name = get_string_manager()->get_string('fullpreset', 'core_adminpresets', null, 'en');
|
||||
$params['name'] = $name;
|
||||
$fullpreset = $DB->get_record('adminpresets', $params);
|
||||
}
|
||||
if (!$fullpreset) {
|
||||
// We tried, but we didn't find full by name. Let's find a core preset that sets 'usecomments' setting to 1.
|
||||
$params = ['name' => 'usecomments', 'value' => '1'];
|
||||
$fullpreset = $DB->get_record_sql($sql, $params);
|
||||
}
|
||||
|
||||
$settings = [
|
||||
// Settings. Hide Guest login button for Starter preset (and back to show for Full).
|
||||
@ -4130,5 +4173,78 @@ privatefiles,moodle|/user/files.php';
|
||||
upgrade_main_savepoint(true, 2022022600.01);
|
||||
}
|
||||
|
||||
if ($oldversion < 2022030100.00) {
|
||||
$sql = "SELECT preset.*
|
||||
FROM {adminpresets} preset
|
||||
INNER JOIN {adminpresets_it} it ON preset.id = it.adminpresetid
|
||||
WHERE it.name = :name AND it.value = :value AND preset.iscore = 1";
|
||||
|
||||
$name = get_string('starterpreset', 'core_adminpresets');
|
||||
$params = ['name' => $name, 'iscore' => 1];
|
||||
$starterpreset = $DB->get_record('adminpresets', $params);
|
||||
if (!$starterpreset) {
|
||||
// Starter admin preset might have been created using the English name. Let's change it to current language.
|
||||
$englishname = get_string_manager()->get_string('starterpreset', 'core_adminpresets', null, 'en');
|
||||
$params['name'] = $englishname;
|
||||
$starterpreset = $DB->get_record('adminpresets', $params);
|
||||
}
|
||||
if (!$starterpreset) {
|
||||
// We tried, but we didn't find starter by name. Let's find a core preset that sets 'usecomments' setting to 0.
|
||||
$params = ['name' => 'usecomments', 'value' => '0'];
|
||||
$starterpreset = $DB->get_record_sql($sql, $params);
|
||||
}
|
||||
// The iscore field is already 1 for starterpreset, so we don't need to change it.
|
||||
// We only need to update the name and comment in case they are different to current language strings.
|
||||
if ($starterpreset && $starterpreset->name != $name) {
|
||||
$starterpreset->name = $name;
|
||||
$starterpreset->comments = get_string('starterpresetdescription', 'core_adminpresets');
|
||||
$DB->update_record('adminpresets', $starterpreset);
|
||||
}
|
||||
|
||||
// Let's mark Full admin presets with current FULL_PRESETS value and change the name to current language.
|
||||
$name = get_string('fullpreset', 'core_adminpresets');
|
||||
$params = ['name' => $name, 'iscore' => 1];
|
||||
$fullpreset = $DB->get_record('adminpresets', $params);
|
||||
if (!$fullpreset) {
|
||||
// Full admin preset might have been created using the English name.
|
||||
$englishname = get_string_manager()->get_string('fullpreset', 'core_adminpresets', null, 'en');
|
||||
$params['name'] = $englishname;
|
||||
$fullpreset = $DB->get_record('adminpresets', $params);
|
||||
}
|
||||
if (!$fullpreset) {
|
||||
// We tried, but we didn't find full by name. Let's find a core preset that sets 'usecomments' setting to 1.
|
||||
$params = ['name' => 'usecomments', 'value' => '1'];
|
||||
$fullpreset = $DB->get_record_sql($sql, $params);
|
||||
}
|
||||
if ($fullpreset) {
|
||||
// We need to update iscore field value, whether the name is the same or not.
|
||||
$fullpreset->name = $name;
|
||||
$fullpreset->comments = get_string('fullpresetdescription', 'core_adminpresets');
|
||||
$fullpreset->iscore = 2;
|
||||
$DB->update_record('adminpresets', $fullpreset);
|
||||
|
||||
// We are applying again changes made on 2022011100.01 upgrading step because of MDL-73953 bug.
|
||||
$blocknames = ['course_summary', 'feedback', 'rss_client', 'selfcompletion'];
|
||||
list($blocksinsql, $blocksinparams) = $DB->get_in_or_equal($blocknames);
|
||||
|
||||
// Remove entries from the adminpresets_app_plug table (in case the preset has been applied).
|
||||
$appliedpresets = $DB->get_records('adminpresets_app', ['adminpresetid' => $fullpreset->id], '', 'id');
|
||||
if ($appliedpresets) {
|
||||
list($appsinsql, $appsinparams) = $DB->get_in_or_equal(array_keys($appliedpresets));
|
||||
$sql = "adminpresetapplyid $appsinsql AND plugin='block' AND name $blocksinsql";
|
||||
$params = array_merge($appsinparams, $blocksinparams);
|
||||
$DB->delete_records_select('adminpresets_app_plug', $sql, $params);
|
||||
}
|
||||
|
||||
// Remove entries for these blocks from the adminpresets_plug table.
|
||||
$sql = "adminpresetid = ? AND plugin='block' AND name $blocksinsql";
|
||||
$params = array_merge([$fullpreset->id], $blocksinparams);
|
||||
$DB->delete_records_select('adminpresets_plug', $sql, $params);
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2022030100.00);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$version = 2022022600.01; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
$version = 2022030100.00; // YYYYMMDD = weekly release date of this DEV branch.
|
||||
// RR = release increments - 00 in DEV branches.
|
||||
// .XX = incremental changes.
|
||||
$release = '4.0dev+ (Build: 20220226)'; // Human-friendly version name
|
||||
|
Loading…
x
Reference in New Issue
Block a user