Blog history restores now.

master
Blog Manager Robot 3 years ago
parent 87359931f0
commit db57abd017
  1. 28
      Web/lib/MJB/Web/Controller/Dashboard.pm
  2. 10
      Web/templates/dashboard/blog_history.html.ep
  3. 20
      libs/MJB-Backend-Jekyll/lib/MJB/Backend/Jekyll.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;

@ -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' ) {
<div style="margin-top: 2em" class="alert alert-success" role="alert">
@ -32,7 +32,7 @@
<tr>
<th class="text-nowrap">When?</th>
<th class="text-nowrap">What?</th>
<th class="text-nowrap">Restore?</th>
<th class="text-nowrap">Action</th>
</tr>
</thead>
<tbody>
@ -41,9 +41,9 @@
<td><%= $change->{dateref} %></a></td>
<td><%= $change->{message} %></a></td>
<td>
<form style="margin-top: 1.5em" method="POST" action="<%= $c->url_for( 'do_dashboard_blog_history' ) %>">
<input type="hidden" name="commit_id" value="<%= $change->{commit} %>">
<button type="submit" class="btn btn-sm btn-primary float-end">Restore</button>
<form style="margin-top: 1.5em; display: inline;" method="POST" action="<%= $c->url_for( 'do_dashboard_blog_history' ) %>">
<input type="hidden" name="commit_hash" value="<%= $change->{commit} %>">
<button type="submit" class="btn btn-sm btn-primary">Undo Change</button>
</form>
</td>
</tr>

@ -282,6 +282,26 @@ sub remove_file {
}
sub revert_commit {
my ( $self, $commit ) = @_;
# Check that the repo exists and is latest.
$self->_ensure_repository_is_latest;
# Add the file to git
$self->system_command( [ qw( git revert --no-edit ), $commit ], {
chdir => $self->repo_path,
});
# Push the repo to the store server
$self->system_command( [ qw( git push origin master ) ], {
chdir => $self->repo_path,
});
return 1;
}
sub delete_post {
my ( $self, $title, $file ) = @_;

Loading…
Cancel
Save