Commit dff12087 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(video-clips): check if created video exists before recreating it and failing

update seed scripts to prevent sql error when reloading install page
parent 2385b1a2
Pipeline #1221 passed with stages
in 8 minutes and 53 seconds
......@@ -296,18 +296,24 @@ class AuthSeeder extends Seeder
}
}
$this->db
->table('auth_permissions')
->ignore(true)
->insertBatch($dataPermissions);
$this->db
->table('auth_groups')
->ignore(true)
->insertBatch($dataGroups);
$this->db
->table('auth_groups_permissions')
->ignore(true)
->insertBatch($dataGroupsPermissions);
if ($this->db->table('auth_groups')->countAll() < count($dataPermissions)) {
$this->db
->table('auth_permissions')
->ignore(true)
->insertBatch($dataPermissions);
}
if ($this->db->table('auth_groups')->countAll() < count($dataGroups)) {
$this->db
->table('auth_groups')
->ignore(true)
->insertBatch($dataGroups);
}
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
->table('categories')
->ignore(true)
->insertBatch($data);
foreach ($data as $categoryLine) {
$this->db
->table('categories')
->ignore(true)
->insert($categoryLine);
}
}
}
......@@ -763,9 +763,11 @@ class LanguageSeeder extends Seeder
],
];
$this->db
->table('languages')
->ignore(true)
->insertBatch($data);
foreach ($data as $languageLine) {
$this->db
->table('languages')
->ignore(true)
->insert($languageLine);
}
}
}
......@@ -69,6 +69,11 @@ class VideoClip extends BaseClip
return $this;
}
if ($this->attributes['media_id'] !== null) {
// media is already set, do nothing
return $this;
}
helper('media');
$file = new File(media_path($filePath));
......
......@@ -144,6 +144,27 @@ class ClipModel extends Model
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
{
$this->clearVideoClipCache($clipId);
......
......@@ -176,11 +176,20 @@ class VideoClipsController extends BaseController
'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);
return redirect()->route('video-clips-list', [$this->podcast->id, $this->episode->id])->with(
'message',
lang('Settings.images.regenerationSuccess')
lang('VideoClip.messages.addToQueueSuccess')
);
}
......
......@@ -35,7 +35,8 @@ return [
'delete' => 'Delete clip',
'logs' => 'Job logs',
'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!',
],
'format' => [
......
......@@ -35,7 +35,8 @@ return [
'delete' => 'Supprimer l’extrait',
'logs' => 'Historique d’exécution',
'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é !',
],
'format' => [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment