Skip to content

Commit

Permalink
Relocate code to model
Browse files Browse the repository at this point in the history
  • Loading branch information
melmothx committed Jan 15, 2024
1 parent 59c849d commit 0c19bb4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
19 changes: 1 addition & 18 deletions lib/AmuseWikiFarm/Controller/Nodes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,7 @@ sub title :Chained('admin') :PathPart('text') :Args(1) {
my $params = $c->request->body_params;
if ($title_id =~ m/$int/) {
if (my $title = $site->titles->texts_only->find($title_id)) {
if (my $removals = $params->{remove_node}) {
my @ids = ref($removals) ? @$removals : ($removals);
if (@ids) {
$title->node_titles->search({ node_id => \@ids })->delete;
$ok++;
}
}
if (my $nid = $params->{add_node_id}) {
if ($nid =~ m/$int/) {
if (my $node = $site->nodes->find($nid)) {
unless ($title->nodes->find($nid)) {
$title->add_to_nodes($node);
$ok++;
}
}
}
}
if ($ok) {
if ($title->edit_collections($params)) {
$c->flash(status_msg => $c->loc("Thanks!"));
}
return $c->response->redirect($c->uri_for($title->full_uri));
Expand Down
26 changes: 26 additions & 0 deletions lib/AmuseWikiFarm/Schema/Result/Title.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,32 @@ sub aggregate {
return $ok;
}

sub edit_collections {
my ($self, $params) = @_;
my $ok = 0;
my $int = qr{\A[0-9]+\z}a;
if (my $removals = $params->{remove_node}) {
if (my @ids = grep { /$int/ } (ref($removals) ? @$removals : ($removals))){
$self->node_titles->search({ node_id => \@ids })->delete;
$ok++;
}
}
if (my $nid = $params->{add_node_id}) {
if ($nid =~ m/$int/) {
if (my $node = $self->site->nodes->find($nid)) {
unless ($self->nodes->find($nid)) {
$self->add_to_nodes($node);
$ok++;
}
}
}
}
if ($ok) {
$self->oai_pmh_records->bump_datestamp;
}
return $ok;
}

__PACKAGE__->meta->make_immutable;

1;

0 comments on commit 0c19bb4

Please sign in to comment.