Skip to content
Browse files

Prepare work on issue #87: move page deletion to the model

  • Loading branch information...
1 parent 6a972af commit 97d4bc9c0818dab6bfff59847c2aff26383ecee9 @dandv dandv committed with Aug 13, 2011
Showing with 13 additions and 8 deletions.
  1. +10 −8 lib/MojoMojo/Controller/Admin.pm
  2. +3 −0 script/util/delete_page.pl
View
18 lib/MojoMojo/Controller/Admin.pm
@@ -297,29 +297,31 @@ sub precompile_pages : Global {
=head2 delete
-Delete a page and it's descendants. This is in Admin.pm because
-we are restricting page deletion to admins only for the time being.
+Delete a page and its descendants. This is in L<MojoMojo::Controller::Admin>
+because we are restricting page deletion to admins only for the time being.
+
+TODO: this method should reside in the Model, not in a Controller (issue #87).
=cut
sub delete : Global FormConfig {
- my ( $self, $c, $path ) = @_;
- my $form = $c->stash->{form};
+ my ( $self, $c ) = @_;
my $stash = $c->stash;
+ my $form = $stash->{form};
$stash->{template} = 'page/delete.tt';
my @descendants;
push @descendants, {
name => $_->name_orig,
id => $_->id,
can_delete => ($_->id == 1) ? 0 : $c->check_permissions($_->path, $c->user)->{delete},
- } for sort { $a->{path} cmp $b->{path} } $c->stash->{'page'}->descendants;
+ } for sort { $a->{path} cmp $b->{path} } $c->stash->{page}->descendants;
$stash->{descendants} = \@descendants;
$stash->{allowed_to_delete} = ( grep {$_->{can_delete} == 0} @descendants )
? 0 : 1;
if ( $form->submitted_and_valid && $stash->{allowed_to_delete} ) {
my @deleted_pages;
my @ids_to_delete;
- for my $page ( $c->stash->{'page'}->descendants ) {
+ for my $page ( $c->stash->{page}->descendants ) {
push @deleted_pages, $page->name_orig;
push @ids_to_delete, $page->id;
# Handling Circular Constraints:
@@ -355,8 +357,8 @@ sub delete : Global FormConfig {
$c->model( $table->{module} )->search( $search )->delete_all;
}
}
- $stash->{'deleted_pages'} = \@deleted_pages;
- $stash->{'template'} = 'page/deleted.tt';
+ $stash->{deleted_pages} = \@deleted_pages;
+ $stash->{template} = 'page/deleted.tt';
}
}
View
3 script/util/delete_page.pl
@@ -1,4 +1,7 @@
#!/usr/bin/env perl
+# TODO: this should call MojoMojo::Controller::Admin::delete() after
+# that method gets moved to the Model. There's no reason to reinvent
+# a poor-man's version of page deletion here (issue #87).
use strict;
use warnings;
# WARNING: This script will delete all the children of the page you are deleting.

0 comments on commit 97d4bc9

Please sign in to comment.
Something went wrong with that request. Please try again.