Skip to content
Permalink
Browse files

Merge branch 'wip-mdl-27790-m21' of git://github.com/rajeshtaneja/moo…

…dle into MOODLE_21_STABLE
  • Loading branch information...
Aparup Banerjee
Aparup Banerjee committed Nov 8, 2011
2 parents 3e99f27 + aa2b2c4 commit f598387441a16c6a085fcc2b6919ac1b63e28874
@@ -42,7 +42,12 @@
$outcome = $restore->process();
if (!$restore->is_independent()) {
if ($restore->get_stage() == restore_ui::STAGE_PROCESS && !$restore->requires_substage()) {
$restore->execute();
try {
$restore->execute();
} catch(Exception $e) {
$restore->cleanup();
throw new moodle_exception((string)$e);
}
} else {
$restore->save_controller();
}
@@ -211,7 +211,7 @@ public function backup_details_unknown(moodle_url $nextstageurl) {
* @return string
*/
public function course_selector(moodle_url $nextstageurl, $wholecourse = true, restore_category_search $categories = null, restore_course_search $courses=null, $currentcourse = null) {
global $CFG;
global $CFG, $PAGE;
require_once($CFG->dirroot.'/course/lib.php');
$nextstageurl->param('sesskey', sesskey());
@@ -232,9 +232,15 @@ public function course_selector(moodle_url $nextstageurl, $wholecourse = true, r
$html .= $this->output->heading(get_string('restoretonewcourse', 'backup'), 2, array('class'=>'header'));
$html .= $this->backup_detail_input(get_string('restoretonewcourse', 'backup'), 'radio', 'target', backup::TARGET_NEW_COURSE, array('checked'=>'checked'));
$html .= $this->backup_detail_pair(get_string('selectacategory', 'backup'), $this->render($categories));
$html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
$html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'), 'class'=>'newcoursecontinue')));
$html .= html_writer::end_tag('div');
$html .= html_writer::end_tag('form');
$config = new stdClass;
$config->title = get_string('confirmnewcoursecontinue', 'backup');
$config->question = get_string('confirmnewcoursecontinuequestion', 'backup');
$config->yesLabel = get_string('continue');
$config->noLabel = get_string('cancel');
$PAGE->requires->yui_module('moodle-backup-confirmcancel', 'M.core_backup.watch_newcoursecontinue_buttons', array($config));
}
if ($wholecourse && !empty($currentcourse)) {
@@ -146,6 +146,39 @@ public function execute() {
$this->stage = new restore_ui_stage_complete($this, $this->stage->get_params(), $this->controller->get_results());
return true;
}
/**
* Delete course which is created by restore process
*/
public function cleanup() {
$courseid = $this->controller->get_courseid();
if ($this->is_temporary_course_created($courseid)) {
delete_course($courseid, false);
}
}
/**
* Checks if the course is not restored fully and current controller has created it.
* @param int $courseid id of the course which needs to be checked
* @return bool
*/
protected function is_temporary_course_created($courseid) {
global $DB;
//Check if current controller instance has created new course.
if ($this->controller->get_target() == backup::TARGET_NEW_COURSE) {
$results = $DB->record_exists_sql("SELECT bc.itemid
FROM {backup_controllers} bc, {course} c
WHERE bc.operation = 'restore'
AND bc.type = 'course'
AND bc.itemid = c.id
AND bc.itemid = ?",
array($courseid)
);
return $results;
}
return false;
}
/**
* Returns true if enforce_dependencies changed any settings
* @return bool
@@ -191,15 +224,18 @@ public function enforce_changed_dependencies() {
/**
* Cancels the current restore and redirects the user back to the relevant place
*/
public function cancel_restore() {
global $PAGE;
// Determine the approriate URL to redirect the user to
if ($PAGE->context->contextlevel == CONTEXT_MODULE && $PAGE->cm !== null) {
$relevanturl = new moodle_url('/mod/'.$PAGE->cm->modname.'/view.php', array('id'=>$PAGE->cm->id));
} else {
$relevanturl = new moodle_url('/course/view.php', array('id'=>$PAGE->course->id));
public function cancel_process() {
//Delete temporary restore course if exists.
if ($this->controller->get_target() == backup::TARGET_NEW_COURSE) {
$this->cleanup();
}
redirect($relevanturl);
parent::cancel_process();
}
/**
* wrapper of cancel_process, kept for avoiding regression.
*/
public function cancel_restore() {
$this->cancel_process();
}
/**
* Gets an array of progress bar items that can be displayed through the restore renderer.
@@ -333,7 +333,7 @@ public function process(base_moodleform $form=null) {
$form = $this->initialise_stage_form();
if ($form->is_cancelled()) {
$this->ui->cancel_restore();
$this->ui->cancel_process();
}
$data = $form->get_data();
@@ -27,4 +27,24 @@ M.core_backup.watch_cancel_buttons = function(config) {
});
}

M.core_backup.watch_newcoursecontinue_buttons = function(config) {
Y.all('.newcoursecontinue').each(function(){
this._confirmationListener = this._confirmationListener || this.on('click', function(e){
// Prevent the default event (sumbit) from firing
e.preventDefault();
// Create the confirm box
var confirm = new M.core.confirm(config);
// If the user clicks yes
confirm.on('complete-yes', function(e){
// Detach the listener for the confirm box so it doesn't fire again.
this._confirmationListener.detach();
// Simulate the original cancel button click
this.simulate('click');
}, this);
// Show the confirm box
confirm.show();
}, this);
});
}

}, '@VERSION@', {'requires':['base','node','node-event-simulate','moodle-enrol-notification']});
@@ -92,6 +92,8 @@
Any information you have entered will be lost.';
$string['confirmcancelyes'] = 'Cancel';
$string['confirmcancelno'] = 'Stay';
$string['confirmnewcoursecontinue'] = 'New course warning';
$string['confirmnewcoursecontinuequestion'] = 'A temporary (hidden) course will be created by the course restoration process. To abort restoration click cancel. Do not close the browser while restoring.';
$string['coursecategory'] = 'Category the course will be restored into';
$string['courseid'] = 'Original ID';
$string['coursesettings'] = 'Course settings';

0 comments on commit f598387

Please sign in to comment.
You can’t perform that action at this time.