mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
Merge branch 'MDL-29262' of git://github.com/stronk7/moodle
Conflicts: version.php
This commit is contained in:
commit
e0ed91ba39
8 changed files with 122 additions and 33 deletions
|
@ -170,17 +170,22 @@ class backup_controller extends backup implements loggable {
|
|||
}
|
||||
|
||||
public function set_status($status) {
|
||||
$this->log('setting controller status to', backup::LOG_DEBUG, $status);
|
||||
// TODO: Check it's a correct status
|
||||
$this->status = $status;
|
||||
// Ensure that, once set to backup::STATUS_AWAITING, controller is stored in DB
|
||||
// Note: never save_controller() after STATUS_EXECUTING or the whole controller,
|
||||
// Note: never save_controller() with the object info after STATUS_EXECUTING or the whole controller,
|
||||
// containing all the steps will be sent to DB. 100% (monster) useless.
|
||||
$this->log('setting controller status to', backup::LOG_DEBUG, $status);
|
||||
// TODO: Check it's a correct status.
|
||||
$this->status = $status;
|
||||
// Ensure that, once set to backup::STATUS_AWAITING, controller is stored in DB.
|
||||
if ($status == backup::STATUS_AWAITING) {
|
||||
$this->save_controller();
|
||||
$tbc = self::load_controller($this->backupid);
|
||||
$this->logger = $tbc->logger; // wakeup loggers
|
||||
$tbc->destroy(); // Clean temp controller structures
|
||||
|
||||
} else if ($status == backup::STATUS_FINISHED_OK) {
|
||||
// If the operation has ended without error (backup::STATUS_FINISHED_OK)
|
||||
// proceed by cleaning the object from database. MDL-29262.
|
||||
$this->save_controller(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,12 +317,20 @@ class backup_controller extends backup implements loggable {
|
|||
backup_helper::log($message, $level, $a, $depth, $display, $this->logger);
|
||||
}
|
||||
|
||||
public function save_controller() {
|
||||
/**
|
||||
* Save controller information
|
||||
*
|
||||
* @param bool $includeobj to decide if the object itself must be updated (true) or no (false)
|
||||
* @param bool $cleanobj to decide if the object itself must be cleaned (true) or no (false)
|
||||
*/
|
||||
public function save_controller($includeobj = true, $cleanobj = false) {
|
||||
// Going to save controller to persistent storage, calculate checksum for later checks and save it
|
||||
// TODO: flag the controller as NA. Any operation on it should be forbidden util loaded back
|
||||
$this->log('saving controller to db', backup::LOG_DEBUG);
|
||||
$this->checksum = $this->calculate_checksum();
|
||||
backup_controller_dbops::save_controller($this, $this->checksum);
|
||||
if ($includeobj ) { // Only calculate checksum if we are going to include the object.
|
||||
$this->checksum = $this->calculate_checksum();
|
||||
}
|
||||
backup_controller_dbops::save_controller($this, $this->checksum, $includeobj, $cleanobj);
|
||||
}
|
||||
|
||||
public static function load_controller($backupid) {
|
||||
|
|
|
@ -166,17 +166,22 @@ class restore_controller extends backup implements loggable {
|
|||
}
|
||||
|
||||
public function set_status($status) {
|
||||
$this->log('setting controller status to', backup::LOG_DEBUG, $status);
|
||||
// TODO: Check it's a correct status
|
||||
$this->status = $status;
|
||||
// Ensure that, once set to backup::STATUS_AWAITING | STATUS_NEED_PRECHECK, controller is stored in DB
|
||||
// Note: never save_controller() after STATUS_EXECUTING or the whole controller,
|
||||
// Note: never save_controller() with the object info after STATUS_EXECUTING or the whole controller,
|
||||
// containing all the steps will be sent to DB. 100% (monster) useless.
|
||||
$this->log('setting controller status to', backup::LOG_DEBUG, $status);
|
||||
// TODO: Check it's a correct status.
|
||||
$this->status = $status;
|
||||
// Ensure that, once set to backup::STATUS_AWAITING | STATUS_NEED_PRECHECK, controller is stored in DB.
|
||||
if ($status == backup::STATUS_AWAITING || $status == backup::STATUS_NEED_PRECHECK) {
|
||||
$this->save_controller();
|
||||
$tbc = self::load_controller($this->restoreid);
|
||||
$this->logger = $tbc->logger; // wakeup loggers
|
||||
$tbc->destroy(); // Clean temp controller structures
|
||||
|
||||
} else if ($status == backup::STATUS_FINISHED_OK) {
|
||||
// If the operation has ended without error (backup::STATUS_FINISHED_OK)
|
||||
// proceed by cleaning the object from database. MDL-29262.
|
||||
$this->save_controller(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,12 +368,20 @@ class restore_controller extends backup implements loggable {
|
|||
backup_helper::log($message, $level, $a, $depth, $display, $this->logger);
|
||||
}
|
||||
|
||||
public function save_controller() {
|
||||
/**
|
||||
* Save controller information
|
||||
*
|
||||
* @param bool $includeobj to decide if the object itself must be updated (true) or no (false)
|
||||
* @param bool $cleanobj to decide if the object itself must be cleaned (true) or no (false)
|
||||
*/
|
||||
public function save_controller($includeobj = true, $cleanobj = false) {
|
||||
// Going to save controller to persistent storage, calculate checksum for later checks and save it
|
||||
// TODO: flag the controller as NA. Any operation on it should be forbidden util loaded back
|
||||
$this->log('saving controller to db', backup::LOG_DEBUG);
|
||||
$this->checksum = $this->calculate_checksum();
|
||||
restore_controller_dbops::save_controller($this, $this->checksum);
|
||||
if ($includeobj ) { // Only calculate checksum if we are going to include the object.
|
||||
$this->checksum = $this->calculate_checksum();
|
||||
}
|
||||
restore_controller_dbops::save_controller($this, $this->checksum, $includeobj, $cleanobj);
|
||||
}
|
||||
|
||||
public static function load_controller($restoreid) {
|
||||
|
|
|
@ -32,16 +32,30 @@
|
|||
*/
|
||||
abstract class backup_controller_dbops extends backup_dbops {
|
||||
|
||||
public static function save_controller($controller, $checksum) {
|
||||
/**
|
||||
* Send one backup controller to DB
|
||||
*
|
||||
* @param backup_controller $controller controller to send to DB
|
||||
* @param string $checksum hash of the controller to be checked
|
||||
* @param bool $includeobj to decide if the object itself must be updated (true) or no (false)
|
||||
* @param bool $cleanobj to decide if the object itself must be cleaned (true) or no (false)
|
||||
* @return int id of the controller record in the DB
|
||||
* @throws backup_controller_exception|backup_dbops_exception
|
||||
*/
|
||||
public static function save_controller($controller, $checksum, $includeobj = true, $cleanobj = false) {
|
||||
global $DB;
|
||||
// Check we are going to save one backup_controller
|
||||
if (! $controller instanceof backup_controller) {
|
||||
throw new backup_controller_exception('backup_controller_expected');
|
||||
}
|
||||
// Check checksum is ok. Sounds silly but it isn't ;-)
|
||||
if (!$controller->is_checksum_correct($checksum)) {
|
||||
// Check checksum is ok. Only if we are including object info. Sounds silly but it isn't ;-).
|
||||
if ($includeobj and !$controller->is_checksum_correct($checksum)) {
|
||||
throw new backup_dbops_exception('backup_controller_dbops_saving_checksum_mismatch');
|
||||
}
|
||||
// Cannot request to $includeobj and $cleanobj at the same time.
|
||||
if ($includeobj and $cleanobj) {
|
||||
throw new backup_dbops_exception('backup_controller_dbops_saving_cannot_include_and_delete');
|
||||
}
|
||||
// Get all the columns
|
||||
$rec = new stdclass();
|
||||
$rec->backupid = $controller->get_backupid();
|
||||
|
@ -57,7 +71,11 @@ abstract class backup_controller_dbops extends backup_dbops {
|
|||
$rec->executiontime= $controller->get_executiontime();
|
||||
$rec->checksum = $checksum;
|
||||
// Serialize information
|
||||
$rec->controller = base64_encode(serialize($controller));
|
||||
if ($includeobj) {
|
||||
$rec->controller = base64_encode(serialize($controller));
|
||||
} else if ($cleanobj) {
|
||||
$rec->controller = '';
|
||||
}
|
||||
// Send it to DB
|
||||
if ($recexists = $DB->get_record('backup_controllers', array('backupid' => $rec->backupid))) {
|
||||
$rec->id = $recexists->id;
|
||||
|
|
|
@ -32,16 +32,30 @@
|
|||
*/
|
||||
abstract class restore_controller_dbops extends restore_dbops {
|
||||
|
||||
public static function save_controller($controller, $checksum) {
|
||||
/**
|
||||
* Send one restore controller to DB
|
||||
*
|
||||
* @param restore_controller $controller controller to send to DB
|
||||
* @param string $checksum hash of the controller to be checked
|
||||
* @param bool $includeobj to decide if the object itself must be updated (true) or no (false)
|
||||
* @param bool $cleanobj to decide if the object itself must be cleaned (true) or no (false)
|
||||
* @return int id of the controller record in the DB
|
||||
* @throws backup_controller_exception|restore_dbops_exception
|
||||
*/
|
||||
public static function save_controller($controller, $checksum, $includeobj = true, $cleanobj = false) {
|
||||
global $DB;
|
||||
// Check we are going to save one backup_controller
|
||||
if (! $controller instanceof restore_controller) {
|
||||
throw new backup_controller_exception('restore_controller_expected');
|
||||
}
|
||||
// Check checksum is ok. Sounds silly but it isn't ;-)
|
||||
if (!$controller->is_checksum_correct($checksum)) {
|
||||
// Check checksum is ok. Only if we are including object info. Sounds silly but it isn't ;-).
|
||||
if ($includeobj and !$controller->is_checksum_correct($checksum)) {
|
||||
throw new restore_dbops_exception('restore_controller_dbops_saving_checksum_mismatch');
|
||||
}
|
||||
// Cannot request to $includeobj and $cleanobj at the same time.
|
||||
if ($includeobj and $cleanobj) {
|
||||
throw new restore_dbops_exception('restore_controller_dbops_saving_cannot_include_and_delete');
|
||||
}
|
||||
// Get all the columns
|
||||
$rec = new stdclass();
|
||||
$rec->backupid = $controller->get_restoreid();
|
||||
|
@ -57,7 +71,11 @@ abstract class restore_controller_dbops extends restore_dbops {
|
|||
$rec->executiontime= $controller->get_executiontime();
|
||||
$rec->checksum = $checksum;
|
||||
// Serialize information
|
||||
$rec->controller = base64_encode(serialize($controller));
|
||||
if ($includeobj) {
|
||||
$rec->controller = base64_encode(serialize($controller));
|
||||
} else if ($cleanobj) {
|
||||
$rec->controller = '';
|
||||
}
|
||||
// Send it to DB
|
||||
if ($recexists = $DB->get_record('backup_controllers', array('backupid' => $rec->backupid))) {
|
||||
$rec->id = $recexists->id;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue