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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -35,7 +35,8 @@ return [
'delete' => 'Supprimer lextrait', 'delete' => 'Supprimer lextrait',
'logs' => 'Historique dexécution', 'logs' => 'Historique dexécution',
'messages' => [ '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é!', 'deleteSuccess' => 'Lextrait vidéo a bien été supprimé!',
], ],
'format' => [ 'format' => [