From 6c5a78224566a5af2e7b040cae816b77b279b54f Mon Sep 17 00:00:00 2001 From: ferishili Date: Mon, 16 Dec 2024 15:59:13 +0100 Subject: [PATCH 1/7] using new opencast api exception from tool_opencast --- block_opencast.php | 4 +- classes/local/addvideo_form.php | 6 +- classes/local/apibridge.php | 150 ++++++++++------------ classes/local/batchupload_form.php | 6 +- classes/local/ingest_uploader.php | 14 +- classes/opencast_connection_exception.php | 39 ------ classes/setting_helper.php | 5 +- index.php | 4 +- settings.php | 10 +- 9 files changed, 96 insertions(+), 142 deletions(-) delete mode 100644 classes/opencast_connection_exception.php diff --git a/block_opencast.php b/block_opencast.php index 63868e51..02c94fac 100644 --- a/block_opencast.php +++ b/block_opencast.php @@ -23,7 +23,7 @@ */ use block_opencast\local\apibridge; -use block_opencast\opencast_connection_exception; +use tool_opencast\exception\opencast_api_response_exception; use tool_opencast\local\settings_api; use tool_opencast\seriesmapping; @@ -133,7 +133,7 @@ public function get_content() { $apibridge = apibridge::get_instance($instance->id); $videos[$instance->id] = $apibridge->get_block_videos($COURSE->id); } - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { $videos[$instance->id] = new stdClass(); $videos[$instance->id]->error = $e->getMessage(); } diff --git a/classes/local/addvideo_form.php b/classes/local/addvideo_form.php index 1137d82d..e9e56ba7 100644 --- a/classes/local/addvideo_form.php +++ b/classes/local/addvideo_form.php @@ -25,7 +25,7 @@ namespace block_opencast\local; -use block_opencast\opencast_connection_exception; +use tool_opencast\exception\opencast_api_response_exception; use block_opencast_renderer; use coding_exception; use core\notification; @@ -102,7 +102,7 @@ public function definition() { foreach ($seriesrecords as $series) { $seriesoption[$series->identifier] = $series->title; } - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { notification::warning($e->getMessage()); foreach ($seriesrecords as $series) { $seriesoption[$series->series] = $series->series; @@ -119,7 +119,7 @@ public function definition() { foreach ($seriesrecords as $series) { $seriesoption[$series->identifier] = $series->title; } - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { notification::warning($e->getMessage()); $seriesoption[$this->_customdata['series']] = $this->_customdata['series']; } diff --git a/classes/local/apibridge.php b/classes/local/apibridge.php index fe7d1b9e..75e4e7c7 100644 --- a/classes/local/apibridge.php +++ b/classes/local/apibridge.php @@ -28,7 +28,7 @@ defined('MOODLE_INTERNAL') || die(); use block_opencast\groupaccess; -use block_opencast\opencast_connection_exception; +use tool_opencast\exception\opencast_api_response_exception; use block_opencast\task\process_duplicated_event_visibility_change; use block_opencast_apibridge_testable; use block_opencast_renderer; @@ -142,12 +142,18 @@ public function check_api_configuration() { * @return OcIngest * @throws dml_exception * @throws moodle_exception - * @throws opencast_connection_exception + * @throws opencast_api_response_exception */ private function get_ingest_api() { $this->api = api::get_instance($this->ocinstanceid, [], [], true); if (!property_exists($this->api->opencastapi, 'ingest')) { - throw new opencast_connection_exception('ingest_endpoint_notfound', 'block_opencast'); + throw new opencast_api_response_exception( + [ + 'reason' => 'exception_request_ingest_endpoint_notfound', + 'code' => 404, + ], + false + ); } return $this->api->opencastapi->ingest; } @@ -158,19 +164,18 @@ private function get_ingest_api() { * @return string Newly created mediapackage * @throws dml_exception * @throws moodle_exception - * @throws opencast_connection_exception + * @throws opencast_api_response_exception */ public function ingest_create_media_package() { $ingestapi = $this->get_ingest_api(); $response = $ingestapi->createMediaPackage(); $code = $response['code']; - $mediapackage = $response['body']; - if ($code === 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else if ($code != 200) { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast'); + + if ($code != 200) { + throw new opencast_api_response_exception($response); } + $mediapackage = $response['body']; return $mediapackage; } @@ -182,20 +187,18 @@ public function ingest_create_media_package() { * @return string * @throws dml_exception * @throws moodle_exception - * @throws opencast_connection_exception + * @throws opencast_api_response_exception */ public function ingest_add_catalog($mediapackage, $flavor, $file) { $ingestapi = $this->get_ingest_api(); $response = $ingestapi->addCatalog($mediapackage, $flavor, $file); $code = $response['code']; - $newmediapackage = $response['body']; - if ($code === 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else if ($code != 200) { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast'); + if ($code != 200) { + throw new opencast_api_response_exception($response); } + $newmediapackage = $response['body']; return $newmediapackage; } @@ -207,20 +210,18 @@ public function ingest_add_catalog($mediapackage, $flavor, $file) { * @return string * @throws dml_exception * @throws moodle_exception - * @throws opencast_connection_exception + * @throws opencast_api_response_exception */ public function ingest_add_track($mediapackage, $flavor, $file) { $ingestapi = $this->get_ingest_api(); $response = $ingestapi->addTrack($mediapackage, $flavor, $this->get_upload_filestream($file)); $code = $response['code']; - $newmediapackage = $response['body']; - if ($code === 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else if ($code != 200) { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast'); + if ($code != 200) { + throw new opencast_api_response_exception($response); } + $newmediapackage = $response['body']; return $newmediapackage; } @@ -232,20 +233,18 @@ public function ingest_add_track($mediapackage, $flavor, $file) { * @return string * @throws dml_exception * @throws moodle_exception - * @throws opencast_connection_exception + * @throws opencast_api_response_exception */ public function ingest_add_attachment($mediapackage, $flavor, $file) { $ingestapi = $this->get_ingest_api(); $response = $ingestapi->addAttachment($mediapackage, $flavor, $file); $code = $response['code']; - $newmediapackage = $response['body']; - if ($code === 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else if ($code != 200) { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast'); + if ($code != 200) { + throw new opencast_api_response_exception($response); } + $newmediapackage = $response['body']; return $newmediapackage; } @@ -257,7 +256,7 @@ public function ingest_add_attachment($mediapackage, $flavor, $file) { * @return string Workflow instance that was started * @throws dml_exception * @throws moodle_exception - * @throws opencast_connection_exception + * @throws opencast_api_response_exception */ public function ingest($mediapackage, $uploadworkflow = '', $workflowconfiguration = []) { $ingestapi = $this->get_ingest_api(); @@ -275,14 +274,12 @@ public function ingest($mediapackage, $uploadworkflow = '', $workflowconfigurati } $code = $response['code']; - $workflow = $response['body']; - if ($code === 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else if ($code != 200) { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast'); + if ($code != 200) { + throw new opencast_api_response_exception($response); } + $workflow = $response['body']; return $workflow; } @@ -356,10 +353,8 @@ public function get_block_videos($courseid, $withmetadata = false) { $response = $this->api->opencastapi->eventsApi->getBySeries($s->series, $params); $code = $response['code']; - if ($code === 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else if ($code != 200) { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast'); + if ($code != 200) { + throw new opencast_api_response_exception($response); } $videos = $response['body']; @@ -773,10 +768,8 @@ public function get_multiple_series_by_identifier($allseries) { $response = $this->api->opencastapi->seriesApi->getAll($params); $code = $response['code']; - if ($code === 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else if ($code != 200) { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast'); + if ($code != 200) { + throw new opencast_api_response_exception($response); } $series = $response['body']; @@ -1836,34 +1829,33 @@ public function get_existing_workflows($tags = [], $onlynames = true, $withconfi $response = $this->api->opencastapi->workflowsApi->getAllDefinitions($queryparams); $code = $response['code']; - if ($code === 200) { - $returnedworkflows = $response['body']; - - // Lookup and filter workflow definitions by tags. - if (count($tags) > 1) { - $returnedworkflows = array_filter($returnedworkflows, function ($wd) use ($tags) { - return !empty(array_intersect($wd->tags, $tags)); - }); - } - if (!$onlynames) { - return $returnedworkflows; - } + if ($code != 200) { + throw new opencast_api_response_exception($response); + } - foreach ($returnedworkflows as $workflow) { + $returnedworkflows = $response['body']; - if (object_property_exists($workflow, 'title') && !empty($workflow->title)) { - $workflows[$workflow->identifier] = $workflow->title; - } else { - $workflows[$workflow->identifier] = $workflow->identifier; - } + // Lookup and filter workflow definitions by tags. + if (count($tags) > 1) { + $returnedworkflows = array_filter($returnedworkflows, function ($wd) use ($tags) { + return !empty(array_intersect($wd->tags, $tags)); + }); + } + + if (!$onlynames) { + return $returnedworkflows; + } + + foreach ($returnedworkflows as $workflow) { + + if (object_property_exists($workflow, 'title') && !empty($workflow->title)) { + $workflows[$workflow->identifier] = $workflow->title; + } else { + $workflows[$workflow->identifier] = $workflow->identifier; } - return $workflows; - } else if ($code == 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast', '', null, $code); } + return $workflows; } /** @@ -2851,16 +2843,16 @@ public function get_lti_consumersecret() { * @return string event's mediapackage * @throws dml_exception * @throws moodle_exception - * @throws opencast_connection_exception + * @throws opencast_api_response_exception */ public function get_event_media_package($eventid) { $response = $this->api->opencastrestclient->performGet("/api/episode/{$eventid}"); $code = $response['code']; - if ($code === 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else if ($code != 200) { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast'); + + if ($code != 200) { + throw new opencast_api_response_exception($response); } + $mediapackage = $response['body']; return $mediapackage; } @@ -2948,16 +2940,17 @@ public function set_duplicated_event_visibility($duplicatedeventid, $sourceevent * Get the opencast version. * * @return string semantic version number of the opencast server. + * @throws opencast_api_response_exception */ public function get_opencast_version() { $response = $this->api->opencastapi->sysinfo->getVersion(); $code = $response['code']; - $versionobject = $response['body']; - if ($code === 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else if ($code != 200) { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast'); + + if ($code != 200) { + throw new opencast_api_response_exception($response); } + + $versionobject = $response['body']; return $versionobject->version; } @@ -2971,15 +2964,14 @@ public function get_opencast_version() { * @param boolean $overwrite whether to overwrite the existing one. * * @return boolean true, if the track is added. - * @throws opencast_connection_exception + * @throws opencast_api_response_exception */ public function event_add_track($identifier, $flavor, $file, $overwrite = true) { $response = $this->api->opencastapi->eventsApi->addTrack($identifier, $flavor, $file, $overwrite); $code = $response['code']; - if ($code === 0) { - throw new opencast_connection_exception('connection_failure', 'block_opencast'); - } else if ($code != 200) { - throw new opencast_connection_exception('unexpected_api_response', 'block_opencast'); + + if ($code != 200) { + throw new opencast_api_response_exception($response); } return true; } diff --git a/classes/local/batchupload_form.php b/classes/local/batchupload_form.php index b770ac5a..fb6a5bed 100644 --- a/classes/local/batchupload_form.php +++ b/classes/local/batchupload_form.php @@ -25,7 +25,7 @@ namespace block_opencast\local; -use block_opencast\opencast_connection_exception; +use tool_opencast\exception\opencast_api_response_exception; use block_opencast_renderer; use coding_exception; use core\notification; @@ -90,7 +90,7 @@ public function definition() { foreach ($seriesrecords as $series) { $seriesoption[$series->identifier] = $series->title; } - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { notification::warning($e->getMessage()); foreach ($seriesrecords as $series) { $seriesoption[$series->series] = $series->series; @@ -107,7 +107,7 @@ public function definition() { foreach ($seriesrecords as $series) { $seriesoption[$series->identifier] = $series->title; } - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { notification::warning($e->getMessage()); $seriesoption[$this->_customdata['series']] = $this->_customdata['series']; } diff --git a/classes/local/ingest_uploader.php b/classes/local/ingest_uploader.php index 8ee5ade4..7a94e637 100644 --- a/classes/local/ingest_uploader.php +++ b/classes/local/ingest_uploader.php @@ -23,7 +23,7 @@ namespace block_opencast\local; -use block_opencast\opencast_connection_exception; +use tool_opencast\exception\opencast_api_response_exception; use block_opencast\opencast_state_exception; use coding_exception; use DateTime; @@ -84,7 +84,7 @@ public static function create_event($job) { // Move on to next status. self::update_status_with_mediapackage($job, self::STATUS_INGEST_ADDING_EPISODE_CATALOG, true, false, false, $mediapackage); - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { mtrace('... failed to create media package'); mtrace($e->getMessage()); break; @@ -102,7 +102,7 @@ public static function create_event($job) { self::update_status_with_mediapackage($job, self::STATUS_INGEST_ADDING_FIRST_TRACK, true, false, false, $mediapackage); - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { mtrace('... failed to add episode metadata'); mtrace($e->getMessage()); break; @@ -145,7 +145,7 @@ public static function create_event($job) { self::update_status_with_mediapackage($job, self::STATUS_INGEST_ADDING_SECOND_TRACK, true, false, false, $mediapackage); - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { mtrace('... failed upload presenter'); mtrace($e->getMessage()); break; @@ -189,7 +189,7 @@ public static function create_event($job) { self::update_status_with_mediapackage($job, self::STATUS_INGEST_ADDING_ACL_ATTACHMENT, true, false, false, $mediapackage); - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { mtrace('... failed upload presentation'); mtrace($e->getMessage()); break; @@ -210,7 +210,7 @@ public static function create_event($job) { self::update_status_with_mediapackage($job, self::STATUS_INGEST_INGESTING, true, false, false, $mediapackage); - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { mtrace('... failed to add acl'); mtrace($e->getMessage()); break; @@ -236,7 +236,7 @@ public static function create_event($job) { array_column($values, 'tag'))]['attributes']['ID']; return $event; - } catch (opencast_connection_exception $e) { + } catch (opencast_api_response_exception $e) { mtrace('... failed to add acl'); mtrace($e->getMessage()); break; diff --git a/classes/opencast_connection_exception.php b/classes/opencast_connection_exception.php deleted file mode 100644 index b4481570..00000000 --- a/classes/opencast_connection_exception.php +++ /dev/null @@ -1,39 +0,0 @@ -. - -/** - * Exception, which is thrown when the opencast server is unreachable or an unexpected response code is returned. - * - * @package block_opencast - * @copyright 2021 Tamara Gunkel, University of Münster - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace block_opencast; - -use moodle_exception; - -/** - * Exception, which is thrown when the opencast server is unreachable or an unexpected response code is returned. - * - * @package block_opencast - * @copyright 2021 Tamara Gunkel, University of Münster - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class opencast_connection_exception extends moodle_exception { - - -} diff --git a/classes/setting_helper.php b/classes/setting_helper.php index e861a6a0..9ad1a377 100644 --- a/classes/setting_helper.php +++ b/classes/setting_helper.php @@ -30,6 +30,7 @@ use Exception; use lang_string; use tool_opencast\empty_configuration_exception; +use tool_opencast\exception\opencast_api_response_exception; /** * Helper class for admin settings. @@ -76,7 +77,7 @@ public static function validate_workflow_setting($data) { * Returns available workflows with the given tag. * @param int $ocinstanceid Opencast instance id. * @param string $workflowtags comma separated list of tags - * @return array|opencast_connection_exception|Exception|empty_configuration_exception|null + * @return array|opencast_api_response_exception|Exception|empty_configuration_exception|null */ public static function load_workflow_choices($ocinstanceid, $workflowtags) { // Don't load anything during initial installation. @@ -93,7 +94,7 @@ public static function load_workflow_choices($ocinstanceid, $workflowtags) { return $apibridge->get_available_workflows_for_menu($workflowtags, true); // Something went wrong and the list of workflows could not be retrieved. - } catch (opencast_connection_exception | empty_configuration_exception $e) { + } catch (opencast_api_response_exception | empty_configuration_exception $e) { return $e; } } diff --git a/index.php b/index.php index f9c2ef0d..e0d4acdb 100644 --- a/index.php +++ b/index.php @@ -29,7 +29,7 @@ use block_opencast\local\ltimodulemanager; use block_opencast\local\massaction_helper; use block_opencast\local\upload_helper; -use block_opencast\opencast_connection_exception; +use tool_opencast\exception\opencast_api_response_exception; use core\notification; use tool_opencast\local\settings_api; require_once('../../config.php'); @@ -59,7 +59,7 @@ $tags = array_map('trim', $tags); $workflows = $apibridge->get_existing_workflows($tags, false); } -} catch (opencast_connection_exception $e) { +} catch (opencast_api_response_exception $e) { $opencasterror = $e->getMessage(); } $workflowsavailable = count($workflows) > 0; diff --git a/settings.php b/settings.php index 1e730221..084928a3 100644 --- a/settings.php +++ b/settings.php @@ -27,7 +27,7 @@ use block_opencast\admin_setting_hiddenhelpbtn; use block_opencast\local\ltimodulemanager; use block_opencast\local\visibility_helper; -use block_opencast\opencast_connection_exception; +use tool_opencast\exception\opencast_api_response_exception; use block_opencast\setting_helper; use block_opencast\setting_default_manager; use core\notification; @@ -202,7 +202,7 @@ get_string('limituploadjobsdesc', 'block_opencast', $link), 1, PARAM_INT)); $workflowchoices = setting_helper::load_workflow_choices($instance->id, 'upload'); - if ($workflowchoices instanceof opencast_connection_exception || + if ($workflowchoices instanceof opencast_api_response_exception || $workflowchoices instanceof empty_configuration_exception) { $opencasterror = $workflowchoices->getMessage(); $workflowchoices = [null => get_string('adminchoice_noconnection', 'block_opencast')]; @@ -259,7 +259,7 @@ $workflowchoices = setting_helper::load_workflow_choices($instance->id, 'delete'); - if ($workflowchoices instanceof opencast_connection_exception || + if ($workflowchoices instanceof opencast_api_response_exception || $workflowchoices instanceof empty_configuration_exception) { $opencasterror = $workflowchoices->getMessage(); $workflowchoices = [null => get_string('adminchoice_noconnection', 'block_opencast')]; @@ -346,7 +346,7 @@ $workflowchoices = setting_helper::load_workflow_choices($instance->id, 'archive'); - if ($workflowchoices instanceof opencast_connection_exception || + if ($workflowchoices instanceof opencast_api_response_exception || $workflowchoices instanceof empty_configuration_exception) { $opencasterror = $workflowchoices->getMessage(); $workflowchoices = [null => get_string('adminchoice_noconnection', 'block_opencast')]; @@ -1042,7 +1042,7 @@ // The default duplicate-event workflow has archive tag, therefore it needs to be adjusted here as well. // As this setting has used api tag for the duplicate event, it is now possible to have multiple tags in here. $workflowchoices = setting_helper::load_workflow_choices($instance->id, 'api,archive'); - if ($workflowchoices instanceof opencast_connection_exception || + if ($workflowchoices instanceof opencast_api_response_exception || $workflowchoices instanceof empty_configuration_exception) { $opencasterror = $workflowchoices->getMessage(); $workflowchoices = [null => get_string('adminchoice_noconnection', 'block_opencast')]; From 4b9f9ce5d93d9c73913f3e9fd73394db03f016d3 Mon Sep 17 00:00:00 2001 From: ferishili Date: Mon, 16 Dec 2024 15:59:21 +0100 Subject: [PATCH 2/7] fix code checker --- classes/local/massaction_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/local/massaction_helper.php b/classes/local/massaction_helper.php index e670d615..0eb6151e 100644 --- a/classes/local/massaction_helper.php +++ b/classes/local/massaction_helper.php @@ -121,7 +121,7 @@ class massaction_helper { * * @throws coding_exception If the default actions are not valid. */ - public function __construct(array $defaultactions = null) { + public function __construct(array $defaultactions = []) { if (!empty($defaultactions)) { $this->massactions = $defaultactions; if (!$this->validate_massactions()) { From 5c1c7cd0166e8daeab20cc9a79c34f9fcb7f69c6 Mon Sep 17 00:00:00 2001 From: ferishili Date: Mon, 16 Dec 2024 16:13:04 +0100 Subject: [PATCH 3/7] adjust tool branch for ci --- .github/workflows/moodle-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index b5880a53..65e297b3 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -12,5 +12,5 @@ jobs: with: requires-tool-plugin: true requires-mod-plugin: true - branch-tool-plugin: oc-16-support + branch-tool-plugin: issue-56 branch-mod-plugin: main From 4f21588e26a263bdc02d4b233b1c509c75ea24fb Mon Sep 17 00:00:00 2001 From: ferishili Date: Tue, 17 Dec 2024 13:13:22 +0100 Subject: [PATCH 4/7] fix and improve dynamic wf config panel issue, fixes #407 as well --- classes/local/workflowconfiguration_helper.php | 12 +++++++++--- renderer.php | 11 ++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/classes/local/workflowconfiguration_helper.php b/classes/local/workflowconfiguration_helper.php index bc3bf345..89d03eb2 100644 --- a/classes/local/workflowconfiguration_helper.php +++ b/classes/local/workflowconfiguration_helper.php @@ -38,6 +38,9 @@ class workflowconfiguration_helper { /** @var string The upload workflow mapping hidden input id. */ const MAPPING_INPUT_HIDDEN_ID = 'configpanelmapping'; + /** @var string A suffix to add to the element ids to avoid conflicts. */ + const CONFIG_PANEL_ELEMENT_SUFFIX = '_moodle_form_config_panel'; + /** @var ?workflowconfiguration_helper the static instance of the class. */ private static $instance = null; @@ -123,19 +126,22 @@ public function get_userdefined_configuration_data(\stdClass $formdata): array { $configpanelmapping = json_decode($formdata->{self::MAPPING_INPUT_HIDDEN_ID}, true); foreach ($configpanelmapping as $cpid => $mappingtype) { $isboolean = $mappingtype === 'boolean'; + $cpidformatted = str_replace(self::CONFIG_PANEL_ELEMENT_SUFFIX, '', $cpid); if (property_exists($formdata, $cpid)) { - $value = boolval($formdata->$cpid); + $value = $formdata->$cpid; if ($isboolean) { + $value = boolval($value); $value = !empty($value) ? 'true' : 'false'; } if ($mappingtype === 'date') { + $value = intval($value); $dobj = new \DateTime("now", new \DateTimeZone("UTC")); $dobj->setTimestamp(intval($value)); $value = $dobj->format('Y-m-d\TH:i:s\Z'); } - $configpaneldata[$cpid] = $value; + $configpaneldata[$cpidformatted] = $value; } else if ($isboolean) { - $configpaneldata[$cpid] = 'false'; + $configpaneldata[$cpidformatted] = 'false'; } } } diff --git a/renderer.php b/renderer.php index dddfb993..43d2e128 100644 --- a/renderer.php +++ b/renderer.php @@ -1628,12 +1628,9 @@ public function render_configuration_panel_form_elements(&$mform, $configuration return; } - // Make sure the html string is valid. - $html = $this->close_tags_in_html_string($configurationpanelhtml); - // Initialize the dom and xpath instances. $dom = new \DOMDocument('1.0', 'utf-8'); - $dom->loadHTML($html); + $dom->loadHTML($configurationpanelhtml); $xpath = new \DOMXpath($dom); // Extracting all inputs and selects in one loop to maintain the sequence and convert them into moodle form elements. @@ -1656,6 +1653,10 @@ public function render_configuration_panel_form_elements(&$mform, $configuration $moodleid = $id; $mappingtype = 'text'; + // Avoid element naming collisions. + $name .= workflowconfiguration_helper::CONFIG_PANEL_ELEMENT_SUFFIX; + $moodleid .= workflowconfiguration_helper::CONFIG_PANEL_ELEMENT_SUFFIX; + // Conver input to moodle form element. if ($nodetype === 'input') { $type = trim($element->getAttribute('type')); @@ -1692,7 +1693,7 @@ public function render_configuration_panel_form_elements(&$mform, $configuration $moodletype = substr($type, 0, 8) === 'datetime' ? 'date_time_selector' : 'date_selector'; $mform->addElement($moodletype, $moodleid, $title); if (!is_null($value)) { - $default = $value; + $default = (int) $value; } } From 6c6cd3178780e2c670dfebc5445b85bed54e859a Mon Sep 17 00:00:00 2001 From: ferishili Date: Tue, 17 Dec 2024 14:41:43 +0100 Subject: [PATCH 5/7] add some debug message for unit tests --- tests/upload_ingest_with_configpanel_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/upload_ingest_with_configpanel_test.php b/tests/upload_ingest_with_configpanel_test.php index c1628f23..02d24cb2 100644 --- a/tests/upload_ingest_with_configpanel_test.php +++ b/tests/upload_ingest_with_configpanel_test.php @@ -126,9 +126,9 @@ public function test_upload_ingest_configpanel(): void { // Workflow configuration helper assertions. $wfconfighelper = workflowconfiguration_helper::get_instance(1); - $this->assertTrue($wfconfighelper->can_provide_configuration_panel()); - $this->assertNotEmpty($wfconfighelper->get_upload_workflow_configuration_panel()); - $this->assertNotEmpty($wfconfighelper->get_allowed_upload_configurations()); + $this->assertTrue($wfconfighelper->can_provide_configuration_panel(), 'Unable to provide configuration panel!'); + $this->assertNotEmpty($wfconfighelper->get_upload_workflow_configuration_panel(), 'Config panel is empty!'); + $this->assertNotEmpty($wfconfighelper->get_allowed_upload_configurations(), 'Allowed configs are empty!'); $configpanelelementmapping = ['straightToPublishing' => 'boolean']; $formdata = new stdClass(); From f8c44f68a69b4b4511f0362759f97c49b125110f Mon Sep 17 00:00:00 2001 From: ferishili Date: Tue, 17 Dec 2024 15:10:22 +0100 Subject: [PATCH 6/7] upgrade opencast version and make it single in ci actions --- .github/workflows/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/config.json b/.github/workflows/config.json index e4f2bee1..ad55d3bc 100644 --- a/.github/workflows/config.json +++ b/.github/workflows/config.json @@ -2,7 +2,7 @@ "main-moodle": "MOODLE_405_STABLE", "main-php": "8.3", "main-oc": "16.6", - "ocs": ["16.6", "15.11"], + "ocs": ["16.7"], "main-db": "mariadb", "moodle-php": { "MOODLE_405_STABLE": ["8.1", "8.2"] From 8c340318fe3513f3151b5f21b1db945d6b237c57 Mon Sep 17 00:00:00 2001 From: ferishili Date: Wed, 18 Dec 2024 16:10:03 +0100 Subject: [PATCH 7/7] make only one oc for tests with adding the default opencast docker branch input --- .github/workflows/config.json | 4 ++-- .github/workflows/config_all.json | 4 ++-- .github/workflows/moodle-ci.yml | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/config.json b/.github/workflows/config.json index ad55d3bc..2cd169b5 100644 --- a/.github/workflows/config.json +++ b/.github/workflows/config.json @@ -1,8 +1,8 @@ { "main-moodle": "MOODLE_405_STABLE", "main-php": "8.3", - "main-oc": "16.6", - "ocs": ["16.7"], + "main-oc": "16.7", + "ocs": [], "main-db": "mariadb", "moodle-php": { "MOODLE_405_STABLE": ["8.1", "8.2"] diff --git a/.github/workflows/config_all.json b/.github/workflows/config_all.json index 558800cd..9627724e 100644 --- a/.github/workflows/config_all.json +++ b/.github/workflows/config_all.json @@ -1,8 +1,8 @@ { "main-moodle": "MOODLE_405_STABLE", "main-php": "8.3", - "main-oc": "16.6", - "ocs": ["16.6", "15.11"], + "main-oc": "16.7", + "ocs": [], "main-db": "mariadb", "moodle-php": { "MOODLE_401_STABLE": ["7.4", "8.0", "8.1"], diff --git a/.github/workflows/moodle-ci.yml b/.github/workflows/moodle-ci.yml index 65e297b3..44c03497 100644 --- a/.github/workflows/moodle-ci.yml +++ b/.github/workflows/moodle-ci.yml @@ -14,3 +14,4 @@ jobs: requires-mod-plugin: true branch-tool-plugin: issue-56 branch-mod-plugin: main + branch-opencast-docker-default: 16.7