Skip to content

Commit

Permalink
Fix: Ceil():Argument #1 ($num) must be of type int|float, null given …
Browse files Browse the repository at this point in the history
…when uploading video (#15621)

* Fix: Ceil():Argument #1 ($num) must be of type int|float, null given when uploading video

* Fix wrong php doc.

* move ceil to getDurationString()

* Remove unnecessary int cast

* Make getDurationString non static
  • Loading branch information
blankse committed Jul 31, 2023
1 parent c485cbe commit 81df1fd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion models/Asset/Video.php
Expand Up @@ -221,7 +221,7 @@ public function getDimensionsFromBackend()
}

/**
* @return int|null
* @return float|null
*/
public function getDuration()
{
Expand Down
51 changes: 29 additions & 22 deletions models/Document/Editable/Video.php
Expand Up @@ -927,27 +927,6 @@ private function getHtml5Code($urls = [], $thumbnail = null)
$code = '';
$video = $this->getVideoAsset();
if ($video) {
$duration = ceil($video->getDuration());

$durationParts = ['PT'];

// hours
if ($duration / 3600 >= 1) {
$hours = floor($duration / 3600);
$durationParts[] = $hours . 'H';
$duration = $duration - $hours * 3600;
}

// minutes
if ($duration / 60 >= 1) {
$minutes = floor($duration / 60);
$durationParts[] = $minutes . 'M';
$duration = $duration - $minutes * 60;
}

$durationParts[] = $duration . 'S';
$durationString = implode('', $durationParts);

$code .= '<div id="pimcore_video_' . $this->getName() . '" class="pimcore_editable_video">' . "\n";

$uploadDate = new \DateTime();
Expand All @@ -959,11 +938,15 @@ private function getHtml5Code($urls = [], $thumbnail = null)
'name' => $this->getTitle(),
'description' => $this->getDescription(),
'uploadDate' => $uploadDate->format('Y-m-d\TH:i:sO'),
'duration' => $durationString,
//'contentUrl' => Tool::getHostUrl() . $urls['mp4'],
//"embedUrl" => "http://www.example.com/videoplayer.swf?video=123",
//"interactionCount" => "1234",
];
$duration = $video->getDuration();

if ($duration !== null) {
$jsonLd['duration'] = $this->getDurationString($duration);
}

if (!$thumbnail) {
$thumbnail = $video->getImageThumbnail([]);
Expand Down Expand Up @@ -1045,6 +1028,30 @@ private function getHtml5Code($urls = [], $thumbnail = null)
return $code;
}

private function getDurationString(float $duration): string
{
$duration = ceil($duration);
$durationParts = ['PT'];

// hours
if ($duration / 3600 >= 1) {
$hours = floor($duration / 3600);
$durationParts[] = $hours . 'H';
$duration = $duration - $hours * 3600;
}

// minutes
if ($duration / 60 >= 1) {
$minutes = floor($duration / 60);
$durationParts[] = $minutes . 'M';
$duration = $duration - $minutes * 60;
}

$durationParts[] = $duration . 'S';

return implode('', $durationParts);
}

/**
* @param string|null $thumbnail
*
Expand Down

0 comments on commit 81df1fd

Please sign in to comment.