. define('CLI_SCRIPT', true); require_once('../../config.php'); $tid = $argv[1]; $ltid = $argv[2]; $template = $DB->get_record('customcert_templates', array('id' => $tid), '*', MUST_EXIST); $template = new \mod_customcert\template($template); $loadtemplate = $DB->get_record('customcert_templates', array('id' => $ltid), '*', MUST_EXIST); $loadtemplate = new \mod_customcert\template($loadtemplate); $cm = $template->get_cm(); if ($template->get_context()->contextlevel == CONTEXT_MODULE) { $customcert = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); $title = $customcert->name; $heading = format_string($title); } else { $title = $SITE->fullname; $heading = $title; } $sql = "SELECT e.* FROM {customcert_elements} e INNER JOIN {customcert_pages} p ON e.pageid = p.id WHERE p.templateid = :templateid"; if ($elements = $DB->get_records_sql($sql, array('templateid' => $template->get_id()))) { foreach ($elements as $element) { if ($e = \mod_customcert\element_factory::get_element_instance($element)) { $e->delete(); } } } $DB->delete_records('customcert_pages', array('templateid' => $template->get_id())); $loadtemplate->copy_to_template($template->get_id());