mirror of
https://code.castopod.org/adaures/castopod
synced 2025-06-23 16:05:34 +00:00
fix: unpublish episode before deleting it + add validation step before deletion
fixes #112, closes #55
This commit is contained in:
parent
b9db936461
commit
f75bd76458
@ -30,7 +30,7 @@ class Checkbox extends FormComponent
|
|||||||
$hint = $this->hint === null ? '' : hint_tooltip($this->hint, 'ml-1');
|
$hint = $this->hint === null ? '' : hint_tooltip($this->hint, 'ml-1');
|
||||||
|
|
||||||
return <<<HTML
|
return <<<HTML
|
||||||
<label class="leading-8">
|
<label class="leading-8 {$this->class}">
|
||||||
{$checkboxInput}
|
{$checkboxInput}
|
||||||
<span class="ml-2">{$this->slot}{$hint}</label>
|
<span class="ml-2">{$this->slot}{$hint}</label>
|
||||||
</label>
|
</label>
|
||||||
|
@ -272,6 +272,14 @@ $routes->group(
|
|||||||
'permission:podcast_episodes-delete',
|
'permission:podcast_episodes-delete',
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
$routes->post(
|
||||||
|
'delete',
|
||||||
|
'EpisodeController::attemptDelete/$1/$2',
|
||||||
|
[
|
||||||
|
'filter' =>
|
||||||
|
'permission:podcast_episodes-delete',
|
||||||
|
],
|
||||||
|
);
|
||||||
$routes->get(
|
$routes->get(
|
||||||
'transcript-delete',
|
'transcript-delete',
|
||||||
'EpisodeController::transcriptDelete/$1/$2',
|
'EpisodeController::transcriptDelete/$1/$2',
|
||||||
|
@ -684,9 +684,63 @@ class EpisodeController extends BaseController
|
|||||||
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]);
|
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete(): RedirectResponse
|
public function delete(): string
|
||||||
{
|
{
|
||||||
(new EpisodeModel())->delete($this->episode->id);
|
helper(['form']);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'podcast' => $this->podcast,
|
||||||
|
'episode' => $this->episode,
|
||||||
|
];
|
||||||
|
|
||||||
|
replace_breadcrumb_params([
|
||||||
|
0 => $this->podcast->title,
|
||||||
|
1 => $this->episode->title,
|
||||||
|
]);
|
||||||
|
return view('episode/delete', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attemptDelete(): RedirectResponse
|
||||||
|
{
|
||||||
|
$rules = [
|
||||||
|
'understand' => 'required',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (! $this->validate($rules)) {
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->withInput()
|
||||||
|
->with('errors', $this->validator->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = db_connect();
|
||||||
|
|
||||||
|
$db->transStart();
|
||||||
|
|
||||||
|
$allPostsLinkedToEpisode = (new PostModel())
|
||||||
|
->where([
|
||||||
|
'episode_id' => $this->episode->id,
|
||||||
|
])
|
||||||
|
->findAll();
|
||||||
|
foreach ($allPostsLinkedToEpisode as $post) {
|
||||||
|
(new PostModel())->removePost($post);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set episode published_at to null to unpublish before deletion
|
||||||
|
$this->episode->published_at = null;
|
||||||
|
|
||||||
|
$episodeModel = new EpisodeModel();
|
||||||
|
if (! $episodeModel->update($this->episode->id, $this->episode)) {
|
||||||
|
$db->transRollback();
|
||||||
|
return redirect()
|
||||||
|
->back()
|
||||||
|
->withInput()
|
||||||
|
->with('errors', $episodeModel->errors());
|
||||||
|
}
|
||||||
|
|
||||||
|
$episodeModel->delete($this->episode->id);
|
||||||
|
|
||||||
|
$db->transComplete();
|
||||||
|
|
||||||
return redirect()->route('episode-list', [$this->podcast->id]);
|
return redirect()->route('episode-list', [$this->podcast->id]);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ return [
|
|||||||
'publish' => 'publish',
|
'publish' => 'publish',
|
||||||
'publish-edit' => 'edit publication',
|
'publish-edit' => 'edit publication',
|
||||||
'unpublish' => 'unpublish',
|
'unpublish' => 'unpublish',
|
||||||
|
'delete' => 'delete',
|
||||||
'fediverse' => 'fediverse',
|
'fediverse' => 'fediverse',
|
||||||
'block-lists' => 'block lists',
|
'block-lists' => 'block lists',
|
||||||
'users' => 'users',
|
'users' => 'users',
|
||||||
|
@ -137,10 +137,16 @@ return [
|
|||||||
],
|
],
|
||||||
'unpublish_form' => [
|
'unpublish_form' => [
|
||||||
'disclaimer' =>
|
'disclaimer' =>
|
||||||
"Unpublishing the episode will delete all the notes associated with the episode and remove it from the podcast's RSS feed.",
|
"Unpublishing the episode will delete all the posts associated with it and remove it from the podcast's RSS feed.",
|
||||||
'understand' => 'I understand, I want to unpublish the episode',
|
'understand' => 'I understand, I want to unpublish the episode',
|
||||||
'submit' => 'Unpublish',
|
'submit' => 'Unpublish',
|
||||||
],
|
],
|
||||||
|
'delete_form' => [
|
||||||
|
'disclaimer' =>
|
||||||
|
"Deleting the episode will delete all the posts associated with it and remove it from the podcast's RSS feed.",
|
||||||
|
'understand' => 'I understand, I want to delete the episode',
|
||||||
|
'submit' => 'Delete',
|
||||||
|
],
|
||||||
'soundbites' => 'Soundbites',
|
'soundbites' => 'Soundbites',
|
||||||
'soundbites_form' => [
|
'soundbites_form' => [
|
||||||
'title' => 'Edit soundbites',
|
'title' => 'Edit soundbites',
|
||||||
|
@ -23,6 +23,7 @@ return [
|
|||||||
'publish' => 'publier',
|
'publish' => 'publier',
|
||||||
'publish-edit' => 'modifier la publication',
|
'publish-edit' => 'modifier la publication',
|
||||||
'unpublish' => 'dépublier',
|
'unpublish' => 'dépublier',
|
||||||
|
'delete' => 'supprimer',
|
||||||
'fediverse' => 'fédiverse',
|
'fediverse' => 'fédiverse',
|
||||||
'block-lists' => 'listes de blocage',
|
'block-lists' => 'listes de blocage',
|
||||||
'users' => 'utilisateurs',
|
'users' => 'utilisateurs',
|
||||||
|
@ -141,6 +141,18 @@ return [
|
|||||||
'message_warning_hint' => 'Ajouter un message augmente l’engagement social, menant à une meilleure visibilité pour votre épisode.',
|
'message_warning_hint' => 'Ajouter un message augmente l’engagement social, menant à une meilleure visibilité pour votre épisode.',
|
||||||
'message_warning_submit' => 'Publish quand même',
|
'message_warning_submit' => 'Publish quand même',
|
||||||
],
|
],
|
||||||
|
'unpublish_form' => [
|
||||||
|
'disclaimer' =>
|
||||||
|
'Dépublier l’épisode supprimera toutes les publications qui lui sont associées et le retirera du flux RSS du podcast.',
|
||||||
|
'understand' => 'Je comprends, je veux dépublier l’épisode',
|
||||||
|
'submit' => 'Dépublier',
|
||||||
|
],
|
||||||
|
'delete_form' => [
|
||||||
|
'disclaimer' =>
|
||||||
|
'Supprimer l’épisode supprimera toutes les publications qui lui sont associées et le retirera du flux RSS du podcast.',
|
||||||
|
'understand' => 'Je comprends, Je veux supprimer l’épisode',
|
||||||
|
'submit' => 'Supprimer',
|
||||||
|
],
|
||||||
'soundbites' => 'Extraits sonores',
|
'soundbites' => 'Extraits sonores',
|
||||||
'soundbites_form' => [
|
'soundbites_form' => [
|
||||||
'title' => 'Modifier les extraits sonores',
|
'title' => 'Modifier les extraits sonores',
|
||||||
|
27
themes/cp_admin/episode/delete.php
Normal file
27
themes/cp_admin/episode/delete.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?= $this->extend('_layout') ?>
|
||||||
|
|
||||||
|
<?= $this->section('title') ?>
|
||||||
|
<?= lang('Episode.delete') ?>
|
||||||
|
<?= $this->endSection() ?>
|
||||||
|
|
||||||
|
<?= $this->section('pageTitle') ?>
|
||||||
|
<?= lang('Episode.delete') ?>
|
||||||
|
<?= $this->endSection() ?>
|
||||||
|
|
||||||
|
<?= $this->section('content') ?>
|
||||||
|
|
||||||
|
<form action="<?= route_to('episode-delete', $podcast->id, $episode->id) ?>" method="POST" class="flex flex-col max-w-xl mx-auto">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
|
||||||
|
<Alert variant="danger" glyph="alert" class="font-semibold"><?= lang('Episode.delete_form.disclaimer') ?></Alert>
|
||||||
|
|
||||||
|
<Forms.Checkbox class="mt-2" name="understand" required="true" isChecked="false"><?= lang('Episode.delete_form.understand') ?></Forms.Checkbox>
|
||||||
|
|
||||||
|
<div class="self-end mt-4">
|
||||||
|
<Button uri="<?= route_to('episode-view', $podcast->id, $episode->id) ?>"><?= lang('Common.cancel') ?></Button>
|
||||||
|
<Button type="submit" variant="danger"><?= lang('Episode.delete_form.submit') ?></Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?= $this->endSection() ?>
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
<Alert variant="danger" glyph="alert" class="font-semibold"><?= lang('Episode.unpublish_form.disclaimer') ?></Alert>
|
<Alert variant="danger" glyph="alert" class="font-semibold"><?= lang('Episode.unpublish_form.disclaimer') ?></Alert>
|
||||||
|
|
||||||
<Forms.Checkbox name="understand" required="true" isChecked="false"><?= lang('Episode.unpublish_form.understand') ?></Forms.Checkbox>
|
<Forms.Checkbox class="mt-2" name="understand" required="true" isChecked="false"><?= lang('Episode.unpublish_form.understand') ?></Forms.Checkbox>
|
||||||
|
|
||||||
<div class="self-end mt-4">
|
<div class="self-end mt-4">
|
||||||
<Button uri="<?= route_to('episode-view', $podcast->id, $episode->id) ?>"><?= lang('Common.cancel') ?></Button>
|
<Button uri="<?= route_to('episode-view', $podcast->id, $episode->id) ?>"><?= lang('Common.cancel') ?></Button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user