Skip to content

Commit abe0a22

Browse files
committed
Refactor update scheduling method to improve clarity and add force update option, removing unwanted log actions
1 parent e1a2a77 commit abe0a22

File tree

6 files changed

+118
-36
lines changed

6 files changed

+118
-36
lines changed

lib/Models/REST/SchedulerClient.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public function __construct($config_id = 1)
2222

2323
/**
2424
* Deletes an event
25-
*
25+
*
2626
* @param string $event_id the event id
27-
*
27+
*
2828
* @return boolean success or not
2929
*/
3030
public function deleteEvent($event_id)
@@ -39,7 +39,7 @@ public function deleteEvent($event_id)
3939

4040
/**
4141
* Updates an event
42-
*
42+
*
4343
* @param string $event_id the event id
4444
* @param int $start start of the event
4545
* @param int $end end of the event
@@ -48,7 +48,7 @@ public function deleteEvent($event_id)
4848
* @param string $mediaPackage mediapackage
4949
* @param string|array $wfproperties workflow properties
5050
* @param string|array $agentparameters agent params
51-
*
51+
*
5252
* @return boolean success or not
5353
*/
5454
public function updateEvent($event_id, $start = 0, $end = 0, $agent = '', $users = '', $mediaPackage = '', $wfproperties = '', $agentparameters = '')

lib/Models/ScheduleHelper.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ private static function createEventMetadata($course_id, $resource_id, $config_id
525525
}
526526

527527
if (\StudipVersion::newerThan('4.4')) {
528-
$room = new \Resource($resource_id);
528+
$room = new \Resource($resource_id);
529529
} else {
530-
$room = \ResourceObject::Factory($resource_id);
530+
$room = \ResourceObject::Factory($resource_id);
531531
}
532532
$ca = Resources::findByResource_id($resource_id);
533533

