MojoMojo
view release on metacpan or search on metacpan
lib/MojoMojo/Controller/Admin.pm view on Meta::CPAN
=head2 handle_role_form
Handle role form processing.
Returns true when a submitted form was actually processed.
=cut
sub handle_role_form : Private {
my ( $self, $c, $role ) = @_;
my $form = $c->stash->{form};
if ( $form->submitted_and_valid ) {
my $params = $form->params;
my $fields = {
name => $params->{name},
active => ( $params->{active} ? 1 : 0 )
};
# make sure updating works
$fields->{id} = $role->id if $role;
$role = $c->model('DBIC::Role')->update_or_create($fields);
if ($role) {
# in order to safely update the role members, they're removed and
# then reinserted - this is a bit inefficient but updating role
# members shouldn't be a frequent operation
$role->role_members->delete;
if ( $params->{role_members} ) {
my @role_members =
ref $params->{role_members} eq 'ARRAY'
? @{ $params->{role_members} }
: $params->{role_members};
for my $person_id (@role_members) {
$role->add_to_role_members(
{
person => $person_id,
admin => 0
}
);
}
}
$c->res->redirect( $c->uri_for('admin/role') );
}
return 1;
}
}
=head2 update_user ( *private*)
Update user based on user listing.
=cut
sub update_user : Local {
my ( $self, $c, $user ) = @_;
$user = $c->model("DBIC::Person")->find($user) || return;
# if ($action eq 'active') {
$user->active( ($user->active == 1) ? 0 : 1 );
# }
$user->update;
$c->stash->{user} = $user;
}
=head2 precompile_pages
Make a formatted version of content body and store it in content.precompiled.
This makes MojoMojo go zing, when loading content for page requests.
Depending on the number of pages, and versions of them, this could take some minutes.
For 2000 page versions on a 2.4 GHz desktop this script took about 3 minutes to run.
=cut
sub precompile_pages : Global {
my ( $self, $c ) = @_;
my $content_rs = $c->model('DBIC::Content');
while ( my $content_record = $content_rs->next ) {
my $body = $content_record->body;
next if !$body;
my $page = $content_record->page;
# Get path from path_pages_by_id().
my @path_pages = $c->model('DBIC::Page')->path_pages_by_id( $page->id );
my @node_names = map { $_->name } @path_pages;
my $path = join( '/', @node_names );
# Collapse leading '//' into '/' since '/' is first in path
# since we just joined with '/'.
$path =~ s{^//}{/};
$c->stash->{path} = $path;
$c->call_plugins( "format_content", \$body, $c, $page );
$body = '' if $c->stash->{precompile_off};
$content_record->precompiled($body);
$content_record->update;
# Reset precompile_off
$c->stash->{precompile_off} = 0;
}
$c->response->body('Precompile Done.');
return;
}
=head2 delete
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
( run in 1.743 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )