Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
58 changes: 58 additions & 0 deletions backup/moodle2/backup_local_metadata_plugin.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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/>.
/**
*
* @package local_metadata
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/** Database:
* local_metadata(id, instanceid, fieldid, data, dataformat).
*/
defined('MOODLE_INTERNAL') || die();
/**
* Provides the information to backup metadata.
*/

class backup_local_metadata_plugin extends backup_local_plugin
{
/**
* Returns the format information to attach to module element.
*/
protected function define_module_plugin_structure() {
return $this->build_structure(backup::VAR_MODID, 'module');
}

/**
* Returns the format information to attach to course element.
*/
protected function define_course_plugin_structure() {
return $this->build_structure(backup::VAR_COURSEID, 'course');
}

/**
* Building the XML structure.
*/
protected function build_structure($id, $name = '') {
$plugin = $this->get_plugin_element();
$name = trim($name) !== '' ? $name . '_' : '';
$pluginwrapper = new backup_nested_element($this->get_recommended_name());
$pluginelement = new backup_nested_element($name . 'metadata', ['id'], ['instanceid', 'fieldid', 'data', 'dataformat']);
$pluginelement->set_source_table('local_metadata', ['instanceid' => $id]);
$pluginwrapper->add_child($pluginelement);
$plugin->add_child($pluginwrapper);
return $plugin;
}
}
28 changes: 28 additions & 0 deletions backup/moodle2/backup_metadata_stepslib.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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/>.
/**
*
* @package local_metadata
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();

class backup_metadata_structure_step extends backup_structure_step
{
protected function define_structure() {
return new backup_nested_element('metadata');
}
}
48 changes: 48 additions & 0 deletions backup/moodle2/backup_metadata_task.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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/>.
/**
*
* @package local_metadata
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/local/metadata/backup/moodle2/backup_metadata_stepslib.php');

class backup_metadata_task extends backup_task
{
/**
* Define (add) particular settings this local plugin can have.
*/
protected function define_my_settings() {
// No particular settings for this local plugin.
}

/**
* Define (add) particular steps this local plugin can have.
*/
protected function define_my_steps() {
$this->add_step(new backup_metadata_structure_step('metadata_structure', 'metadata.xml'));
}

/**
* Code the transformations to perform in the local plugin in
* order to get transportable (encoded) links.
*/
public static function encode_content_links($content) {
return $content;
}
}
79 changes: 79 additions & 0 deletions backup/moodle2/restore_local_metadata_plugin.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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/>.
/**
*
* @package local_metadata
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/** Database:
*
* local_metadata(id, instanceid, fieldid, data, dataformat).
*/
defined('MOODLE_INTERNAL') || die();
/**
* Provides the information to restore metadata.
*/
class restore_local_metadata_plugin extends restore_local_plugin
{
const TABLE = 'local_metadata';

/**
* Returns the format information to attach to module element.
*/
protected function define_module_plugin_structure() {
return $this->get_paths('module');
}

/**
* Returns the format information to attach to course element.
*/
protected function define_course_plugin_structure() {
return $this->get_paths('course');
}

protected function get_paths($name) {
$paths = [];
$elename = trim($name) !== '' ? ($name . '_') : '';
$elepath = $this->get_pathfor($elename . 'metadata');
$paths[] = new restore_path_element($elename . 'metadata', $elepath);
return $paths; // And we return the interesting paths.
}

public function process_module_metadata($data) {
$data = (object)$data;
$data->instanceid = $this->task->get_moduleid();
$this->insert_into_db($data);
}

public function process_course_metadata($data) {
global $DB;
$data = (object)$data;
$courseid = $this->task->get_courseid();
if ($record = $DB->get_record(self::TABLE, ['instanceid' => $courseid, 'fieldid' => $data->fieldid])) {
$data->id = $record->id;
$data->instanceid = $courseid;
$DB->update_record(self::TABLE, $data);
} else {
$data->instanceid = $courseid;
$this->insert_into_db($data);
}
}

protected function insert_into_db($data) {
global $DB;
$DB->insert_record(self::TABLE, $data);
}
}
59 changes: 30 additions & 29 deletions version.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
<?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/>.

/**
* @package local_metadata
* @author Mike Churchward <mike.churchward@poetopensource.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2017 onwards Mike Churchward (mike.churchward@poetopensource.org)
*/

defined('MOODLE_INTERNAL') || die;
$plugin->version = 2018120100;
$plugin->release = '3.6.0 (Build 2018120300)';
$plugin->maturity = MATURITY_STABLE;
$plugin->requires = 2016052300; // Moodle 3.1 release and upwards.
$plugin->component = 'local_metadata';
<?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/>.

/**
* @package local_metadata
* @author Mike Churchward <mike.churchward@poetopensource.org>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2017 onwards Mike Churchward (mike.churchward@poetopensource.org)
*/

defined('MOODLE_INTERNAL') || die;
$plugin->version = 2019011100;
$plugin->release = '3.6.0 (Build 2019011100)';
$plugin->maturity = MATURITY_STABLE;
$plugin->requires = 2016052300; // Moodle 3.1 release and upwards.
$plugin->component = 'local_metadata';