mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-19 13:01:19 +00:00
fix(media): init file properties in setAttributes' Model method + set defaults to pathinfo data
This commit is contained in:
parent
26a714d9c2
commit
0775add678
@ -21,14 +21,11 @@ class Audio extends BaseMedia
|
||||
{
|
||||
protected string $type = 'audio';
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|null $data
|
||||
*/
|
||||
public function __construct(array $data = null)
|
||||
public function initFileProperties(): void
|
||||
{
|
||||
parent::__construct($data);
|
||||
parent::initFileProperties();
|
||||
|
||||
if ($this->file_metadata) {
|
||||
if ($this->file_metadata !== null) {
|
||||
$this->duration = (float) $this->file_metadata['playtime_seconds'];
|
||||
$this->header_size = (int) $this->file_metadata['avdataoffset'];
|
||||
}
|
||||
|
@ -56,29 +56,30 @@ class BaseMedia extends Entity
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|null $data
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function __construct(array $data = null)
|
||||
public function setAttributes(array $data): self
|
||||
{
|
||||
parent::__construct($data);
|
||||
parent::setAttributes($data);
|
||||
|
||||
$this->initFileProperties();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function initFileProperties(): void
|
||||
{
|
||||
if ($this->file_key !== '') {
|
||||
[
|
||||
'filename' => $filename,
|
||||
'dirname' => $dirname,
|
||||
'extension' => $extension,
|
||||
] = pathinfo($this->file_key);
|
||||
$pathInfo = pathinfo($this->file_key) + [
|
||||
'filename' => '',
|
||||
'dirname' => '',
|
||||
'extension' => '',
|
||||
];
|
||||
|
||||
$this->attributes['file_url'] = service('file_manager')->getUrl($this->file_key);
|
||||
$this->attributes['file_name'] = $filename;
|
||||
$this->attributes['file_directory'] = $dirname;
|
||||
$this->attributes['file_extension'] = $extension;
|
||||
}
|
||||
$this->file_url = service('file_manager')
|
||||
->getUrl($this->file_key);
|
||||
$this->file_name = $pathInfo['filename'];
|
||||
$this->file_directory = $pathInfo['dirname'];
|
||||
$this->file_extension = $pathInfo['extension'];
|
||||
}
|
||||
|
||||
public function setFile(File $file): self
|
||||
|
@ -29,10 +29,7 @@ class Image extends BaseMedia
|
||||
{
|
||||
parent::initFileProperties();
|
||||
|
||||
if ($this->file_key !== '' && $this->file_metadata !== null && array_key_exists(
|
||||
'sizes',
|
||||
$this->file_metadata
|
||||
)) {
|
||||
if ($this->file_metadata && array_key_exists('sizes', $this->file_metadata)) {
|
||||
$this->sizes = $this->file_metadata['sizes'];
|
||||
$this->initSizeProperties();
|
||||
}
|
||||
|
@ -21,11 +21,11 @@ class Transcript extends BaseMedia
|
||||
|
||||
protected string $type = 'transcript';
|
||||
|
||||
public function __construct(?array $data = null)
|
||||
public function initFileProperties(): void
|
||||
{
|
||||
parent::__construct($data);
|
||||
parent::initFileProperties();
|
||||
|
||||
if ($this->file_key && $this->file_metadata && array_key_exists('json_key', $this->file_metadata)) {
|
||||
if ($this->file_metadata !== null && array_key_exists('json_key', $this->file_metadata)) {
|
||||
helper('media');
|
||||
|
||||
$this->json_key = $this->file_metadata['json_key'];
|
||||
|
@ -102,14 +102,7 @@ class MediaModel extends Model
|
||||
{
|
||||
$cacheName = "media#{$mediaId}";
|
||||
if (! ($found = cache($cacheName))) {
|
||||
$builder = $this->where([
|
||||
'id' => $mediaId,
|
||||
]);
|
||||
|
||||
/** @var object $result */
|
||||
$result = $builder->first();
|
||||
$mediaClass = $this->returnType;
|
||||
$found = new $mediaClass($result->toArray(false, true));
|
||||
$found = $this->find($mediaId);
|
||||
|
||||
cache()
|
||||
->save($cacheName, $found, DECADE);
|
||||
|
@ -168,6 +168,10 @@ class PodcastImport extends BaseCommand
|
||||
$this->importTask->pass();
|
||||
} catch (Exception $exception) {
|
||||
$this->error($exception->getMessage());
|
||||
log_message(
|
||||
'critical',
|
||||
'Error when importing ' . $this->importTask->feed_url . PHP_EOL . $exception->getTraceAsString()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user