Check in initial version
This commit is contained in:
commit
32bf8be85c
6 changed files with 141 additions and 0 deletions
18
db/access.php
Normal file
18
db/access.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$capabilities = array(
|
||||
|
||||
'local/replication:replicate' => array(
|
||||
'riskbitmask' => RISK_DATALOSS,
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
'archetypes' => array(
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'manager' => CAP_ALLOW
|
||||
),
|
||||
'clonepermissionsfrom' => 'moodle/course:manageactivities'
|
||||
)
|
||||
|
||||
);
|
11
lang/en/local_replication.php
Normal file
11
lang/en/local_replication.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$string['modulename'] = 'Replication';
|
||||
$string['modulenameplural'] = $string['modulename'];
|
||||
$string['pluginname'] = $string['modulename'];
|
||||
|
||||
$string['settings'] = 'Settings';
|
||||
|
||||
$string['directory'] = 'Directory to dump exports to';
|
35
settings.php
Normal file
35
settings.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?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/>.
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
if ($hassiteconfig) {
|
||||
$ADMIN->add('localplugins', new admin_category('local_replication_settings', new lang_string('pluginname', 'local_replication')));
|
||||
$settingspage = new admin_settingpage('local_replication', new lang_string('pluginname', 'local_replication'));
|
||||
|
||||
if ($ADMIN->fulltree) {
|
||||
$settingspage->add(new admin_setting_configtext(
|
||||
'local_replication/directory',
|
||||
new lang_string('directory', 'local_replication'),
|
||||
new lang_string('directory_help', 'local_replication'),
|
||||
1
|
||||
));
|
||||
}
|
||||
|
||||
$ADMIN->add('localplugins', $settingspage);
|
||||
}
|
||||
|
||||
|
12
test.php
Normal file
12
test.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
require_once("../../config.php");
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
|
||||
$id = $_GET["id"];
|
||||
$course = get_course($id);
|
||||
|
||||
$replicationconfig = get_config('local_replication');
|
||||
$directory = $replicationconfig->directory;
|
||||
|
||||
$context = context_course::instance($id);
|
||||
|
56
trigger.php
Normal file
56
trigger.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
require_once("../../config.php");
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
|
||||
$id = $_GET["id"];
|
||||
$course = get_course($id);
|
||||
|
||||
$replicationconfig = get_config('local_replication');
|
||||
$directory = $replicationconfig->directory;
|
||||
|
||||
$context = context_course::instance($id);
|
||||
|
||||
if (!has_capability('local/replication:replicate', $context)) {
|
||||
die("User not allowed to trigger replication!");
|
||||
}
|
||||
|
||||
$bc = new backup_controller(\backup::TYPE_1COURSE, $id, backup::FORMAT_MOODLE,
|
||||
backup::INTERACTIVE_YES, backup::MODE_GENERAL, $USER->id);
|
||||
|
||||
$tasks = $bc->get_plan()->get_tasks();
|
||||
foreach ($tasks as &$task) {
|
||||
if ($task instanceof \backup_root_task) {
|
||||
$setting = $task->get_setting('users');
|
||||
$setting->set_value('0');
|
||||
$setting = $task->get_setting('anonymize');
|
||||
$setting->set_value('1');
|
||||
$setting = $task->get_setting('role_assignments');
|
||||
$setting->set_value('0');
|
||||
$setting = $task->get_setting('filters');
|
||||
$setting->set_value('0');
|
||||
$setting = $task->get_setting('comments');
|
||||
$setting->set_value('0');
|
||||
$setting = $task->get_setting('logs');
|
||||
$setting->set_value('0');
|
||||
$setting = $task->get_setting('grade_histories');
|
||||
$setting->set_value('0');
|
||||
}
|
||||
}
|
||||
|
||||
$filename = $directory . '/course_' . $id . "_" . $course->category . "_" . date('U') . '.mbz';
|
||||
|
||||
$bc->set_status(backup::STATUS_AWAITING);
|
||||
$bc->execute_plan();
|
||||
|
||||
$result = $bc->get_results();
|
||||
|
||||
if(isset($result['backup_destination']) && $result['backup_destination']) {
|
||||
$file = $result['backup_destination'];
|
||||
|
||||
if(!$file->copy_content_to($filename)) {
|
||||
echo("Problems copying final backup to '". $filename . "'");
|
||||
}
|
||||
}
|
||||
|
||||
echo('Course is now getting replicated. <a href="javascript:history.back();">Back to Course Administration</a>');
|
||||
|
9
version.php
Normal file
9
version.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = "2021120101";
|
||||
$plugin->component = 'local_replication';
|
||||
$plugin->maturity = MATURITY_ALPHA;
|
||||
$plugin->release = 'v0.0.1';
|
||||
$plugin->requires = '2019111800';
|
Loading…
Reference in a new issue