forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-27376 MDL-27377 MDL-27378 Backup converters refactoring - work in…
… progress These are David's changes of Mark's code that replace the plan/tasks/steps infrastructure with a bit simpler one. The changes will be described in the next commit that will actually finish the conversion. TODO: refactor backup/converter/moodle1/stepslib.php into conversion handlers.
- Loading branch information
Showing
19 changed files
with
1,046 additions
and
779 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Provides base converter classes | ||
* | ||
* @package core | ||
* @subpackage backup-convert | ||
* @copyright 2011 Mark Nielsen <[email protected]> | ||
|
@@ -24,10 +26,14 @@ | |
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot . '/backup/util/includes/convert_includes.php'); | ||
|
||
/** | ||
* Base abstract converter | ||
* Base converter class | ||
* | ||
* All Moodle backup converters are supposed to extend this base class. | ||
* | ||
* @throws backup_exception|Exception|null | ||
* @throws convert_exception | ||
*/ | ||
abstract class base_converter { | ||
|
||
|
@@ -74,9 +80,6 @@ public function get_name() { | |
*/ | ||
public function convert() { | ||
|
||
$e = null; | ||
|
||
// try to execute the converter | ||
try { | ||
$this->create_workdir(); | ||
$this->execute(); | ||
|
@@ -88,7 +91,7 @@ public function convert() { | |
$this->destroy(); | ||
|
||
// eventually re-throw the execution exception | ||
if ($e instanceof Exception) { | ||
if (isset($e) and ($e instanceof Exception)) { | ||
throw $e; | ||
} | ||
} | ||
|
@@ -139,23 +142,10 @@ public static function description() { | |
); | ||
} | ||
|
||
/// end of public API ////////////////////////////////////////////////////// | ||
|
||
/** | ||
* Initialize the instance if needed, called by the constructor | ||
*/ | ||
protected function init() { | ||
} | ||
|
||
/** | ||
* Converts the contents of the tempdir into the target format in the workdir | ||
*/ | ||
protected abstract function execute(); | ||
|
||
/** | ||
* @return string the full path to the working directory | ||
*/ | ||
protected function get_workdir_path() { | ||
public function get_workdir_path() { | ||
global $CFG; | ||
|
||
return "$CFG->dataroot/temp/backup/$this->workdir"; | ||
|
@@ -164,20 +154,33 @@ protected function get_workdir_path() { | |
/** | ||
* @return string the full path to the directory with the source backup | ||
*/ | ||
protected function get_tempdir_path() { | ||
public function get_tempdir_path() { | ||
global $CFG; | ||
|
||
return "$CFG->dataroot/temp/backup/$this->tempdir"; | ||
} | ||
|
||
/// end of public API ////////////////////////////////////////////////////// | ||
|
||
/** | ||
* Initialize the instance if needed, called by the constructor | ||
*/ | ||
protected function init() { | ||
} | ||
|
||
/** | ||
* Converts the contents of the tempdir into the target format in the workdir | ||
*/ | ||
protected abstract function execute(); | ||
|
||
/** | ||
* Prepares a new empty working directory | ||
*/ | ||
protected function create_workdir() { | ||
|
||
fulldelete($this->get_workdir_path()); | ||
if (!check_dir_exists($this->get_workdir_path())) { | ||
throw new backup_exception('failedtocreateworkdir'); | ||
throw new convert_exception('failed_create_workdir'); | ||
} | ||
} | ||
|
||
|
@@ -191,15 +194,15 @@ protected function replace_tempdir() { | |
global $CFG; | ||
|
||
if (empty($CFG->keeptempdirectoriesonbackup)) { | ||
fulldelete($this->get_tempdir_path); | ||
fulldelete($this->get_tempdir_path()); | ||
} else { | ||
if (!rename($this->get_tempdir_path, $this->get_tempdir_path . '_' . $this->get_name() . '_' . $this->id . '_source')) { | ||
throw new backup_exception('failedrenamesourcetempdir'); | ||
if (!rename($this->get_tempdir_path(), $this->get_tempdir_path() . '_' . $this->get_name() . '_' . $this->id . '_source')) { | ||
throw new convert_exception('failed_rename_source_tempdir'); | ||
} | ||
} | ||
|
||
if (!rename($this->get_workdir_path(), $this->get_tempdir_path())) { | ||
throw new backup_exception('failedmoveconvertedintoplace'); | ||
throw new convert_exception('failed_move_converted_into_place'); | ||
} | ||
} | ||
|
||
|
@@ -213,7 +216,26 @@ protected function destroy() { | |
global $CFG; | ||
|
||
if (empty($CFG->keeptempdirectoriesonbackup)) { | ||
fulldelete($this->get_workdir_path); | ||
fulldelete($this->get_workdir_path()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* General convert-related exception | ||
* | ||
* @author David Mudrak <[email protected]> | ||
*/ | ||
class convert_exception extends moodle_exception { | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $errorcode key for the corresponding error string | ||
* @param object $a extra words and phrases that might be required in the error string | ||
* @param string $debuginfo optional debugging information | ||
*/ | ||
public function __construct($errorcode, $a = null, $debuginfo = null) { | ||
parent::__construct($errorcode, '', '', $a, $debuginfo); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.