Skip to content

Commit af54be6

Browse files
ELIS-8632: Peer Review change to check if multiple blockinstances exist and loop through all + language string 'datahub:addinstance'
1 parent 126a5dd commit af54be6

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

Diff for: db/install.php

+23-20
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,30 @@ function xmldb_local_datahub_install() {
3232
$oldrecord = $DB->get_record('block', array('name' => 'rlip'), 'id');
3333
if (!empty($oldrecord)) {
3434
// Convert any existing old rlip block instances to html blocks.
35-
$plugins = get_string('plugins', 'local_datahub');
36-
$logs = get_string('logs', 'local_datahub');
37-
$obj = new stdClass();
35+
$oldblockinsts = $DB->get_recordset('block_instances', array('blockname' => 'rlip'), '', 'id');
36+
if ($oldblockinsts && $oldblockinsts->valid()) {
37+
$plugins = get_string('plugins', 'local_datahub');
38+
$logs = get_string('logs', 'local_datahub');
39+
$obj = new stdClass();
40+
$pluginstag = html_writer::tag('a', $plugins, array('href' => $CFG->wwwroot.'/local/datahub/plugins.php', 'title' => $plugins));
41+
$logstag = html_writer::tag('a', $logs, array('href' => $CFG->wwwroot.'/local/datahub/viewlogs.php', 'title' => $logs));
42+
$obj->text = html_writer::tag('p', $pluginstag).html_writer::tag('p', $logstag);
43+
$obj->title = get_string('pluginname', 'local_datahub');
44+
$obj->format = 1;
45+
$configdata = base64_encode(serialize($obj));
46+
$sql = "UPDATE {block_instances} SET blockname = 'html', configdata = ? WHERE blockname = 'rlip'";
47+
$DB->execute($sql, array($configdata));
3848

39-
$blockinstanceid = $DB->get_field('block_instances', 'id', array('blockname' => 'rlip'));
40-
41-
$pluginstag = html_writer::tag('a', $plugins, array('href' => $CFG->wwwroot.'/local/datahub/plugins.php', 'title' => $plugins));
42-
$logstag = html_writer::tag('a', $logs, array('href' => $CFG->wwwroot.'/local/datahub/viewlogs.php', 'title' => $logs));
43-
$obj->text = html_writer::tag('p', $pluginstag).html_writer::tag('p', $logstag);
44-
$obj->title = get_string('pluginname', 'local_datahub');
45-
$obj->format = 1;
46-
$configdata = base64_encode(serialize($obj));
47-
$sql = "UPDATE {block_instances} SET blockname = 'html', configdata = ? WHERE blockname = 'rlip'";
48-
$DB->execute($sql, array($configdata));
49-
50-
$context = context_block::instance($blockinstanceid);
51-
$cap = 'moodle/block:view';
52-
$roles = get_roles_with_capability($cap, CAP_ALLOW, $context);
53-
foreach ($roles as $role) {
54-
if ($role->id != 1) {
55-
assign_capability($cap, CAP_PREVENT, $role->id, $context->id);
49+
// Hide blocks from all but site admins
50+
$cap = 'moodle/block:view';
51+
foreach ($oldblockinsts as $oldblockinst) {
52+
$context = context_block::instance($oldblockinst->id);
53+
$roles = get_roles_with_capability($cap, CAP_ALLOW, $context);
54+
foreach ($roles as $role) {
55+
if ($role->id != 1) {
56+
assign_capability($cap, CAP_PREVENT, $role->id, $context->id);
57+
}
58+
}
5659
}
5760
}
5861

Diff for: lang/en/local_datahub.php

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
$string['automatic'] = 'Automatic';
2929
$string['confirm_delete_ipjob'] = 'Are you sure to delete DH job #{$a}?';
3030
$string['configdisableincron'] = 'If enabled, this setting disables this plugin from running in the Moodle cron. Use this setting when running imports & exports via a separate system-level cron.';
31+
$string['datahub:addinstance'] = 'Add a DataHub instance';
3132
$string['datahub_settings'] = 'Datahub Settings';
3233
$string['dateformat'] = 'M/d/Y';
3334
$string['dblogimportexceedstimelimit'] = 'Failed importing all lines from import file {$a->filename} due to time limit exceeded. Processed {$a->recordsprocessed} of {$a->totalrecords} records.';

0 commit comments

Comments
 (0)