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

Workflow configuration panel during upload #390

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
2 changes: 1 addition & 1 deletion .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ jobs:
with:
requires-tool-plugin: true
requires-mod-plugin: true
branch-tool-plugin: master
branch-tool-plugin: oc-16-support
branch-mod-plugin: master
11 changes: 10 additions & 1 deletion addvideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
use block_opencast\local\upload_helper;
use core\output\notification;
use tool_opencast\local\settings_api;
use block_opencast\local\workflowconfiguration_helper;

require_once('../../config.php');

global $PAGE, $OUTPUT, $CFG, $USER, $SITE, $DB;
Expand Down Expand Up @@ -268,8 +270,15 @@
json_encode($data->scheduledvisibilitygroups) : null;
}

// Prepare user defined workflow configurations if enabled and exist.
$workflowconfiguration = null;
$wfconfighelper = workflowconfiguration_helper::get_instance($ocinstanceid);
if ($configpaneldata = $wfconfighelper->get_userdefined_configuration_data($data)) {
$workflowconfiguration = json_encode($configpaneldata);
}

// Update all upload jobs.
upload_helper::save_upload_jobs($ocinstanceid, $courseid, $options, $visibility);
upload_helper::save_upload_jobs($ocinstanceid, $courseid, $options, $visibility, $workflowconfiguration);
redirect($redirecturl, get_string('uploadjobssaved', 'block_opencast'), null, notification::NOTIFY_SUCCESS);
}

Expand Down
11 changes: 10 additions & 1 deletion batchupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use block_opencast\local\upload_helper;
use core\output\notification;
use tool_opencast\local\settings_api;
use block_opencast\local\workflowconfiguration_helper;

require_once('../../config.php');

global $PAGE, $OUTPUT, $CFG, $USER, $SITE, $DB;
Expand Down Expand Up @@ -243,6 +245,13 @@
json_encode($data->scheduledvisibilitygroups) : null;
}

// Prepare user defined workflow configurations if enabled and exist.
$workflowconfiguration = null;
$wfconfighelper = workflowconfiguration_helper::get_instance($ocinstanceid);
if ($configpaneldata = $wfconfighelper->get_userdefined_configuration_data($data)) {
$workflowconfiguration = json_encode($configpaneldata);
}

$error = null;
$totalfiles = count($batchuploadedfiles);
// Loop through the files and proceed with the upload and cleanup records.
Expand Down Expand Up @@ -284,7 +293,7 @@
$options->presenter = $newfile->get_itemid();

// Save the upload job.
upload_helper::save_upload_jobs($ocinstanceid, $courseid, $options, $visibility);
upload_helper::save_upload_jobs($ocinstanceid, $courseid, $options, $visibility, $workflowconfiguration);
} catch (moodle_exception $e) {
$errorcount++;
}
Expand Down
17 changes: 17 additions & 0 deletions classes/local/addvideo_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function definition() {
$ocinstanceid = $this->_customdata['ocinstanceid'];
$apibridge = apibridge::get_instance($ocinstanceid);
$eventdefaults = $this->_customdata['eventdefaults'];
$wfconfighelper = workflowconfiguration_helper::get_instance($ocinstanceid);

$usechunkupload = class_exists('\local_chunkupload\chunkupload_form_element')
&& get_config('block_opencast', 'enablechunkupload_' . $ocinstanceid);
Expand Down Expand Up @@ -309,6 +310,22 @@ public function definition() {
}
}

// Offering workflow configuration panel settings.
if ($wfconfighelper->can_provide_configuration_panel()) {
$mform->closeHeaderBefore('configurationpanel_header');
$mform->addElement('header', 'configurationpanel_header', get_string('configurationpanel_header', 'block_opencast'));
$mform->setExpanded('configurationpanel_header', true);

$configpanelexplanation = html_writer::tag('p', get_string('configurationpanelheader_explanation', 'block_opencast'));
$mform->addElement('html', $configpanelexplanation);

$renderer->render_configuration_panel_form_elements(
$mform,
$wfconfighelper->get_upload_workflow_configuration_panel(),
$wfconfighelper->get_allowed_upload_configurations()
);
}

$mform->closeHeaderBefore('upload_filepicker');

