From db57abd0171b6ca173fe03fd585d8f71cafb42da Mon Sep 17 00:00:00 2001 From: Blog Manager Robot Date: Sat, 29 Oct 2022 03:18:23 +0000 Subject: [PATCH] Blog history restores now. --- Web/lib/MJB/Web/Controller/Dashboard.pm | 28 +++++++++++++++++++ Web/templates/dashboard/blog_history.html.ep | 10 +++---- .../lib/MJB/Backend/Jekyll.pm | 20 +++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/Web/lib/MJB/Web/Controller/Dashboard.pm b/Web/lib/MJB/Web/Controller/Dashboard.pm index af451f4..39141b9 100644 --- a/Web/lib/MJB/Web/Controller/Dashboard.pm +++ b/Web/lib/MJB/Web/Controller/Dashboard.pm @@ -364,5 +364,33 @@ sub blog_history ( $c ) { my $history = $c->stash->{history} = $c->jekyll($blog->domain->name)->history; } +sub do_blog_history ( $c ) { + my $blog = $c->stash->{blog} = $c->db->blog( $c->param('id') ); + + if ( $blog->person->id ne $c->stash->{person}->id ) { + $c->render( + text => "Error: This blog isn't owned by you.", + status => 404, + format => 'txt', + ); + return; + } + + my $commit = $c->param('commit_hash'); + + my $jekyll = $c->jekyll($blog->domain->name); + + my $history = $c->stash->{history} = $jekyll->history; + + my ( $old_commit ) = grep { $_->{commit} eq $commit } @{$history}; + + if ( $old_commit ) { + $jekyll->revert_commit( $commit ); + + $c->flash( confirmation => "Undid $commit!" ); + $c->redirect_to( $c->url_for( 'show_dashboard_blog_history', { id => $blog->id } ) ); + } +} + 1; diff --git a/Web/templates/dashboard/blog_history.html.ep b/Web/templates/dashboard/blog_history.html.ep index c0b8bbd..5be18b8 100644 --- a/Web/templates/dashboard/blog_history.html.ep +++ b/Web/templates/dashboard/blog_history.html.ep @@ -1,6 +1,6 @@ % layout 'standard', title => 'Dashboard', sb_active => 'dashboard'; -%= include 'dashboard/_blog_nav', page => 'posts' +%= include 'dashboard/_blog_nav', page => 'history' % if ( my $confirmation = flash 'confirmation' ) {