Skip to content
Snippets Groups Projects
Unverified Commit a2491130 authored by Tobias Reischmann's avatar Tobias Reischmann
Browse files

Integrate backup and restore of workflows into adminsettings

parent e3830b8d
No related branches found
No related tags found
No related merge requests found
......@@ -18,8 +18,10 @@ namespace tool_lifecycle;
use tool_lifecycle\entity\trigger_subplugin;
use tool_lifecycle\form\form_workflow_instance;
use tool_lifecycle\form\form_upload_workflow;
use tool_lifecycle\form\form_step_instance;
use tool_lifecycle\form\form_trigger_instance;
use tool_lifecycle\local\backup\restore_lifecycle_workflow;
use tool_lifecycle\manager\step_manager;
use tool_lifecycle\manager\settings_manager;
use tool_lifecycle\manager\trigger_manager;
......@@ -166,6 +168,10 @@ class admin_settings {
array('action' => ACTION_WORKFLOW_INSTANCE_FROM, 'sesskey' => sesskey())),
get_string('add_workflow', 'tool_lifecycle'));
echo $OUTPUT->single_button(new \moodle_url($PAGE->url,
array('action' => ACTION_WORKFLOW_UPLOAD_FROM, 'sesskey' => sesskey())),
get_string('upload_workflow', 'tool_lifecycle'));
$table = new workflow_definition_table('tool_lifecycle_workflow_definitions');
echo $OUTPUT->box_start("lifecycle-enable-overflow lifecycle-table");
$table->out(10, false);
......@@ -239,8 +245,10 @@ class admin_settings {
* This is the entry point for this controller class.
*/
public function execute($action, $workflowid) {
global $PAGE;
global $PAGE, $CFG, $OUTPUT;
$this->check_permissions();
/** @var \tool_lifecycle_renderer $renderer */
$renderer = $PAGE->get_renderer('tool_lifecycle');
// Has to be called before moodleform is created!
admin_externalpage_setup('tool_lifecycle_adminsettings');
......@@ -248,10 +256,13 @@ class admin_settings {
workflow_manager::handle_action($action, $workflowid);
$form = new form_workflow_instance($PAGE->url, workflow_manager::get_workflow($workflowid));
$uploadform = new form_upload_workflow($PAGE->url);
$PAGE->set_title(get_string('adminsettings_edit_workflow_definition_heading', 'tool_lifecycle'));
if ($action === ACTION_WORKFLOW_INSTANCE_FROM) {
$this->view_workflow_instance_form($form);
} else if ($action === ACTION_WORKFLOW_UPLOAD_FROM) {
$renderer->render_workflow_upload_form($uploadform);
} else {
if ($form->is_submitted() && !$form->is_cancelled() && $data = $form->get_submitted_data()) {
if ($data->id) {
......@@ -270,6 +281,15 @@ class admin_settings {
return;
}
}
if ($uploadform->is_submitted() && !$uploadform->is_cancelled() && $data = $uploadform->get_submitted_data()) {
$xmldata = $uploadform->get_file_content('backupfile');
$restore = new restore_lifecycle_workflow($xmldata);
$errors = $restore->execute();
if (count($errors) != 0) {
$renderer->render_workflow_upload_form($uploadform, $errors);
return;
}
}
$this->view_plugins_table();
}
}
......
......@@ -28,6 +28,20 @@ require_once(__DIR__.'/../../lib.php');
class settings_manager {
/**
* Saves the local settings for a subplugin step instance.
* @param int $instanceid id of the subplugininstance.
* @param 'step'|'trigger' $type type of the subplugin.
* @param string $subpluginname name of the subplugin.
* @param string $name name of the setting.
* @param mixed $value value of the setting.
* @throws \moodle_exception
*/
public static function save_setting($instanceid, $type, $subpluginname, $name, $value) {
$data = [$name => $value];
self::save_settings($instanceid, $type, $subpluginname, $data);
}
/**
* Saves the local settings for a subplugin step instance.
* @param int $instanceid id of the subplugininstance.
......
......@@ -26,6 +26,8 @@ namespace tool_lifecycle\manager;
use tool_lifecycle\entity\trigger_subplugin;
use tool_lifecycle\entity\workflow;
use tool_lifecycle\local\backup\backup_lifecycle_workflow;
use tool_lifecycle\local\exporter\workflow_exporter;
use tool_lifecycle\local\data\manual_trigger_tool;
defined('MOODLE_INTERNAL') || die();
......@@ -224,6 +226,9 @@ class workflow_manager {
if ($action === ACTION_WORKFLOW_DUPLICATE) {
self::duplicate_workflow($workflowid);
}
if ($action === ACTION_WORKFLOW_BACKUP) {
self::backup_workflow($workflowid);
}
if ($action === ACTION_WORKFLOW_DISABLE) {
if (confirm_sesskey()) {
self::disable($workflowid);
......@@ -381,6 +386,17 @@ class workflow_manager {
return $newworkflow;
}
/**
* Calls the backup process for the workflow, which will send the workflow structure with all
* subplugins as a xml file to the client.
* @param int $workflowid id of the workflow to be backed up.
* @throws \moodle_exception
*/
public static function backup_workflow($workflowid) {
$task = new backup_lifecycle_workflow($workflowid);
$task->execute();
}
/**
* Checks if it should be possible to disable a workflow
*
......
......@@ -105,6 +105,11 @@ class workflow_definition_table extends workflow_table {
$icon = 't/copy';
$output .= $this->format_icon_link($action, $row->id, $icon, $alt);
$action = ACTION_WORKFLOW_BACKUP;
$alt = get_string('backupworkflow', 'tool_lifecycle');
$icon = 't/backup';
$output .= $this->format_icon_link($action, $row->id, $icon, $alt);
$action = ACTION_WORKFLOW_INSTANCE_FROM;
$alt = get_string('editworkflow', 'tool_lifecycle');
$icon = 't/edit';
......
......@@ -67,6 +67,7 @@ $string['trigger_sortindex'] = 'Up/Down';
$string['trigger_workflow'] = 'Workflow';
$string['add_workflow'] = 'Add Workflow';
$string['upload_workflow'] = 'Upload Workflow';
$string['workflow_title'] = 'Title';
$string['workflow_title_help'] = 'Workflow title (visible for admins only).';
$string['workflow_displaytitle'] = 'Displayed workflow title';
......@@ -78,6 +79,7 @@ $string['workflow_sortindex'] = 'Up/Down';
$string['workflow_tools'] = 'Actions';
$string['viewsteps'] = 'View Workflow Steps';
$string['editworkflow'] = 'Edit Title';
$string['backupworkflow'] = 'Backup Workflow';
$string['duplicateworkflow'] = 'Duplicate Workflow';
$string['deleteworkflow'] = 'Delete Workflow';
$string['deleteworkflow_confirm'] = 'The workflow is going to be deleted. This can\'t be undone. Are you sure?';
......@@ -144,3 +146,9 @@ $string['manual_trigger_process_existed'] = 'A workflow for this course already
$string['workflow_started'] = 'Workflow started.';
$string['workflow_is_running'] = 'Workflow is running.';
// Backup & Restore
$string['restore_workflow_not_found'] = 'Wrong format of the backup file. The workflow could not be found.';
$string['restore_subplugins_invalid'] = 'Wrong format of the backup file. The structure of the subplugin elements is not as expected.';
$string['restore_step_does_not_exist'] = 'The step {$a} is not installed, but is included in the backup file. Please installed it first and try again.';
$string['restore_trigger_does_not_exist'] = 'The trigger {$a} is not installed, but is included in the backup file. Please installed it first and try again.';
\ No newline at end of file
......@@ -38,6 +38,8 @@ define('ACTION_TRIGGER_INSTANCE_FORM', 'trigger_instance_form');
define('ACTION_TRIGGER_INSTANCE_DELETE', 'trigger_instance_delete');
define('ACTION_STEP_INSTANCE_DELETE', 'step_instance_delete');
define('ACTION_WORKFLOW_INSTANCE_FROM', 'workflow_instance_form');
define('ACTION_WORKFLOW_UPLOAD_FROM', 'workflow_upload_form');
define('ACTION_WORKFLOW_BACKUP', 'workflow_instance_backup');
define('ACTION_WORKFLOW_DELETE', 'workflow_instance_delete');
define('ACTION_WORKFLOW_DUPLICATE', 'workflow_instance_duplicate');
define('ACTION_WORKFLOW_ACTIVATE', 'workflow_instance_activate');
......
......@@ -40,10 +40,29 @@ class tool_lifecycle_renderer extends plugin_renderer_base {
*
* @return string
*/
public function header() {
public function header($title) {
global $OUTPUT, $PAGE;
echo $OUTPUT->header();
if ($title) {
echo $OUTPUT->heading($title);
} else {
echo $OUTPUT->heading($PAGE->heading);
}
}
/**
* Renders the workflow upload form including errors, which occured during upload.
* @param \tool_lifecycle\form\form_upload_workflow $form
* @param array $errors
*/
public function render_workflow_upload_form($form, $errors = array()) {
global $OUTPUT;
$this->header(get_string('adminsettings_edit_workflow_definition_heading', 'tool_lifecycle'));
foreach ($errors as $error) {
echo $OUTPUT->notification($error);
}
echo $form->render();
$this->footer();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment