Skip to content

Commit 1cfab72

Browse files
committed
clone new step opencast 4.5
1 parent b397cb7 commit 1cfab72

18 files changed

Lines changed: 3024 additions & 0 deletions

step/opencast/CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
moodle-lifecyclestep_opencast
2+
=============================
3+
4+
Changes
5+
-------
6+
7+
### Unreleased
8+
9+
* 2023-06-14 - Update README.md & CHANGES.md
10+
* 2023-06-13 - First draft (by Farbod Zamani)
11+
* 2022-07-18 - Initial implementation (PoC by Alexander Bias)

step/opencast/COPYING.txt

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

step/opencast/LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

step/opencast/README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Course Life Cycle Opencast Step (moodle-lifecyclestep_opencast)
2+
3+
## History
4+
5+
This plugin was originally developed in 2022 by Alexander Bias from [lern.link](https://lern.link/) on behalf of the [University of Ulm](https://www.uni-ulm.de/). It is currently maintained by [Farbod Zamani](https://github.com/ferishili) from [elan e.V.](https://elan-ev.de/).
6+
7+
## Requirements
8+
9+
* Moodle 4.5+
10+
* Opencast 15+
11+
* Moodle Opencast API plugin (`tool_opencast`) 4.5-rx
12+
* Moodle Opencast Videos plugin (`block_opencast`) 4.5-rx
13+
* Moodle Course Life Cycle (`tool_lifecycle`) 5.x
14+
15+
## Installation
16+
17+
This plugin is a subplugin of the Course Life Cycle admin tool and must be placed under `admin/tool/lifecycle/step`, however, using Moodle Plugin installation wizard is strongly recommended.
18+
19+
You can obtain the main Course Life Cycle plugin from:
20+
[https://moodle.org/plugins/view/tool_lifecycle](https://moodle.org/plugins/view/tool_lifecycle)
21+
22+
Make sure the main plugin is installed before installing this subplugin.
23+
24+
## More Information
25+
26+
For detailed information about step plugins, please refer to the [Wiki](https://github.com/learnweb/moodle-tool_lifecycle/wiki) of the `moodle-tool_lifecycle` admin tool.
27+
28+
## Description
29+
30+
This plugin provides a step for the [Course Life Cycle](https://github.com/learnweb/moodle-tool_lifecycle) tool.
31+
32+
It allows administrators to define, for each course, what should happen to the associated Opencast videos after a configurable period of time. The step can either:
33+
34+
* Delete the Opencast events belonging to the Moodle course, or
35+
* Run a specific Opencast workflow on each eligible event.
36+
37+
The step supports both duplication modes used by the Opencast integration:
38+
39+
* **ACL Change** (shared course series across multiple courses)
40+
* **Event Duplication** (standard duplication mode)
41+
42+
In the case of shared series using the *ACL Change* mode, the step correctly handles ACL updates as required.
43+
44+
## Settings
45+
46+
The step automatically detects multi-tenancy configurations provided by the Opencast API plugin and applies the settings per Opencast instance accordingly.
47+
48+
### Opencast Instance–Specific Settings
49+
50+
For each configured Opencast instance, the following settings are available:
51+
52+
* **Opencast workflow**
53+
Defines the Opencast workflow that will be executed for each eligible event.
54+
55+
* **Enable deletion process**
56+
If enabled, events will be deleted when a course is processed by this step. If disabled, the configured workflow will be executed instead.
57+
58+
* **Remove series mapping when deleting**
59+
If the deletion process is enabled, this option ensures that the series-to-course mapping in Moodle is also removed.
60+
61+
### General Settings
62+
63+
In addition to the instance-specific settings, the following general options are available:
64+
65+
* **Enable trace**
66+
Logs and traces the entire process step by step.
67+
68+
* **Enable admin notification**
69+
Notifies administrators if an error occurs during processing.
70+
71+
## Concept
72+
73+
The following diagrams illustrate the overall processing logic.
74+
75+
### Top-Level Process
76+
77+
![top layer process](./docs/lib.png)
78+
79+
### Deletion Process
80+
81+
If the deletion process is enabled for an Opencast instance, processing follows this flow:
82+
83+
![delete process](./docs/delete.png)
84+
85+
### Default Process
86+
87+
If the deletion process is disabled, the step executes the configured workflow for each eligible event:
88+
89+
![default process](./docs/default.png)
90+
91+
### Sequence Diagram
92+
93+
![sequence diagram](./docs/seq.png)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Helper class to handle logs printing in Opencast Step
19+
*
20+
* @package lifecyclestep_opencast
21+
* @copyright 2026 Farbod Zamani Boroujeni, elan e.V.
22+
* @author Farbod Zamani Boroujeni <zamani@elan-ev.de>
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
namespace lifecyclestep_opencast;
27+
28+
/**
29+
* Helper class to handle logs printing in Opencast Step
30+
*/
31+
class log_helper {
32+
/** @var bool $traceenabled Whether tracing is On. */
33+
private bool $traceenabled = true;
34+
/**
35+
* Constructor function.
36+
* @param bool $traceenabled A flag to make sure that the settings is applied.
37+
*/
38+
public function __construct(bool $traceenabled) {
39+
$this->traceenabled = $traceenabled;
40+
}
41+
/**
42+
* Prints mtrace log cleaner.
43+
*
44+
* @param string $message The message
45+
* @param string $prefix the message prefix.
46+
* @param int $ind The level of indentation for the message prefix.
47+
* @param bool $newline the flag to set if the mrtace should also print end of line.
48+
*/
49+
public function print_mtrace(string $message, string $prefix = '', int $ind = 0, bool $newline = true): void {
50+
// Prevent printing mtrace if disabled.
51+
if (!$this->traceenabled) {
52+
return;
53+
}
54+
/*
55+
* phpcs:disable moodle.NamingConventions.ValidVariableName.VariableNameLowerCase
56+
*/
57+
global $FULLSCRIPT;
58+
$ishtml = !empty($FULLSCRIPT) ? str_contains($FULLSCRIPT, 'run.php') : false;
59+
/*
60+
* phpcs:enable
61+
* Enable enables back all sniffer rules!
62+
*/
63+
64+
$eol = '';
65+
if ($newline) {
66+
$eol = "\n";
67+
// HTML end of line if called by run-command of workflowoverview.
68+
if ($ishtml) {
69+
$eol = "<br>";
70+
}
71+
}
72+
73+
$indstr = "";
74+
if ($ind > 0) {
75+
for ($i = 0; $i < $ind; $i++) {
76+
$indannotation = " ";
77+
if ($ishtml) {
78+
$indannotation = "&nbsp;&nbsp;";
79+
}
80+
$indstr .= $indannotation;
81+
}
82+
}
83+
$message = $indstr . $message;
84+
85+
if (!empty($prefix)) {
86+
$message = $prefix . $message;
87+
}
88+
89+
mtrace($message, $eol);
90+
}
91+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Helper class to handle notifications in Opencast Step
19+
*
20+
* @package lifecyclestep_opencast
21+
* @copyright 2023 Farbod Zamani Boroujeni, elan e.V.
22+
* @author Farbod Zamani Boroujeni <zamani@elan-ev.de>
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
namespace lifecyclestep_opencast;
27+
28+
/**
29+
* Helper class to handle notifications in Opencast Step
30+
*/
31+
class notification_helper {
32+
/** @var bool $notificationenabled Whether notifying feature is On. */
33+
private bool $notificationenabled = true;
34+
/**
35+
* Constructor function.
36+
* @param bool $notificationenabled A flag to make sure that the settings is enabled.
37+
*/
38+
public function __construct(bool $notificationenabled) {
39+
$this->notificationenabled = $notificationenabled;
40+
}
41+
/**
42+
* Notifies admins when a course is processed.
43+
*
44+
* @param stdClass $course the course object.
45+
* @param string $ocworkflow the workflow.
46+
*/
47+
public function notify_course_processed($course, $ocworkflow) {
48+
if (!$this->notificationenabled) {
49+
return;
50+
}
51+
$coursefullname = get_string('coursefullnameunknown', 'lifecyclestep_opencast');
52+
if ($course->fullname) {
53+
$coursefullname = $course->fullname;
54+
}
55+
$a = (object)[
56+
'courseid' => $course->id,
57+
'coursefullname' => $coursefullname,
58+
'ocworkflow' => $ocworkflow,
59+
];
60+
61+
$subject = get_string('notifycourseprocessed_subj', 'lifecyclestep_opencast');
62+
$body = get_string('notifycourseprocessed_body', 'lifecyclestep_opencast', $a);
63+
64+
$admin = get_admin();
65+
$this->send_message('error', $admin, $subject, $body);
66+
}
67+
68+
/**
69+
* Notifies admins upon failied workflow start on an event.
70+
*
71+
* @param stdClass $course the course object.
72+
* @param int $ocinstanceid the opencast instance id.
73+
* @param stdClass $video the video object.
74+
* @param string $ocworkflow the workflow.
75+
*/
76+
public function notify_failed_workflow($course, $ocinstanceid, $video, $ocworkflow) {
77+
if (!$this->notificationenabled) {
78+
return;
79+
}
80+
$coursefullname = get_string('coursefullnameunknown', 'lifecyclestep_opencast');
81+
if ($course->fullname) {
82+
$coursefullname = $course->fullname;
83+
}
84+
$a = (object)[
85+
'courseid' => $course->id,
86+
'coursefullname' => $coursefullname,
87+
'ocworkflow' => $ocworkflow,
88+
'videotitle' => $video->title,
89+
'videoidentifier' => $video->identifier,
90+
'ocinstanceid' => $ocinstanceid,
91+
];
92+
93+
$subject = get_string('errorfailedworkflow_subj', 'lifecyclestep_opencast');
94+
$body = get_string('errorfailedworkflow_body', 'lifecyclestep_opencast', $a);
95+
96+
$admin = get_admin();
97+
$this->send_message('error', $admin, $subject, $body);
98+
}
99+
100+
/**
101+
* Notifies admins upon fatal error.
102+
* It is a complimentary function to use anywhere that fits, by default try catch in cron job is handled by moodle itself.
103+
*
104+
* @param stdClass $course the course object.
105+
* @param int $ocinstanceid the opencast instance id.
106+
* @param string $ocworkflow the workflow.
107+
* @param string $error error details.
108+
*/
109+
public function notify_error($course, $ocinstanceid, $ocworkflow, $error) {
110+
if (!$this->notificationenabled) {
111+
return;
112+
}
113+
$coursefullname = get_string('coursefullnameunknown', 'lifecyclestep_opencast');
114+
if ($course->fullname) {
115+
$coursefullname = $course->fullname;
116+
}
117+
$a = (object)[
118+
'courseid' => $course->id,
119+
'coursefullname' => $coursefullname,
120+
'ocworkflow' => $ocworkflow,
121+
'error' => $error,
122+
'ocinstanceid' => $ocinstanceid,
123+
];
124+
125+
$subject = get_string('errorexception_subj', 'lifecyclestep_opencast');
126+
$body = get_string('errorexception_body', 'lifecyclestep_opencast', $a);
127+
128+
$admin = get_admin();
129+
$this->send_message('error', $admin, $subject, $body);
130+
}
131+
132+
/**
133+
* Notifies admins upon fatal error.
134+
* It is a complimentary function to use anywhere that fits, by default try catch in cron job is handled by moodle itself.
135+
*
136+
* @param stdClass $course the course object.
137+
* @param int $ocinstanceid the opencast instance id.
138+
* @param string $ocworkflow the workflow.
139+
*/
140+
public function notify_workflow_not_exists($course, $ocinstanceid, $ocworkflow) {
141+
if (!$this->notificationenabled) {
142+
return;
143+
}
144+
$coursefullname = get_string('coursefullnameunknown', 'lifecyclestep_opencast');
145+
if ($course->fullname) {
146+
$coursefullname = $course->fullname;
147+
}
148+
$a = (object)[
149+
'courseid' => $course->id,
150+
'coursefullname' => $coursefullname,
151+
'ocworkflow' => $ocworkflow,
152+
'ocinstanceid' => $ocinstanceid,
153+
];
154+
155+
$subject = get_string('errorworkflownotexists_subj', 'lifecyclestep_opencast');
156+
$body = get_string('errorworkflownotexists_body', 'lifecyclestep_opencast', $a);
157+
158+
$admin = get_admin();
159+
$this->send_message('error', $admin, $subject, $body);
160+
}
161+
162+
/**
163+
* Sends moodle internal message.
164+
*
165+
* @param string $messagetype Message type
166+
* @param object $touser User to which notification is sent
167+
* @param string $subject Subject
168+
* @param string $body Body
169+
* @param string $format Format
170+
*/
171+
private function send_message($messagetype, $touser, $subject, $body, $format = FORMAT_PLAIN) {
172+
$message = new \core\message\message();
173+
$message->courseid = SITEID;
174+
$message->component = 'block_opencast';
175+
$message->name = $messagetype;
176+
$message->userfrom = \core_user::get_user(\core_user::NOREPLY_USER);
177+
$message->userto = $touser;
178+
$message->subject = $subject;
179+
$message->fullmessage = html_to_text($body);
180+
$message->fullmessageformat = $format;
181+
$message->fullmessagehtml = $body;
182+
$message->smallmessage = '';
183+
$message->notification = 1;
184+
185+
message_send($message);
186+
}
187+
}

0 commit comments

Comments
 (0)