Skip to content
Snippets Groups Projects
Commit 45e86f80 authored by Justus Dieckmann's avatar Justus Dieckmann
Browse files

Add new table delayed_workflow and rollbackdelay + finishdelay fields to workflow

parent 973a3d95
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,10 @@ class processor {
continue;
}
}
foreach ($triggers as $trigger) {
$lib = lib_manager::get_trigger_lib($trigger->subpluginname);
$lib->course_triggered($course, $trigger->id);
}
// If all trigger instances agree, that they want to trigger a process, we do so.
process_manager::create_process($course->id, $workflow->id);
$counttriggered++;
......
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="admin/tool/lifecycle/db" VERSION="20181219" COMMENT="XMLDB file for Moodle tool/lifecycle"
<XMLDB PATH="admin/tool/lifecycle/db" VERSION="20190625" COMMENT="XMLDB file for Moodle tool/lifecycle"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../lib/xmldb/xmldb.xsd"
>
......@@ -106,10 +106,25 @@
<FIELD NAME="sortindex" TYPE="int" LENGTH="3" NOTNULL="false" SEQUENCE="false" COMMENT="Sortindex for active workflows"/>
<FIELD NAME="manual" TYPE="int" LENGTH="1" NOTNULL="false" SEQUENCE="false" COMMENT="Specifies for active workflows if the workflow is manually or automatically triggered. True, if manual. False, if automatic."/>
<FIELD NAME="displaytitle" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="rollbackdelay" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="finishdelay" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="tool_lifecycle_delayed_workf" COMMENT="List of courses and workflows, for which the next check is delayed until a certain timestamp.">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="20" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="workflowid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="delayeduntil" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false" COMMENT="The timestamp till when the course is delayed with the workflow"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="courseid_fk" TYPE="foreign" FIELDS="courseid" REFTABLE="course" REFFIELDS="id"/>
<KEY NAME="workflowid_fk" TYPE="foreign" FIELDS="workflowid" REFTABLE="workflow" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
\ No newline at end of file
......@@ -327,5 +327,48 @@ function xmldb_tool_lifecycle_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2019053100, 'tool', 'lifecycle');
}
if ($oldversion < 2019062500) {
$duration = get_config(null, 'lifecycle_duration');
// Define field finishdelay to be added to tool_lifecycle_workflow.
$table = new xmldb_table('tool_lifecycle_workflow');
$field = new xmldb_field('finishdelay', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, $duration, 'rollbackdelay');
// Conditionally launch add field finishdelay.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Define field rollbackdelay to be added to tool_lifecycle_workflow.
$field = new xmldb_field('rollbackdelay', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, $duration, 'displaytitle');
// Conditionally launch add field rollbackdelay.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Define table tool_lifecycle_delayed_workf to be created.
$table = new xmldb_table('tool_lifecycle_delayed_workf');
// Adding fields to table tool_lifecycle_delayed_workf.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('courseid', XMLDB_TYPE_INTEGER, '20', null, XMLDB_NOTNULL, null, null);
$table->add_field('workflowid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('delayeduntil', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
// Adding keys to table tool_lifecycle_delayed_workf.
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
$table->add_key('courseid_fk', XMLDB_KEY_FOREIGN, ['courseid'], 'course', ['id']);
$table->add_key('workflowid_fk', XMLDB_KEY_FOREIGN, ['workflowid'], 'workflow', ['id']);
// Conditionally launch create table for tool_lifecycle_delayed_workf.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Lifecycle savepoint reached.
upgrade_plugin_savepoint(true, 2019062500, 'tool', 'lifecycle');
}
return true;
}
\ No newline at end of file
......@@ -23,6 +23,7 @@
* @copyright 2017 Tobias Reischmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lifecycle\trigger;
use tool_lifecycle\response\trigger_response;
......@@ -32,12 +33,14 @@ defined('MOODLE_INTERNAL') || die();
/**
* This class bundles different functions necessary for every trigger of a workflow.
* This class should not be extended directly. Please use base_manual or base_automatic.
*
* @package tool_lifecycle\trigger
*/
abstract class base {
/**
* The return value should be equivalent with the name of the subplugin folder.
*
* @return string technical name of the subplugin
*/
public abstract function get_subpluginname();
......@@ -52,6 +55,7 @@ abstract class base {
/**
* This method can be overriden, to add form elements to the form_step_instance.
* It is called in definition().
*
* @param \MoodleQuickForm $mform
*/
public function extend_add_instance_form_definition($mform) {
......@@ -60,6 +64,7 @@ abstract class base {
/**
* This method can be overriden, to set default values to the form_step_instance.
* It is called in definition_after_data().
*
* @param \MoodleQuickForm $mform
* @param array $settings array containing the settings from the db.
*/
......@@ -68,18 +73,19 @@ abstract class base {
/**
* This method can be overriden, to add additional data validation to the instance form.
*
* @param $error
* @param $data
*/
public function extend_add_instance_form_validation(&$error, $data) {
}
/**
* If true, the trigger can be used to manually define workflows, based on an instance of this trigger.
* This has to be combined with installing the workflow in db/install.php of the trigger plugin.
* If false, at installation the trigger will result in a preset workflow, which can not be changed.
* This is for instance relevant for the sitecourse trigger or the delayedcourses trigger.
*
* @return bool
*/
public function has_multiple_instances() {
......@@ -88,29 +94,40 @@ abstract class base {
/**
* Specifies if the trigger is a manual or an automatic trigger.
*
* @return boolean
*/
public abstract function is_manual_trigger();
/**
* Returns the status message for the trigger.
*
* @return string status message
*/
public function get_status_message() {
return get_string("workflow_started", "tool_lifecycle");
}
/**
* Function is called when all trigger decide on triggering a course.
* For cleanup purposes.
*/
public function course_triggered($course, $triggerid) {
}
}
/**
* This class represents an automatic trigger.
* It is used when workflow should be started based on a specific logic.
*
* @package tool_lifecycle\trigger
*/
abstract class base_automatic extends base {
/**
* Checks the course and returns a repsonse, which tells if the course should be further processed.
*
* @param $course object to be processed.
* @param $triggerid int id of the trigger instance.
* @return trigger_response
......@@ -136,6 +153,7 @@ abstract class base_automatic extends base {
/**
* This class represents a manual trigger.
* It is used to enable user to manually start processes for workflows.
*
* @package tool_lifecycle\trigger
*/
abstract class base_manual extends base {
......@@ -144,8 +162,10 @@ abstract class base_manual extends base {
return true;
}
}
/**
* Class representing a local settings object for a subplugin instance.
*
* @package tool_lifecycle\trigger
*/
class instance_setting {
......@@ -158,6 +178,7 @@ class instance_setting {
/**
* Create a local settings object.
*
* @param string $name name of the setting
* @param string $paramtype param type. Used for cleansing and parsing, e.g. PARAM_INT.
*/
......
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die;
$plugin->maturity = MATURITY_ALPHA;
$plugin->version = 2019053100;
$plugin->version = 2019062500;
$plugin->component = 'tool_lifecycle';
$plugin->requires = 2017111300; // Require Moodle 3.4 (or above).
$plugin->release = 'v3.6-r1';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment