296 | 296 |
|
297 | 297 |
=head2 delete
|
298 | 298 |
|
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).
|
301 | 303 |
|
302 | 304 |
=cut
|
303 | 305 |
|
304 | 306 |
sub delete : Global FormConfig {
|
305 | |
my ( $self, $c, $path ) = @_;
|
306 | |
my $form = $c->stash->{form};
|
|
307 |
my ( $self, $c ) = @_;
|
307 | 308 |
my $stash = $c->stash;
|
|
309 |
my $form = $stash->{form};
|
308 | 310 |
$stash->{template} = 'page/delete.tt';
|
309 | 311 |
my @descendants;
|
310 | 312 |
push @descendants, {
|
311 | 313 |
name => $_->name_orig,
|
312 | 314 |
id => $_->id,
|
313 | 315 |
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;
|
315 | 317 |
$stash->{descendants} = \@descendants;
|
316 | 318 |
$stash->{allowed_to_delete} = ( grep {$_->{can_delete} == 0} @descendants )
|
317 | 319 |
? 0 : 1;
|
318 | 320 |
if ( $form->submitted_and_valid && $stash->{allowed_to_delete} ) {
|
319 | 321 |
my @deleted_pages;
|
320 | 322 |
my @ids_to_delete;
|
321 | |
for my $page ( $c->stash->{'page'}->descendants ) {
|
|
323 |
for my $page ( $c->stash->{page}->descendants ) {
|
322 | 324 |
push @deleted_pages, $page->name_orig;
|
323 | 325 |
push @ids_to_delete, $page->id;
|
324 | 326 |
# Handling Circular Constraints:
|
|
354 | 356 |
$c->model( $table->{module} )->search( $search )->delete_all;
|
355 | 357 |
}
|
356 | 358 |
}
|
357 | |
$stash->{'deleted_pages'} = \@deleted_pages;
|
358 | |
$stash->{'template'} = 'page/deleted.tt';
|
|
359 |
$stash->{deleted_pages} = \@deleted_pages;
|
|
360 |
$stash->{template} = 'page/deleted.tt';
|
359 | 361 |
}
|
360 | 362 |
}
|
361 | 363 |
|