From 529210a9eb36d44d7e61032a1b155159dd3ffacd Mon Sep 17 00:00:00 2001 From: Tomo Tsuyuki Date: Thu, 8 Aug 2024 18:50:07 +1000 Subject: [PATCH] Issue #122 Complete duplicate_task --- classes/task/duplicate_task.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/classes/task/duplicate_task.php b/classes/task/duplicate_task.php index 7464a8d..5c83ced 100644 --- a/classes/task/duplicate_task.php +++ b/classes/task/duplicate_task.php @@ -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()); + } } } }