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:
Yassine Doghri 2022-01-21 17:25:27 +00:00
parent 2385b1a292
commit dff1208725
8 changed files with 70 additions and 23 deletions

View File

@ -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);
}
}
/**

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -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));

View File

@ -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);

View File

@ -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')
);
}

View File

@ -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' => [

View File

@ -35,7 +35,8 @@ return [
'delete' => 'Supprimer lextrait',
'logs' => 'Historique dexécution',
'messages' => [
'createSuccess' => 'Lextrait vidéo a été créé avec succès!',
'alreadyExistingError' => 'Lextrait vidéo que vous essayez de créer existe déjà!',
'addToQueueSuccess' => 'Lextrait vidéo a été ajouté à la file dattente, en attente de création!',
'deleteSuccess' => 'Lextrait vidéo a bien été supprimé!',
],
'format' => [