mirror of
https://code.castopod.org/adaures/castopod
synced 2025-06-05 17:02:01 +00:00
fix(video-clips): check if created video exists before recreating it and failing
update seed scripts to prevent sql error when reloading install page
This commit is contained in:
parent
2385b1a292
commit
dff1208725
@ -296,18 +296,24 @@ class AuthSeeder extends Seeder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db
|
if ($this->db->table('auth_groups')->countAll() < count($dataPermissions)) {
|
||||||
->table('auth_permissions')
|
$this->db
|
||||||
->ignore(true)
|
->table('auth_permissions')
|
||||||
->insertBatch($dataPermissions);
|
->ignore(true)
|
||||||
$this->db
|
->insertBatch($dataPermissions);
|
||||||
->table('auth_groups')
|
}
|
||||||
->ignore(true)
|
if ($this->db->table('auth_groups')->countAll() < count($dataGroups)) {
|
||||||
->insertBatch($dataGroups);
|
$this->db
|
||||||
$this->db
|
->table('auth_groups')
|
||||||
->table('auth_groups_permissions')
|
->ignore(true)
|
||||||
->ignore(true)
|
->insertBatch($dataGroups);
|
||||||
->insertBatch($dataGroupsPermissions);
|
}
|
||||||
|
if ($this->db->table('auth_groups_permissions')->countAll() < count($dataGroupsPermissions)) {
|
||||||
|
$this->db
|
||||||
|
->table('auth_groups_permissions')
|
||||||
|
->ignore(true)
|
||||||
|
->insertBatch($dataGroupsPermissions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -791,9 +791,11 @@ class CategorySeeder extends Seeder
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->db
|
foreach ($data as $categoryLine) {
|
||||||
->table('categories')
|
$this->db
|
||||||
->ignore(true)
|
->table('categories')
|
||||||
->insertBatch($data);
|
->ignore(true)
|
||||||
|
->insert($categoryLine);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -763,9 +763,11 @@ class LanguageSeeder extends Seeder
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->db
|
foreach ($data as $languageLine) {
|
||||||
->table('languages')
|
$this->db
|
||||||
->ignore(true)
|
->table('languages')
|
||||||
->insertBatch($data);
|
->ignore(true)
|
||||||
|
->insert($languageLine);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,11 @@ class VideoClip extends BaseClip
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->attributes['media_id'] !== null) {
|
||||||
|
// media is already set, do nothing
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
helper('media');
|
helper('media');
|
||||||
$file = new File(media_path($filePath));
|
$file = new File(media_path($filePath));
|
||||||
|
|
||||||
|
@ -144,6 +144,27 @@ class ClipModel extends Model
|
|||||||
return (int) $result[0]['running_count'];
|
return (int) $result[0]['running_count'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function doesVideoClipExist(VideoClip $videoClip): int | false
|
||||||
|
{
|
||||||
|
$result = $this->select('id')
|
||||||
|
->where([
|
||||||
|
'podcast_id' => $videoClip->podcast_id,
|
||||||
|
'episode_id' => $videoClip->episode_id,
|
||||||
|
'start_time' => $videoClip->start_time,
|
||||||
|
'duration' => $videoClip->duration,
|
||||||
|
])
|
||||||
|
->where('JSON_EXTRACT(`metadata`, "$.format")', $videoClip->format)
|
||||||
|
->where('JSON_EXTRACT(`metadata`, "$.theme.name")', $videoClip->theme['name'])
|
||||||
|
->get()
|
||||||
|
->getResultArray();
|
||||||
|
|
||||||
|
if ($result === []) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) $result[0]['id'];
|
||||||
|
}
|
||||||
|
|
||||||
public function deleteVideoClip(int $podcastId, int $episodeId, int $clipId): BaseResult | bool
|
public function deleteVideoClip(int $podcastId, int $episodeId, int $clipId): BaseResult | bool
|
||||||
{
|
{
|
||||||
$this->clearVideoClipCache($clipId);
|
$this->clearVideoClipCache($clipId);
|
||||||
|
@ -176,11 +176,20 @@ class VideoClipsController extends BaseController
|
|||||||
'updated_by' => user_id(),
|
'updated_by' => user_id(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Check if video clip exists before inserting a new line
|
||||||
|
if ((new ClipModel())->doesVideoClipExist($videoClip)) {
|
||||||
|
// video clip already exists
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->withInput()
|
||||||
|
->with('error', lang('VideoClip.messages.alreadyExistingError'));
|
||||||
|
}
|
||||||
|
|
||||||
(new ClipModel())->insert($videoClip);
|
(new ClipModel())->insert($videoClip);
|
||||||
|
|
||||||
return redirect()->route('video-clips-list', [$this->podcast->id, $this->episode->id])->with(
|
return redirect()->route('video-clips-list', [$this->podcast->id, $this->episode->id])->with(
|
||||||
'message',
|
'message',
|
||||||
lang('Settings.images.regenerationSuccess')
|
lang('VideoClip.messages.addToQueueSuccess')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ return [
|
|||||||
'delete' => 'Delete clip',
|
'delete' => 'Delete clip',
|
||||||
'logs' => 'Job logs',
|
'logs' => 'Job logs',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
'createSuccess' => 'Video clip has been successfully created!',
|
'alreadyExistingError' => 'The video clip you are trying to create already exists!',
|
||||||
|
'addToQueueSuccess' => 'Video clip has been added to queue, awaiting to be created!',
|
||||||
'deleteSuccess' => 'Video clip has been successfully removed!',
|
'deleteSuccess' => 'Video clip has been successfully removed!',
|
||||||
],
|
],
|
||||||
'format' => [
|
'format' => [
|
||||||
|
@ -35,7 +35,8 @@ return [
|
|||||||
'delete' => 'Supprimer l’extrait',
|
'delete' => 'Supprimer l’extrait',
|
||||||
'logs' => 'Historique d’exécution',
|
'logs' => 'Historique d’exécution',
|
||||||
'messages' => [
|
'messages' => [
|
||||||
'createSuccess' => 'L’extrait vidéo a été créé avec succès !',
|
'alreadyExistingError' => 'L’extrait vidéo que vous essayez de créer existe déjà !',
|
||||||
|
'addToQueueSuccess' => 'L’extrait vidéo a été ajouté à la file d’attente, en attente de création !',
|
||||||
'deleteSuccess' => 'L’extrait vidéo a bien été supprimé !',
|
'deleteSuccess' => 'L’extrait vidéo a bien été supprimé !',
|
||||||
],
|
],
|
||||||
'format' => [
|
'format' => [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user