Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #122 Complete duplicate_task #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions classes/task/duplicate_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,28 @@ public function execute() {
$data = $this->get_custom_data();
// We use sectionid for duplicating modules in the same course, but sectionnum for duplicating to another course.
if (!empty($data->courseid)) {
// If a courseid has been set we are duplicating to another course.
$sectionnum = -1;
if (property_exists($data, 'sectionnum')) {
// If no sectionnum has been specified, we default to -1 which means course modules will be restored to the same
// section they have in the source course.
$sectionnum = $data->sectionnum;
}
// If a courseid has been set we are duplicating to another course.
actions::duplicate_to_course((array) $data->modules, $data->courseid, $sectionnum);
try {
actions::duplicate_to_course((array) $data->modules, $data->courseid, $sectionnum);
} catch (moodle_exception $e) {
// Add the error to log and complete the task.
mtrace($e->getMessage());
}
} else {
// If no courseid has been set, we just duplicate in the same course.
$sectionid = empty($data->sectionid) ? false : $data->sectionid;
actions::duplicate((array) $data->modules, $sectionid);
try {
actions::duplicate((array) $data->modules, $sectionid);
} catch (moodle_exception $e) {
// Add the error to log and complete the task.
mtrace($e->getMessage());
}
}
}
}
Loading