@@ -619,18 +619,21 @@ public static function deleteEventForSeminar($course_id, $termin_id, $external_c
619619
/**
620620
* Updates an scheduled event
621621
* NOTE: it performs updating of scheduled record on both sides (SOP & OC)
622-
* this function will be used upon time range cahnges with Slider
622+
* this function will be used upon time range change with Slider
623623
*
624624
* @param string $course_id - course identifier
625625
* @param string $termin_id - termin identifier
626626
* @param int $start - the start timestamp
627627
* @param int $end - the end timestamp
628628
* @param bool $update_resource - whether to update the resources info of scheduled recording object
629+
* @param bool $force_oc_update - a flag to force update recordings on opencast.
629630
*
630631
* @return bool success or not
631632
*/
632-
public static function updateEventForSeminar($course_id, $termin_id, $start = null, $end = null, $update_resource = false)
633+
public static function updateEventForSeminar($course_id, $termin_id, $start = null, $end = null, $update_resource = false,
634+
$force_oc_update = false)
633635
{
636+
$has_changes = false;
634637
$date = new \SingleDate($termin_id);
635638
$resource_id = $date->getResourceID();
636639
if (!$resource_id) {
@@ -674,6 +677,7 @@ public static function updateEventForSeminar($course_id, $termin_id, $start = nu
674677
if (!empty($new_start)) {
675678
$scheduled_recording_obj->start = $new_start;
676679
$scheduled_recording_obj->store();
680+
$has_changes = true;
677681
}
678682

679683
$new_end = 0;
@@ -692,6 +696,7 @@ public static function updateEventForSeminar($course_id, $termin_id, $start = nu
692696
if (!empty($new_end)) {
693697
$scheduled_recording_obj->end = $new_end;
694698
$scheduled_recording_obj->store();
699+
$has_changes = true;
695700
}
696701

697702
$is_livestream = (bool) $scheduled_recording_obj->is_livestream;
@@ -703,6 +708,11 @@ public static function updateEventForSeminar($course_id, $termin_id, $start = nu
703708
$workflow_id = $is_livestream ? $resource_obj['livestream_workflow_id'] : $resource_obj['workflow_id'];
704709
$scheduled_recording_obj->workflow_id = $workflow_id;
705710
$scheduled_recording_obj->store();
711+
$has_changes = true;
712+
}
713+
714+
if (!$force_oc_update && !$has_changes) {
715+
return true;
706716
}
707717

708718
$metadata = self::createEventMetadata($course_id, $resource_id, $resource_obj['config_id'], $termin_id, $event_id, $is_livestream);

lib/Routes/Schedule/ScheduleBulk.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __invoke(Request $request, Response $response, $args)
5151
$result = ScheduleHelper::deleteEventForSeminar($course_id, $termin_id);
5252
break;
5353
case 'update':
54-
$result = ScheduleHelper::updateEventForSeminar($course_id, $termin_id);
54+
$result = ScheduleHelper::updateEventForSeminar($course_id, $termin_id, null, null, true, true);
5555
break;
5656
}
5757
if (!$result) {

lib/Routes/Schedule/ScheduleUpdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __invoke(Request $request, Response $response, $args)
3838
'text' => _('Die geplante Aufzeichnung konnte nicht aktualisiert werden.')
3939
];
4040

41-
if (ScheduleHelper::updateEventForSeminar($course_id, $termin_id, $start, $end)) {
41+
if (ScheduleHelper::updateEventForSeminar($course_id, $termin_id, $start, $end, true, true)) {
4242
$message = [
4343
'type' => 'success',
4444
'text' => _('Die geplante Aufzeichnung wurde aktualisiert.')

migrations/046_add_remove_media.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@
22
class AddRemoveMedia extends Migration
33
{
44

5-
static $log_actions = [
6-
[
7-
'name' => 'OC_REMOVE_MEDIA',
8-
'description' => 'Opencast: Episode geloescht',
9-
'template' => '%user loeschte Episode %info in %sem(%affected)',
10-
'active' => 1
11-
],
12-
];
5+
static $log_actions = [
6+
[
7+
'name' => 'OC_REMOVE_MEDIA',
8+
'description' => 'Opencast: Episode geloescht',
9+
'template' => '%user loeschte Episode %info in %sem(%affected)',
10+
'active' => 1
11+
],
12+
];
1313

1414

15-
function up()
16-
{
17-
$db = DBManager::get();
18-
$query = $db->prepare("INSERT INTO log_actions (action_id, name, description, info_template, active) VALUES (?, ?, ?, ?, ?)");
15+
function up()
16+
{
17+
$db = DBManager::get();
18+
$query = $db->prepare("INSERT INTO log_actions (action_id, name, description, info_template, active) VALUES (?, ?, ?, ?, ?)");
1919

20-
foreach (self::$log_actions as $action) {
21-
$query->execute(array(md5($action['name']), $action['name'], $action['description'], $action['template'], $action['active']));
22-
}
23-
}
20+
foreach (self::$log_actions as $action) {
21+
$query->execute(array(md5($action['name']), $action['name'], $action['description'], $action['template'], $action['active']));
22+
}
23+
}
2424

25-
function down()
26-
{
27-
$db = DBManager::get();
28-
$query = $db->prepare("DELETE FROM log_actions WHERE action_id = ?");
29-
$query2 = $db->prepare("DELETE FROM log_events WHERE action_id = ?");
25+
function down()
26+
{
27+
$db = DBManager::get();
28+
$query = $db->prepare("DELETE FROM log_actions WHERE action_id = ?");
29+
$query2 = $db->prepare("DELETE FROM log_events WHERE action_id = ?");
3030

31-
foreach (self::$log_actions as $action) {
32-
$query->execute(array(md5($action['name'])));
33-
$query2->execute(array(md5($action['name'])));
34-
}
35-
}
31+
foreach (self::$log_actions as $action) {
32+
$query->execute(array(md5($action['name'])));
33+
$query2->execute(array(md5($action['name'])));
34+
}
35+
}
3636
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
class RemoveLogActions extends Migration
3+
{
4+
const PLUGINCLASSNAME = 'OpencastV3';
5+
6+
private $log_actions = [
7+
[
8+
'name' => 'OC_CHANGE_EPISODE_VISIBILITY',
9+
'description' => 'Opencast: Sichtbarkeit einer Episode geandert',
10+
'template' => '%user aendert Sichtbarkeit der Aufzeichnung %affected in %sem(%coaffected)',
11+
],
12+
[
13+
'name' => 'OC_CHANGE_TAB_VISIBILITY',
14+
'description' => 'Opencast: Sichtbarkeit des Kursreiters geaendert',
15+
'template' => '%user aendert Sichtbarkeit des Kursreiters in %sem(%affected)',
16+
],
17+
[
18+
'name' => 'OC_CREATE_SERIES',
19+
'description' => 'Opencast: Anlegen einer Aufzeichnungsserie',
20+
'template' => '%user legt neue Aufzeichnungsserie in %sem(%affected) an',
21+
],
22+
[
23+
'name' => 'OC_CONNECT_SERIES',
24+
'description' => 'Opencast: Verknuepfung einer Aufzeichnungsserie',
25+
'template' => '%user verknuepft vorhandene Aufzeichnungsserie %affected in %sem(%coaffected) an',
26+
],
27+
[
28+
'name' => 'OC_REMOVE_CONNECTED_SERIES',
29+
'description' => 'Opencast: Aufheben einer Aufzeichnungsserienverknuepfung',
30+
'template' => '%user loescht die Verbindung zur Aufzeichnungsserie %affected in %sem(%coaffected) an',
31+
],
32+
[
33+
'name' => 'OC_UPLOAD_MEDIA',
34+
'description' => 'Opencast: Upload einer Datei in einer Aufzeichnungsserie',
35+
'template' => '%user laedt eine Datei mit der WorkflowID %affected in %sem(%coaffected) hoch',
36+
],
37+
[
38+
'name' => 'OC_REMOVE_MEDIA',
39+
'description' => 'Opencast: Episode geloescht',
40+
'template' => '%user loeschte Episode %info in %sem(%affected)',
41+
],
42+
[
43+
'name' => 'OC_TOS',
44+
'description' => 'Opencast: TOS akzeptiert/abgelehnt',
45+
'template' => '%user hat TOS %info in %sem(%affected)',
46+
],
47+
];
48+
49+
public function description()
50+
{
51+
return 'Remove unwanted log actions';
52+
}
53+
54+
public function up()
55+
{
56+
foreach ($this->log_actions as $log_action) {
57+
StudipLog::unregisterAction($log_action['name']);
58+
}
59+
}
60+
61+
public function down()
62+
{
63+
foreach ($this->log_actions as $log_action) {
64+
StudipLog::registerActionPlugin(
65+
$log_action['name'],
66+
$log_action['description'],
67+
$log_action['template'],
68+
self::PLUGINCLASSNAME
69+
);
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)