Codebase list libmojomojo-perl / 1016ccc
Prepare work on issue #87: move page deletion to the model Dan Dascalescu 12 years ago
2 changed file(s) with 13 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
296296
297297 =head2 delete
298298
299 Delete a page and it's descendants. This is in Admin.pm because
300 we are restricting page deletion to admins only for the time being.
299 Delete a page and its descendants. This is in L<MojoMojo::Controller::Admin>
300 because we are restricting page deletion to admins only for the time being.
301
302 TODO: this method should reside in the Model, not in a Controller (issue #87).
301303
302304 =cut
303305
304306 sub delete : Global FormConfig {
305 my ( $self, $c, $path ) = @_;
306 my $form = $c->stash->{form};
307 my ( $self, $c ) = @_;
307308 my $stash = $c->stash;
309 my $form = $stash->{form};
308310 $stash->{template} = 'page/delete.tt';
309311 my @descendants;
310312 push @descendants, {
311313 name => $_->name_orig,
312314 id => $_->id,
313315 can_delete => ($_->id == 1) ? 0 : $c->check_permissions($_->path, $c->user)->{delete},
314 } for sort { $a->{path} cmp $b->{path} } $c->stash->{'page'}->descendants;
316 } for sort { $a->{path} cmp $b->{path} } $c->stash->{page}->descendants;
315317 $stash->{descendants} = \@descendants;
316318 $stash->{allowed_to_delete} = ( grep {$_->{can_delete} == 0} @descendants )
317319 ? 0 : 1;
318320 if ( $form->submitted_and_valid && $stash->{allowed_to_delete} ) {
319321 my @deleted_pages;
320322 my @ids_to_delete;
321 for my $page ( $c->stash->{'page'}->descendants ) {
323 for my $page ( $c->stash->{page}->descendants ) {
322324 push @deleted_pages, $page->name_orig;
323325 push @ids_to_delete, $page->id;
324326 # Handling Circular Constraints:
354356 $c->model( $table->{module} )->search( $search )->delete_all;
355357 }
356358 }
357 $stash->{'deleted_pages'} = \@deleted_pages;
358 $stash->{'template'} = 'page/deleted.tt';
359 $stash->{deleted_pages} = \@deleted_pages;
360 $stash->{template} = 'page/deleted.tt';
359361 }
360362 }
361363
00 #!/usr/bin/env perl
1 # TODO: this should call MojoMojo::Controller::Admin::delete() after
2 # that method gets moved to the Model. There's no reason to reinvent
3 # a poor-man's version of page deletion here (issue #87).
14 use strict;
25 use warnings;
36 # WARNING: This script will delete all the children of the page you are deleting.