Skip to content

Commit b6bb4ef

Browse files
authored
Merge pull request #114 from catalyst/113-userlist-regression-fix
Issue #113: Fix regression caused by previous commit.
2 parents 8e84276 + f867555 commit b6bb4ef

File tree

7 files changed

+51
-20
lines changed

7 files changed

+51
-20
lines changed

classes/local/datasource/base.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public function get_config_cache_key(): ?string {
388388
// By default, all stored configs are expected to have a stored hash to be used as a key. If one is not stored, then an
389389
// exception will be thrown.
390390
// If a datasource doesn't use caching (either returning '' or null), then this method should be overridden.
391-
$key = $cmstype->get_custom_data(self::get_shortname() . 'confighash');
391+
$key = $cmstype->get_custom_data(static::get_shortname() . 'confighash');
392392
// We expect there to be something, so false, null, '', and 0 are all illigit.
393393
if (empty($key)) {
394394
throw new \moodle_exception('error:no_config_hash', 'mod_cms', '', $this->cms->get('id'));
@@ -405,7 +405,7 @@ public function update_config_cache_key() {
405405
$hash = hash(lib::HASH_ALGO, serialize($this->get_for_export()));
406406
// The config hash is stored with the CMS type.
407407
$cmstype = $this->cms->get_type();
408-
$cmstype->set_custom_data(self::get_shortname() . 'confighash', $hash);
408+
$cmstype->set_custom_data(static::get_shortname() . 'confighash', $hash);
409409
$cmstype->save();
410410
}
411411

classes/local/datasource/userlist.php

-9
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ class userlist extends base_mod_cms {
5050
/** @var cmsuserlist_handler Custom field handler. */
5151
protected $cfhandler;
5252

53-
/**
54-
* The short name of the datasource type. Must be unique.
55-
*
56-
* @return string
57-
*/
58-
public static function get_shortname(): string {
59-
return 'list';
60-
}
61-
6253
/**
6354
* Get the display name.
6455
*

db/upgrade.php

+42
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,47 @@ function xmldb_cms_upgrade($oldversion) {
299299
upgrade_mod_savepoint(true, 2023111500, 'cms');
300300
}
301301

302+
if ($oldversion < 2023112100) {
303+
// Update CMS types settings to upgrade list to userlist.
304+
$like = $DB->sql_like('datasources', ':list');
305+
$records = cms_types::get_records_select($like, ['list' => '%list%']);
306+
foreach ($records as $record) {
307+
$datasources = $record->get('datasources');
308+
// Remove list.
309+
$datasources = array_filter($datasources, function ($i) {
310+
return $i !== 'list';
311+
});
312+
// Add userlist.
313+
$datasources[] = 'userlist';
314+
$record->set('datasources', $datasources);
315+
// Convert config hash name.
316+
$hash = $record->get_custom_data('listconfighash');
317+
if ($hash !== null) {
318+
$record->set_custom_data('listconfighash', null);
319+
$record->set_custom_data('userlistconfighash', $hash);
320+
}
321+
$record->save();
322+
}
323+
324+
// Update CMS instances.
325+
$like = $DB->sql_like('datasources', ':userlist');
326+
$cmstypeids = $DB->get_records_select_menu('cms_types', $like, ['userlist' => '%userlist%'], '', 'id,name');
327+
if (count($cmstypeids) !== 0) {
328+
[$insql, $inparams] = $DB->get_in_or_equal(array_keys($cmstypeids));
329+
$records = cms::get_records_select("typeid $insql", $inparams);
330+
foreach ($records as $record) {
331+
// Convert config hash name.
332+
$hash = $record->get_custom_data('listinstancehash');
333+
if ($hash !== null) {
334+
$record->set_custom_data('listinstancehash', null);
335+
$record->set_custom_data('userlistinstancehash', $hash);
336+
$record->save();
337+
}
338+
}
339+
}
340+
341+
upgrade_mod_savepoint(true, 2023112100, 'cms');
342+
}
343+
302344
return true;
303345
}

tests/datasource_userlist_test.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function setUp(): void {
5050
* @covers \mod_cms\local\datasource\userlist::get_shortname
5151
*/
5252
public function test_name() {
53-
$this->assertEquals('list', dsuserlist::get_shortname());
53+
$this->assertEquals('userlist', dsuserlist::get_shortname());
5454
}
5555

5656
/**
@@ -91,7 +91,7 @@ public function test_import() {
9191
$cmstype = $manager->create((object) [
9292
'name' => 'name',
9393
'idnumber' => 'test-name',
94-
'datasources' => 'list',
94+
'datasources' => 'userlist',
9595
]);
9696

9797
$cms = $cmstype->get_sample_cms();
@@ -150,7 +150,7 @@ public function test_config_delete() {
150150
global $DB;
151151

152152
$manager = new manage_content_types();
153-
$cmstype = $manager->create((object) ['name' => 'Name', 'idnumber' => 'test-name', 'datasources' => 'list']);
153+
$cmstype = $manager->create((object) ['name' => 'Name', 'idnumber' => 'test-name', 'datasources' => 'userlist']);
154154

155155
// Test that stuff gets deleted even if not included in datasource list.
156156
$cmstype->set('datasources', []);
@@ -207,7 +207,6 @@ public function test_instance_delete() {
207207
*/
208208
public function test_instance_form_validataion() {
209209
$cmstype = $this->import();
210-
$cmstype->set('datasources', ['userlist']);
211210
$cmstype->save();
212211

213212
$cms = new cms();
@@ -236,7 +235,6 @@ public function test_instance_form_validataion() {
236235
*/
237236
public function test_update_instance() {
238237
$cmstype = $this->import();
239-
$cmstype->set('datasources', ['userlist']);
240238
$cmstype->save();
241239

242240
$cms = new cms();

tests/fixtures/test_import_1.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mustache: ''
77
datasources:
88
- fields
99
- images
10-
- list
10+
- userlist
1111
datasourcedefs:
1212
fields:
1313
categories:
@@ -29,7 +29,7 @@ datasourcedefs:
2929
filesize: '196'
3030
mimetype: image/png
3131
content: iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAAXNSR0IArs4c6QAAAH5JREFUKFOFz6ENwmAQhuGnCYIBcAzAAiWwAoqEiqZLYElFJYJRMCxQA0EicYyAQpEKBLmk4k9Dwrm7732T7zJ/JkvyAk9cUyeAMQ5444y4rfDBPpY1lqh7s8EDc9wC2GCB3aDOFqMApr39wh0XzFDhmJYskWOCDi1OKfDz4S/mihIlTY5RLwAAAABJRU5ErkJggg==
32-
list:
32+
userlist:
3333
columns:
3434
-
3535
name: Name

tests/renderer_test.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function test_get_data() {
5353
$cmstype = $manager->create((object) [
5454
'name' => 'somename',
5555
'idnumber' => 'test-somename',
56-
'datasources' => 'fields,images,roles,list',
56+
'datasources' => 'fields,images,roles,userlist',
5757
]);
5858

5959
$cms = $cmstype->get_sample_cms();

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

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

28-
$plugin->version = 2023111500;
28+
$plugin->version = 2023112100;
2929
$plugin->requires = 2020061500; // Moodle 3.9.0 and above.
3030
$plugin->supported = [39, 401]; // Moodle 3.9 to 4.1 inclusive.
3131
$plugin->component = 'mod_cms';

0 commit comments

Comments
 (0)