$mform->addElement('header', 'upload_filepicker', get_string('upload', 'block_opencast'));
Expand Down
31 changes: 27 additions & 4 deletions classes/local/apibridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,13 @@ public function ingest_add_attachment($mediapackage, $flavor, $file) {
* Ingests a mediapackage.
* @param string $mediapackage Mediapackage
* @param string $uploadworkflow workflow definition is to start after ingest
* @param array $workflowconfiguration workflow configuration as array
* @return string Workflow instance that was started
* @throws dml_exception
* @throws moodle_exception
* @throws opencast_connection_exception
*/
public function ingest($mediapackage, $uploadworkflow = '') {
public function ingest($mediapackage, $uploadworkflow = '', $workflowconfiguration = []) {
$ingestapi = $this->get_ingest_api();

if (empty($uploadworkflow)) {
Expand All @@ -268,9 +269,9 @@ public function ingest($mediapackage, $uploadworkflow = '') {
$uploadtimeout = get_config('block_opencast', 'uploadtimeout');
if ($uploadtimeout !== false) {
$timeout = intval($uploadtimeout);
$response = $ingestapi->setRequestTimeout($timeout)->ingest($mediapackage, $uploadworkflow);
$response = $ingestapi->setRequestTimeout($timeout)->ingest($mediapackage, $uploadworkflow, '', $workflowconfiguration);
} else {
$response = $ingestapi->ingest($mediapackage, $uploadworkflow);
$response = $ingestapi->ingest($mediapackage, $uploadworkflow, '', $workflowconfiguration);
}

$code = $response['code'];
Expand Down Expand Up @@ -1167,6 +1168,7 @@ public function create_event($job) {
global $DB;

$event = new event();
$wfconfighelper = workflowconfiguration_helper::get_instance($this->ocinstanceid);

// Get initial visibility object.
$initialvisibility = visibility_helper::get_initial_visibility($job);
Expand Down Expand Up @@ -1216,7 +1218,8 @@ public function create_event($job) {

$acl = $event->get_json_acl();
$metadata = $event->get_meta_data();
$processing = $event->get_processing($this->ocinstanceid);
$processingdata = $wfconfighelper->get_workflow_processing_data($job->workflowconfiguration);
$processing = $processingdata['processing_json'];
$scheduling = '';
$presenter = null;
$presentation = null;
Expand Down Expand Up @@ -1883,6 +1886,26 @@ public function get_workflow_definition($id) {
return false;
}

/**
* Retrieves a workflow instance from Opencast.
* @param string $id Workflow instance id
* @param bool $withoperations flag to get instance with operations
* @param bool $withconfiguration flag to get instance with configurations
* @return false|mixed Workflow instance or false if not successful
*/
public function get_workflow_instance($id, $withoperations = false, $withconfiguration = true) {
$response = $this->api->opencastapi->workflowsApi->get(
$id,
$withoperations,
$withconfiguration
);
if ($response['code'] === 200) {
return $response['body'];
}

return false;
}

/**
* Helperfunction to get the list of available workflows to be used in the plugin's settings.
*
Expand Down
17 changes: 17 additions & 0 deletions classes/local/batchupload_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function definition() {
$ocinstanceid = $this->_customdata['ocinstanceid'];
$apibridge = apibridge::get_instance($ocinstanceid);
$eventdefaults = $this->_customdata['eventdefaults'];
$wfconfighelper = new workflowconfiguration_helper($ocinstanceid);

$mform = $this->_form;

Expand Down Expand Up @@ -286,6 +287,22 @@ public function definition() {
}
}

// Offering workflow configuration panel settings.
if ($wfconfighelper->can_provide_configuration_panel()) {
$mform->closeHeaderBefore('configurationpanel_header');
$mform->addElement('header', 'configurationpanel_header', get_string('configurationpanel_header', 'block_opencast'));
$mform->setExpanded('configurationpanel_header', true);

$configpanelexplanation = html_writer::tag('p', get_string('configurationpanelheader_explanation', 'block_opencast'));
$mform->addElement('html', $configpanelexplanation);

$renderer->render_configuration_panel_form_elements(
$mform,
$wfconfighelper->get_upload_workflow_configuration_panel(),
$wfconfighelper->get_allowed_upload_configurations()
);
}

// Batch Upload section.
$mform->closeHeaderBefore('batchupload_form_header');

Expand Down
8 changes: 7 additions & 1 deletion classes/local/ingest_uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ingest_uploader {
public static function create_event($job) {
global $DB;
$apibridge = apibridge::get_instance($job->ocinstanceid);
$wfconfighelper = workflowconfiguration_helper::get_instance($job->ocinstanceid);

switch ($job->status) {
case self::STATUS_INGEST_CREATING_MEDIA_PACKAGE:
Expand Down Expand Up @@ -216,7 +217,10 @@ public static function create_event($job) {
}
case self::STATUS_INGEST_INGESTING:
try {
$workflow = $apibridge->ingest($job->mediapackage);
// Prepare workflow configuration beforehand.
$processingdata = $wfconfighelper->get_workflow_processing_data($job->workflowconfiguration);
$workflowconfiguration = $processingdata['configuration'];
$workflow = $apibridge->ingest($job->mediapackage, '', $workflowconfiguration);
mtrace('... video uploaded');
// Move on to next status.
self::update_status_with_mediapackage($job, upload_helper::STATUS_UPLOADED);
Expand All @@ -228,6 +232,8 @@ public static function create_event($job) {
$event = new stdClass();
$event->identifier = $values[array_search('MP:MEDIAPACKAGE',
array_column($values, 'tag'))]['attributes']['ID'];
$event->workflowid = $values[array_search('MP:WORKFLOW',
array_column($values, 'tag'))]['attributes']['ID'];

return $event;
} catch (opencast_connection_exception $e) {
Expand Down
11 changes: 10 additions & 1 deletion classes/local/upload_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ public static function get_upload_jobs($ocinstanceid, $courseid) {
* @param int $courseid Course id
* @param object $options Options
* @param object $visibility Visibility object
* @param string $workflowconfiguration Workflow configuration
*/
public static function save_upload_jobs($ocinstanceid, $courseid, $options, $visibility = null) {
public static function save_upload_jobs($ocinstanceid, $courseid, $options, $visibility = null,
$workflowconfiguration = null) {
global $DB, $USER;

// Find the current files for the jobs.
Expand Down Expand Up @@ -224,6 +226,12 @@ public static function save_upload_jobs($ocinstanceid, $courseid, $options, $vis
$job->timecreated = time();
$job->timemodified = $job->timecreated;
$job->ocinstanceid = $ocinstanceid;

// Add workflow processing data to the uploadjob as json string.
if (!empty($workflowconfiguration)) {
$job->workflowconfiguration = $workflowconfiguration;
}

$uploadjobid = $DB->insert_record('block_opencast_uploadjob', $job);

$options->uploadjobid = $uploadjobid;
Expand Down Expand Up @@ -605,6 +613,7 @@ protected function process_upload_job($job) {
if ($event) {
$stepsuccessful = true;
$job->opencasteventid = $event->identifier;
$job->workflowid = (int) $event->workflowid;
$DB->update_record('block_opencast_uploadjob', $job);
}
break;
Expand Down
Loading
Loading