From 8a1a951f7c77bf997256044eba67fb38b5ea33c9 Mon Sep 17 00:00:00 2001 From: David Monllao Date: Mon, 16 Jul 2012 14:54:06 +0800 Subject: [PATCH] MDL-29563 course Hide duplication button in activities without backup2 support - Credit to Mark Nielsen --- course/lib.php | 4 ++-- course/modduplicate.php | 18 ++++++++++++++---- lang/en/moodle.php | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/course/lib.php b/course/lib.php index 838e194f56f..603901d6561 100644 --- a/course/lib.php +++ b/course/lib.php @@ -3291,8 +3291,8 @@ function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $movesele ); } - // Duplicate (require both target import caps to be able to duplicate, see modduplicate.php) - if (has_all_capabilities($dupecaps, $coursecontext)) { + // Duplicate (require both target import caps to be able to duplicate and backup2 support, see modduplicate.php) + if (has_all_capabilities($dupecaps, $coursecontext) && plugin_supports('mod', $mod->modname, FEATURE_BACKUP_MOODLE2)) { $actions[] = new action_link( new moodle_url($baseurl, array('duplicate' => $mod->id)), new pix_icon('t/copy', $str->duplicate, 'moodle', array('class' => 'iconsmall')), diff --git a/course/modduplicate.php b/course/modduplicate.php index e08ea355faa..b4d593b4e01 100644 --- a/course/modduplicate.php +++ b/course/modduplicate.php @@ -56,6 +56,20 @@ $PAGE->set_pagelayout('incourse'); $output = $PAGE->get_renderer('core', 'backup'); +$a = new stdClass(); +$a->modtype = get_string('modulename', $cm->modname); +$a->modname = format_string($cm->name); + +if (!plugin_supports('mod', $cm->modname, FEATURE_BACKUP_MOODLE2)) { + echo $output->header(); + echo $output->notification(get_string('duplicatenosupport', 'core', $a)); + echo $output->continue_button( + new moodle_url('/course/view.php#section-' . $cm->sectionnum, array('id' => $course->id)) + ); + echo $output->footer(); + die; +} + // backup the activity $bc = new backup_controller(backup::TYPE_1ACTIVITY, $cm->id, backup::FORMAT_MOODLE, @@ -118,10 +132,6 @@ if (empty($CFG->keeptempdirectoriesonbackup)) { fulldelete($backupbasepath); } -$a = new stdClass(); -$a->modtype = get_string('modulename', $cm->modname); -$a->modname = format_string($cm->name); - echo $output->header(); if ($newcmid) { diff --git a/lang/en/moodle.php b/lang/en/moodle.php index af23c90f27a..1aae903d93e 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -487,6 +487,7 @@ $string['duplicate'] = 'Duplicate'; $string['duplicateconfirm'] = 'Are you sure you want to duplicate {$a->modtype} \'{$a->modname}\' ?'; $string['duplicatecontcourse'] = 'Return to the course'; $string['duplicatecontedit'] = 'Edit the new copy'; +$string['duplicatenosupport'] = '\'{$a->modname}\' activity could not be duplicated because the {$a->modtype} module does not support backup and restore.'; $string['duplicatesuccess'] = '{$a->modtype} \'{$a->modname}\' has been duplicated successfully'; $string['duplicatinga'] = 'Duplicating: {$a}'; $string['edhelpaspellpath'] = 'To use spell-checking within the editor, you MUST have aspell 0.50 or later installed on your server, and you must specify the correct path to access the aspell binary. On Unix/Linux systems, this path is usually /usr/bin/aspell, but it might be something else.';