diff --git a/lib/Ebook.php b/lib/Ebook.php index fba7a098..9579815f 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -2156,6 +2156,27 @@ final class Ebook{ } } + public function Delete(): void{ + $this->RemoveTags(); + $this->RemoveLocSubjects(); + $this->RemoveCollectionMemberships(); + $this->RemoveGitCommits(); + $this->RemoveSources(); + $this->RemoveContributors(); + $this->RemoveTocEntries(); + $this->RemoveEbookPlaceholder(); + + foreach($this->Projects as $project){ + $project->Delete(); + } + + Db::Query(' + DELETE + from Ebooks + where EbookId = ? + ', [$this->EbookId]); + } + // *********** // ORM METHODS // *********** diff --git a/lib/Project.php b/lib/Project.php index e068f0c2..05a5fd87 100644 --- a/lib/Project.php +++ b/lib/Project.php @@ -455,6 +455,20 @@ final class Project{ } } + public function Delete(): void{ + Db::Query(' + DELETE + from ProjectReminders + where ProjectId = ? + ', [$this->ProjectId]); + + Db::Query(' + DELETE + from Projects + where ProjectId = ? + ', [$this->ProjectId]); + } + public function FillFromHttpPost(): void{ $this->PropertyFromHttp('EbookId'); $this->PropertyFromHttp('ProducerName'); diff --git a/templates/EbookMetadata.php b/templates/EbookMetadata.php index c3121305..b668c106 100644 --- a/templates/EbookMetadata.php +++ b/templates/EbookMetadata.php @@ -21,6 +21,16 @@ $showPlaceholderMetadata = $showPlaceholderMetadata ?? false;

Placeholder metadata

Edit placeholder

+
+ Delete placeholder +
+ +

Delete the Ebook, EbookPlaceholder, Project, and other related objects.

+ +
+
diff --git a/www/css/core.css b/www/css/core.css index de484b3f..ebc6b7ce 100644 --- a/www/css/core.css +++ b/www/css/core.css @@ -933,6 +933,14 @@ main.front-page > a.button{ text-align: center; } +button.delete{ + background-color: maroon; +} + +button.delete:hover{ + background-color: firebrick; +} + article.ebook ul, article.ebook ol{ list-style: none; diff --git a/www/ebook-placeholders/new.php b/www/ebook-placeholders/new.php index 4f728aba..330950ff 100644 --- a/www/ebook-placeholders/new.php +++ b/www/ebook-placeholders/new.php @@ -5,9 +5,11 @@ session_start(); $isCreated = HttpInput::Bool(SESSION, 'is-ebook-placeholder-created') ?? false; $isOnlyProjectCreated = HttpInput::Bool(SESSION, 'is-only-ebook-project-created') ?? false; +$isDeleted = HttpInput::Bool(SESSION, 'is-ebook-placeholder-deleted') ?? false; $exception = HttpInput::SessionObject('exception', Exceptions\AppException::class); $ebook = HttpInput::SessionObject('ebook', Ebook::class); $project = HttpInput::SessionObject('project', Project::class); +$deletedEbookTitle = ''; try{ if(Session::$User === null){ @@ -45,6 +47,13 @@ try{ session_unset(); } + elseif($isDeleted){ + if($ebook !== null){ + $deletedEbookTitle = $ebook->Title; + $ebook = null; + } + session_unset(); + } elseif($exception){ // We got here because an `Ebook` submission had errors and the user has to try again. http_response_code(Enums\HttpCode::UnprocessableContent->value); @@ -78,6 +87,8 @@ catch(Exceptions\InvalidPermissionsException){

Ebook placeholder created: Title) ?>!

+ +

Ebook placeholder deleted:

diff --git a/www/ebook-placeholders/post.php b/www/ebook-placeholders/post.php index e0065aca..978a8e1a 100644 --- a/www/ebook-placeholders/post.php +++ b/www/ebook-placeholders/post.php @@ -5,7 +5,7 @@ $ebook = null; try{ session_start(); - $httpMethod = HttpInput::ValidateRequestMethod([Enums\HttpMethod::Post, Enums\HttpMethod::Put]); + $httpMethod = HttpInput::ValidateRequestMethod([Enums\HttpMethod::Post, Enums\HttpMethod::Put, Enums\HttpMethod::Delete]); $exceptionRedirectUrl = '/ebook-placeholders/new'; if(Session::$User === null){ @@ -78,6 +78,20 @@ try{ http_response_code(Enums\HttpCode::SeeOther->value); header('Location: ' . $ebook->Url); } + + // DELETE an `EbookPlaceholder`. + if($httpMethod == Enums\HttpMethod::Delete){ + $ebook = Ebook::GetByIdentifier($identifier); + $exceptionRedirectUrl = $ebook->Url; + + $ebook->Delete(); + + $_SESSION['ebook'] = $ebook; + $_SESSION['is-ebook-placeholder-deleted'] = true; + + http_response_code(Enums\HttpCode::SeeOther->value); + header('Location: /ebook-placeholders/new'); + } } catch(Exceptions\LoginRequiredException){ Template::RedirectToLogin();