Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mdl 27450 #25

Closed
wants to merge 78 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
17252e2
Adding some of the base classes and starting to fill out their method…
polothy Mar 9, 2011
7336701
Minor fixes and added more methods
polothy Mar 9, 2011
1e8c265
Added converter format detection and added conversion logic to restor…
polothy Mar 10, 2011
c5c8b35
Making the conversion process more re-usable
polothy Mar 10, 2011
8450e2c
Attempting to write up processing of the moodle.xml file - the conver…
polothy Mar 11, 2011
5af8804
Moving converters into sub-directories so they can have other files a…
polothy Mar 11, 2011
653bc98
Fixing several bugs while actually trying to execute some of the code
polothy Mar 11, 2011
dda1981
Starting to unit test - fixed bugs, things are... working!?!
polothy Mar 11, 2011
5c10f37
Adding vanilla 1.9 moodle.xml for unit testing.
philcali Mar 11, 2011
bb2e160
Full example implementation of the convert course step
polothy Mar 14, 2011
970bc1f
Adding root and final tasks
polothy Mar 14, 2011
142ec51
Added contextid generation... I think.
Mar 14, 2011
eba6af7
Re-arranging function definition
polothy Mar 14, 2011
e10e887
Might make it faster...
polothy Mar 14, 2011
6c0235b
Adding doc block
polothy Mar 14, 2011
62c5daf
Adding doc block todos
polothy Mar 14, 2011
a656fcb
Adding the convert_file function to the file manager.
Mar 14, 2011
56bd1ab
Added use of get_contextid and fixed some problems
polothy Mar 14, 2011
be14592
Creating stepslib.php and taskslib.php
polothy Mar 14, 2011
d2c32ec
A start at a moodle1 abstract structured step
polothy Mar 14, 2011
7125544
Adding to moodle1 abstract structured step
polothy Mar 14, 2011
30a4a49
Figured out how to get the final task to work properly
polothy Mar 17, 2011
534d429
Section conversion
polothy Mar 18, 2011
72c089f
Adding in activity support and adding base forum classes as proof of …
polothy Mar 21, 2011
7c9d292
Cleanup from last commit, just wanted prototype code to be saved to VCS
polothy Mar 21, 2011
5aee1af
Adding plugin abstract class and adding a step to activities to gener…
polothy Mar 21, 2011
8e2c536
Adding basic block instance conversion
polothy Mar 21, 2011
be85390
Adding moodle_backup.xml generation and updating course structure step
polothy Mar 22, 2011
5b01180
Apply parser processor new methods + observe $CFG->keeptempdirectorie…
stronk7 Apr 14, 2011
e48477d
MDL-22414 Fixed standard copyright file headers (R0417)
mudrd8mz May 4, 2011
0164592
MDL-27376 MDL-27377 Backup converters API refactored
mudrd8mz May 5, 2011
1e2c735
MDL-27376 MDL-27377 MDL-27378 Backup converters refactoring - work in…
mudrd8mz May 9, 2011
a5fe591
MDL-27376 MDL-27377 MDL-27378 Backup converters refactoring - still w…
mudrd8mz May 11, 2011
beb7de3
More backup-converter API improvements
mudrd8mz May 12, 2011
9b5f1ad
Improved the moodle1_convert stashing subsystem
mudrd8mz May 12, 2011
d5d0263
Refactored get_contextid() and unit tests for it
mudrd8mz May 12, 2011
baa6f6a
Improved course module info conversion
mudrd8mz May 13, 2011
5f3185f
MDL-27444 Choice module 1.9 backup converts to 2.0 format
mudrd8mz May 13, 2011
a5ea28b
Removing relics of the previous plan/tasks/steps based implementation
mudrd8mz May 13, 2011
eb3dc80
Merge branch 'master' into backup-convert
mudrd8mz May 13, 2011
1cc0e42
The current element's data are passed to the on_element_end() event h…
mudrd8mz May 13, 2011
17d2e21
Renamed converter factory method to more self-descriptive get_convert…
mudrd8mz May 13, 2011
99a8251
The main moodle_backup.xml file is now being generated by the converter
mudrd8mz May 16, 2011
383f6f6
Fixed wrong class name
mudrd8mz May 16, 2011
4eb2a09
The display() method in backup/restore UI returns the HTML rather the…
mudrd8mz May 17, 2011
179982a
Added missing description of the moodle1 converter
mudrd8mz May 17, 2011
d51345c
Fixed the class name in the calling code after a recent change
mudrd8mz May 17, 2011
3a07672
The core_backup_renderer does not need the full backup information an…
mudrd8mz May 17, 2011
f666f14
The first attempt to include backup conversion in the restore process
mudrd8mz May 17, 2011
71d1751
Improved the information display about a non-standard backup file
mudrd8mz May 18, 2011
96f7c7a
Implemented new XML transformer for the files being written during th…
mudrd8mz May 18, 2011
ba66847
Roles definition conversion
mudrd8mz May 18, 2011
c171d28
The basic wrapper for question categories conversion
mudrd8mz May 18, 2011
c18f90f
Merge remote branch 'github/master' into backup-convert
mudrd8mz May 18, 2011
ae80f68
Improvements in moodle1_xml_handler external API
mudrd8mz May 18, 2011
46ff8b0
The handler's process_xxx() method is not mandatory any more
mudrd8mz May 19, 2011
ab1da26
MDL-27442 forum: allow forum to be restored into 2.1 from a 1.9 backup
andyjdavis May 18, 2011
317f1c6
Generate fake XML files to make the restore process happy
mudrd8mz May 19, 2011
2304cba
Do not try to convert activity modules that do not have the converter…
mudrd8mz May 19, 2011
be53cf4
MDL-27439 added moodle1 backup converter for assignment
May 20, 2011
01b922f
Trivial improvement of member variables doc
mudrd8mz May 20, 2011
6d73f18
New method get_stash_itemids()
mudrd8mz May 20, 2011
dbf6843
Include a course file in the unit test
mudrd8mz May 20, 2011
6700d28
New get_nextid() method
mudrd8mz May 20, 2011
26cac34
Improved get_contextid()
mudrd8mz May 20, 2011
716a961
The handlers now throw moodle1_convert_exception instead of convert_e…
mudrd8mz May 20, 2011
f3b0b1e
The write_xml() does not put 'id' into attributes implicitly
mudrd8mz May 20, 2011
8312ab6
Course files conversion
mudrd8mz May 20, 2011
8b866ce
Merge branch 'MDL-27439' of git://github.com/nebgor/moodle into backu…
mudrd8mz May 24, 2011
eb78f06
MDL-27594 backup - fix start/end notifications on empty chunks
stronk7 May 22, 2011
6357693
Extended debugging information thrown by an exception
mudrd8mz May 24, 2011
8bcefb3
Activity module handler get_moduleid() replaced with get_cminfo()
mudrd8mz May 24, 2011
2fe7d14
The generation of module.xml and friends moved to a later phase
mudrd8mz May 24, 2011
b391176
MDL-27445 added moodle1 backup converter for chat
May 20, 2011
ad28527
MDL-27445 Fixed the deprecated call
mudrd8mz May 24, 2011
d171107
MDL-27445 added moodle1 backup converter for label
May 20, 2011
d777f26
MDL-27445 Fixed the deprecated call
mudrd8mz May 25, 2011
39a35cc
MDL-27450 mod_survey: added conversion code to restore 1.9 backup to …
May 26, 2011
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backup/backup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ abstract class backup implements checksumable {
const MODE_HUB = 30;
const MODE_SAMESITE = 40;
const MODE_AUTOMATED = 50;
const MODE_CONVERTED = 60;

// Target (new/existing/current/adding/deleting)
const TARGET_CURRENT_DELETING = 0;
Expand Down
40 changes: 19 additions & 21 deletions backup/controller/restore_controller.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,38 +377,36 @@ public static function get_tempdir_name($courseid = 0, $userid = 0) {
}

/**
* convert from current format to backup::MOODLE format
* Converts from current format to backup::MOODLE format
*/
public function convert() {
global $CFG;
require_once($CFG->dirroot . '/backup/util/helper/convert_helper.class.php');

if ($this->status != backup::STATUS_REQUIRE_CONV) {
throw new restore_controller_exception('cannot_convert_not_required_status');
}
if ($this->format == backup::FORMAT_UNKNOWN) {
throw new restore_controller_exception('cannot_convert_from_unknown_format');
}
if ($this->format == backup::FORMAT_MOODLE1) {
// TODO: Implement moodle1 => moodle2 conversion
throw new restore_controller_exception('cannot_convert_yet_from_moodle1_format');

// Run conversion to the proper format
if (!convert_helper::to_moodle2_format($this->get_tempdir(), $this->format)) {
// todo - unable to find the conversion path, what to do now?
// throwing the exception as a temporary solution
throw new restore_controller_exception('unable_to_find_conversion_path');
}

// Once conversions have finished, we check again the format
$newformat = backup_general_helper::detect_backup_format($tempdir);
// If no exceptions were thrown, then we are in the proper format
$this->format = backup::FORMAT_MOODLE;

// If format is moodle2, load plan, apply security and set status based on interactivity
if ($newformat === backup::FORMAT_MOODLE) {
// Load plan
$this->load_plan();
// Load plan, apply security and set status based on interactivity
$this->load_plan();

// Perform all initial security checks and apply (2nd param) them to settings automatically
restore_check::check_security($this, true);
// Perform all initial security checks and apply (2nd param) them to settings automatically
restore_check::check_security($this, true);

if ($this->interactive == backup::INTERACTIVE_YES) {
$this->set_status(backup::STATUS_SETTING_UI);
} else {
$this->set_status(backup::STATUS_NEED_PRECHECK);
}
if ($this->interactive == backup::INTERACTIVE_YES) {
$this->set_status(backup::STATUS_SETTING_UI);
} else {
throw new restore_controller_exception('conversion_ended_with_wrong_format', $newformat);
$this->set_status(backup::STATUS_NEED_PRECHECK);
}
}

Expand Down
241 changes: 241 additions & 0 deletions backup/converter/convertlib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Provides base converter classes
*
* @package core
* @subpackage backup-convert
* @copyright 2011 Mark Nielsen <mark@moodlerooms.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/backup/util/includes/convert_includes.php');

/**
* Base converter class
*
* All Moodle backup converters are supposed to extend this base class.
*
* @throws convert_exception
*/
abstract class base_converter {

/** @var string unique identifier of this converter instance */
protected $id;
/** @var string the name of the directory containing the unpacked backup being converted */
protected $tempdir;
/** @var string the name of the directory where the backup is converted to */
protected $workdir;

/**
* Constructor
*
* @param string $tempdir the relative path to the directory containing the unpacked backup to convert
*/
public function __construct($tempdir) {

$this->tempdir = $tempdir;
$this->id = convert_helper::generate_id($this->workdir);
$this->workdir = $tempdir . '_' . $this->get_name() . '_' . $this->id;
$this->init();
}

/**
* Get instance identifier
*
* @return string the unique identifier of this converter instance
*/
public function get_id() {
return $this->id;
}

/**
* Get converter name
*
* @return string the system name of the converter
*/
public function get_name() {
return array_shift(explode('_', get_class($this)));
}

/**
* Converts the backup directory
*/
public function convert() {

try {
$this->create_workdir();
$this->execute();
$this->replace_tempdir();
} catch (Exception $e) {
}

// clean-up stuff if needed
$this->destroy();

// eventually re-throw the execution exception
if (isset($e) and ($e instanceof Exception)) {
throw $e;
}
}

/// public static methods //////////////////////////////////////////////////

/**
* Makes sure that this converter is available at this site
*
* This is intended for eventual PHP extensions check, environment check etc.
* All checks that do not depend on actual backup data should be done here.
*
* @return boolean true if this converter should be considered as available
*/
public static function is_available() {
return true;
}

/**
* Detects the format of the backup directory
*
* Moodle 2.x format is being detected by the core itself. The converters are
* therefore supposed to detect the source format. Eventually, if the target
* format os not {@link backup::FORMAT_MOODLE} then they should be able to
* detect both source and target formats.
*
* @param string $tempdir the name of the backup directory
* @return null|string null if not recognized, backup::FORMAT_xxx otherwise
*/
public static function detect_format($tempdir) {
return null;
}

/**
* Returns the basic information about the converter
*
* The returned array must contain the following keys:
* 'from' - the supported source format, eg. backup::FORMAT_MOODLE1
* 'to' - the supported target format, eg. backup::FORMAT_MOODLE
* 'cost' - the cost of the conversion, non-negative non-zero integer
*/
public static function description() {

return array(
'from' => null,
'to' => null,
'cost' => null,
);
}

/**
* @return string the full path to the working directory
*/
public function get_workdir_path() {
global $CFG;

return "$CFG->dataroot/temp/backup/$this->workdir";
}

/**
* @return string the full path to the directory with the source backup
*/
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 convert_exception('failed_create_workdir');
}
}

/**
* Replaces the source backup directory with the converted version
*
* If $CFG->keeptempdirectoriesonbackup is defined, the original source
* source backup directory is kept for debugging purposes.
*/
protected function replace_tempdir() {
global $CFG;

if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($this->get_tempdir_path());
} else {
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 convert_exception('failed_move_converted_into_place');
}
}

/**
* Cleans up stuff after the execution
*
* Note that we do not know if the execution was successful or not.
* An exception might have been thrown.
*/
protected function destroy() {
global $CFG;

if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($this->get_workdir_path());
}
}
}

/**
* General convert-related exception
*
* @author David Mudrak <david@moodle.com>
*/
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);
}
}
Loading