fix(migrations): ignore invalid utf8 chars for media files metadata + update transcript parser

check that transcript parser constants are defined before declaring them
This commit is contained in:
Yassine Doghri 2022-01-28 10:31:30 +00:00
parent d807ab9732
commit 45e8f99e75
4 changed files with 18 additions and 7 deletions

View File

@ -88,7 +88,7 @@ class BaseMedia extends Entity
$this->attributes['type'] = $this->type; $this->attributes['type'] = $this->type;
$this->attributes['file_mimetype'] = $file->getMimeType(); $this->attributes['file_mimetype'] = $file->getMimeType();
$this->attributes['file_metadata'] = json_encode(lstat((string) $file)); $this->attributes['file_metadata'] = json_encode(lstat((string) $file), JSON_INVALID_UTF8_IGNORE);
$this->attributes['file_path'] = save_media( $this->attributes['file_path'] = save_media(
$file, $file,
$this->attributes['file_directory'], $this->attributes['file_directory'],

View File

@ -61,7 +61,7 @@ class Image extends BaseMedia
]; ];
} }
$this->attributes['file_metadata'] = json_encode($metadata); $this->attributes['file_metadata'] = json_encode($metadata, JSON_INVALID_UTF8_IGNORE);
$this->initFileProperties(); $this->initFileProperties();
$this->saveSizes(); $this->saveSizes();

View File

@ -58,7 +58,7 @@ class Transcript extends BaseMedia
$metadata['json_path'] = $jsonFilePath; $metadata['json_path'] = $jsonFilePath;
} }
$this->attributes['file_metadata'] = json_encode($metadata); $this->attributes['file_metadata'] = json_encode($metadata, JSON_INVALID_UTF8_IGNORE);
return $this; return $this;
} }

View File

@ -30,10 +30,21 @@ class TranscriptParser
*/ */
public function parseSrt(): string | false public function parseSrt(): string | false
{ {
define('SRT_STATE_SUBNUMBER', 0); if (! defined('SRT_STATE_SUBNUMBER')) {
define('SRT_STATE_TIME', 1); define('SRT_STATE_SUBNUMBER', 0);
define('SRT_STATE_TEXT', 2); }
define('SRT_STATE_BLANK', 3);
if (! defined('SRT_STATE_TIME')) {
define('SRT_STATE_TIME', 1);
}
if (! defined('SRT_STATE_TEXT')) {
define('SRT_STATE_TEXT', 2);
}
if (! defined('SRT_STATE_BLANK')) {
define('SRT_STATE_BLANK', 3);
}
$subs = []; $subs = [];
$state = SRT_STATE_SUBNUMBER; $state = SRT_STATE_SUBNUMBER;