本文整理汇总了PHP中assign::copy_area_files_for_upgrade方法的典型用法代码示例。如果您正苦于以下问题:PHP assign::copy_area_files_for_upgrade方法的具体用法?PHP assign::copy_area_files_for_upgrade怎么用?PHP assign::copy_area_files_for_upgrade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类assign
的用法示例。
在下文中一共展示了assign::copy_area_files_for_upgrade方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upgrade_assignment
/**
* This function converts all of the base settings for an instance of
* the old assignment to the new format. Then it calls each of the plugins
* to see if they can help upgrade this assignment.
* @param int $oldassignmentid (don't rely on the old assignment type even being installed)
* @param string $log This string gets appended to during the conversion process
* @return bool true or false
*/
public function upgrade_assignment($oldassignmentid, &$log)
{
global $DB, $CFG, $USER;
// Steps to upgrade an assignment.
// Is the user the admin? admin check goes here.
if (!is_siteadmin($USER->id)) {
return false;
}
core_php_time_limit::raise(ASSIGN_MAX_UPGRADE_TIME_SECS);
// Get the module details.
$oldmodule = $DB->get_record('modules', array('name' => 'assignment'), '*', MUST_EXIST);
$params = array('module' => $oldmodule->id, 'instance' => $oldassignmentid);
$oldcoursemodule = $DB->get_record('course_modules', $params, '*', MUST_EXIST);
$oldcontext = context_module::instance($oldcoursemodule->id);
// First insert an assign instance to get the id.
$oldassignment = $DB->get_record('assignment', array('id' => $oldassignmentid), '*', MUST_EXIST);
$oldversion = get_config('assignment_' . $oldassignment->assignmenttype, 'version');
$data = new stdClass();
$data->course = $oldassignment->course;
$data->name = $oldassignment->name;
$data->intro = $oldassignment->intro;
$data->introformat = $oldassignment->introformat;
$data->alwaysshowdescription = 1;
$data->sendnotifications = $oldassignment->emailteachers;
$data->sendlatenotifications = $oldassignment->emailteachers;
$data->duedate = $oldassignment->timedue;
$data->allowsubmissionsfromdate = $oldassignment->timeavailable;
$data->grade = $oldassignment->grade;
$data->submissiondrafts = $oldassignment->resubmit;
$data->requiresubmissionstatement = 0;
$data->markingworkflow = 0;
$data->markingallocation = 0;
$data->cutoffdate = 0;
// New way to specify no late submissions.
if ($oldassignment->preventlate) {
$data->cutoffdate = $data->duedate;
}
$data->teamsubmission = 0;
$data->requireallteammemberssubmit = 0;
$data->teamsubmissiongroupingid = 0;
$data->blindmarking = 0;
$data->attemptreopenmethod = 'none';
$data->maxattempts = ASSIGN_UNLIMITED_ATTEMPTS;
$newassignment = new assign(null, null, null);
if (!$newassignment->add_instance($data, false)) {
$log = get_string('couldnotcreatenewassignmentinstance', 'mod_assign');
return false;
}
// Now create a new coursemodule from the old one.
$newmodule = $DB->get_record('modules', array('name' => 'assign'), '*', MUST_EXIST);
$newcoursemodule = $this->duplicate_course_module($oldcoursemodule, $newmodule->id, $newassignment->get_instance()->id);
if (!$newcoursemodule) {
$log = get_string('couldnotcreatenewcoursemodule', 'mod_assign');
return false;
}
// Convert the base database tables (assignment, submission, grade).
// These are used to store information in case a rollback is required.
$gradingarea = null;
$gradingdefinitions = null;
$gradeidmap = array();
$completiondone = false;
$gradesdone = false;
// From this point we want to rollback on failure.
$rollback = false;
try {
$newassignment->set_context(context_module::instance($newcoursemodule->id));
// The course module has now been created - time to update the core tables.
// Copy intro files.
$newassignment->copy_area_files_for_upgrade($oldcontext->id, 'mod_assignment', 'intro', 0, $newassignment->get_context()->id, 'mod_assign', 'intro', 0);
// Get the plugins to do their bit.
foreach ($newassignment->get_submission_plugins() as $plugin) {
if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
$plugin->enable();
if (!$plugin->upgrade_settings($oldcontext, $oldassignment, $log)) {
$rollback = true;
}
} else {
$plugin->disable();
}
}
foreach ($newassignment->get_feedback_plugins() as $plugin) {
if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
$plugin->enable();
if (!$plugin->upgrade_settings($oldcontext, $oldassignment, $log)) {
$rollback = true;
}
} else {
$plugin->disable();
}
}
// See if there is advanced grading upgrades required.
$gradingarea = $DB->get_record('grading_areas', array('contextid' => $oldcontext->id, 'areaname' => 'submission'), '*', IGNORE_MISSING);
//.........这里部分代码省略.........
示例2: upgrade_assignment
/**
* This function converts all of the base settings for an instance of
* the old assignment to the new format. Then it calls each of the plugins
* to see if they can help upgrade this assignment.
* @param int $oldassignmentid (don't rely on the old assignment type even being installed)
* @param string $log This string gets appended to during the conversion process
* @return bool true or false
*/
public function upgrade_assignment($oldassignmentid, &$log)
{
// steps to upgrade an assignment
global $DB, $CFG, $USER;
// steps to upgrade an assignment
// is the user the admin? admin check goes here
if (!is_siteadmin($USER->id)) {
return false;
}
// should we use a shutdown handler to rollback on timeout?
@set_time_limit(ASSIGN_MAX_UPGRADE_TIME_SECS);
// get the module details
$oldmodule = $DB->get_record('modules', array('name' => 'assignment'), '*', MUST_EXIST);
$oldcoursemodule = $DB->get_record('course_modules', array('module' => $oldmodule->id, 'instance' => $oldassignmentid), '*', MUST_EXIST);
$oldcontext = context_module::instance($oldcoursemodule->id);
// first insert an assign instance to get the id
$oldassignment = $DB->get_record('assignment', array('id' => $oldassignmentid), '*', MUST_EXIST);
$oldversion = get_config('assignment_' . $oldassignment->assignmenttype, 'version');
$data = new stdClass();
$data->course = $oldassignment->course;
$data->name = $oldassignment->name;
$data->intro = $oldassignment->intro;
$data->introformat = $oldassignment->introformat;
$data->alwaysshowdescription = 1;
$data->sendnotifications = $oldassignment->emailteachers;
$data->sendlatenotifications = $oldassignment->emailteachers;
$data->duedate = $oldassignment->timedue;
$data->allowsubmissionsfromdate = $oldassignment->timeavailable;
$data->grade = $oldassignment->grade;
$data->submissiondrafts = $oldassignment->resubmit;
$data->preventlatesubmissions = $oldassignment->preventlate;
$newassignment = new assign(null, null, null);
if (!$newassignment->add_instance($data, false)) {
$log = get_string('couldnotcreatenewassignmentinstance', 'mod_assign');
return false;
}
// now create a new coursemodule from the old one
$newmodule = $DB->get_record('modules', array('name' => 'assign'), '*', MUST_EXIST);
$newcoursemodule = $this->duplicate_course_module($oldcoursemodule, $newmodule->id, $newassignment->get_instance()->id);
if (!$newcoursemodule) {
$log = get_string('couldnotcreatenewcoursemodule', 'mod_assign');
return false;
}
// convert the base database tables (assignment, submission, grade)
// these are used to store information in case a rollback is required
$gradingarea = null;
$gradingdefinitions = null;
$gradeidmap = array();
$completiondone = false;
$gradesdone = false;
// from this point we want to rollback on failure
$rollback = false;
try {
$newassignment->set_context(context_module::instance($newcoursemodule->id));
// the course module has now been created - time to update the core tables
// copy intro files
$newassignment->copy_area_files_for_upgrade($oldcontext->id, 'mod_assignment', 'intro', 0, $newassignment->get_context()->id, 'mod_assign', 'intro', 0);
// get the plugins to do their bit
foreach ($newassignment->get_submission_plugins() as $plugin) {
if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
$plugin->enable();
if (!$plugin->upgrade_settings($oldcontext, $oldassignment, $log)) {
$rollback = true;
}
} else {
$plugin->disable();
}
}
foreach ($newassignment->get_feedback_plugins() as $plugin) {
if ($plugin->can_upgrade($oldassignment->assignmenttype, $oldversion)) {
$plugin->enable();
if (!$plugin->upgrade_settings($oldcontext, $oldassignment, $log)) {
$rollback = true;
}
} else {
$plugin->disable();
}
}
// see if there is advanced grading upgrades required
$gradingarea = $DB->get_record('grading_areas', array('contextid' => $oldcontext->id, 'areaname' => 'submission'), '*', IGNORE_MISSING);
if ($gradingarea) {
$DB->update_record('grading_areas', array('id' => $gradingarea->id, 'contextid' => $newassignment->get_context()->id, 'component' => 'mod_assign', 'areaname' => 'submissions'));
$gradingdefinitions = $DB->get_records('grading_definitions', array('areaid' => $gradingarea->id));
}
// upgrade completion data
$DB->set_field('course_modules_completion', 'coursemoduleid', $newcoursemodule->id, array('coursemoduleid' => $oldcoursemodule->id));
$allcriteria = $DB->get_records('course_completion_criteria', array('moduleinstance' => $oldcoursemodule->id));
foreach ($allcriteria as $criteria) {
$criteria->module = 'assign';
$criteria->moduleinstance = $newcoursemodule->id;
$DB->update_record('course_completion_criteria', $criteria);
}
//.........这里部分代码省略.........