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

Bugfix/video duration validation #2047

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Controller/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
* @SWG\Parameter(
* name="type",
* in="path",
* description="The type of the Widget e.g. text. Media based Widgets like Image are added via POST /playlist/library/assign/{playlistId} call.",

Check warning on line 127 in lib/Controller/Widget.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 154 characters
* type="string",
* required=true
* ),
Expand All @@ -138,7 +138,7 @@
* @SWG\Parameter(
* name="displayOrder",
* in="formData",
* description="Optional integer to say which position this assignment should occupy in the list. If more than one media item is being added, this will be the position of the first one.",

Check warning on line 141 in lib/Controller/Widget.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 196 characters
* type="integer",
* required=false
* ),
Expand Down Expand Up @@ -398,7 +398,7 @@

// Validate common parameters if we don't have a validator present.
$widgetValidators = $module->getWidgetValidators();
if (count($widgetValidators) <= 0 && $widget->duration < 0) {
if (count($widgetValidators) <= 0 && $widget->duration <= 0) {
throw new InvalidArgumentException(__('Duration needs to be a positive value'), 'duration');
}

Expand Down Expand Up @@ -712,7 +712,7 @@
* @SWG\Parameter(
* name="transitionDirection",
* in="formData",
* description="The direction for this transition, only appropriate for transitions that move, such as fly. Available options: N, NE, E, SE, S, SW, W, NW",

Check warning on line 715 in lib/Controller/Widget.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 164 characters
* type="integer",
* required=false
* ),
Expand Down Expand Up @@ -815,7 +815,7 @@
// Are we allowed to do this?
if ($widget->type === 'subplaylist') {
throw new InvalidArgumentException(
__('Audio cannot be attached to a Sub-Playlist Widget. Please attach it to the Widgets inside the Playlist'),

Check warning on line 818 in lib/Controller/Widget.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 125 characters
'type'
);
}
Expand Down Expand Up @@ -919,7 +919,7 @@
// Are we allowed to do this?
if ($widget->type === 'subplaylist') {
throw new InvalidArgumentException(
__('Audio cannot be attached to a Sub-Playlist Widget. Please attach it to the Widgets inside the Playlist'),

Check warning on line 922 in lib/Controller/Widget.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 125 characters
'type'
);
}
Expand Down
9 changes: 6 additions & 3 deletions lib/Widget/Validator/RemoteUrlsZeroDurationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RemoteUrlsZeroDurationValidator implements WidgetValidatorInterface
public function validate(Module $module, Widget $widget, string $stage): void
{
$url = urldecode($widget->getOptionValue('uri', ''));
if ($widget->useDuration == 1
if ($widget->useDuration === 1
&& $widget->duration <= 0
&& !Str::startsWith($url, 'file://')
&& Str::contains($url, '://')
Expand All @@ -53,9 +53,12 @@ public function validate(Module $module, Widget $widget, string $stage): void
__('The duration needs to be greater than 0 for remote URLs'),
'duration'
);
} else if ($widget->duration < 0) {
} else if ($widget->useDuration === 1 && $widget->duration <= 0) {
// Locally stored file, still needs a positive duration.
throw new InvalidArgumentException(__('Duration needs to be 0 or above'), 'duration');
throw new InvalidArgumentException(
__('The duration needs to be above 0 for a locally stored file '),
'duration'
);
}
}
}
11 changes: 7 additions & 4 deletions lib/Widget/Validator/ZeroDurationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ class ZeroDurationValidator implements WidgetValidatorInterface
*/
public function validate(Module $module, Widget $widget, string $stage): void
{
// Videos can have 0 durations
if ($widget->duration <= 0) {
throw new InvalidArgumentException(__('Duration needs to be 0 or above'), 'duration');
// Videos can have 0 durations (but not if useDuration is selected)
if ($widget->useDuration === 1 && $widget->duration <= 0) {
throw new InvalidArgumentException(
sprintf(__('Duration needs to be above 0 for %s'), $module->name),
'duration'
);
}
}
}
}
Loading