From 042fd6b92d43f895cc298b7f402618cfe9ce5aa4 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 12 Jun 2017 23:51:25 +0000 Subject: [PATCH] Bug 15326: [FOLLOW-UP] Many fixes This patch: - moves action buttons into a dropdown, adds a delete button to dropdown - fixes the tests (they should now all pass) - fixes qa tool problems - removes the Koha::CmsPages->remove() method (unnecessary) - makes changes to the Koha::CmsPages->add() method (now simpler, easier to test) This is now ready to test. Sponsored-by: Catalyst IT --- Koha/CmsPages.pm | 67 ++++------- .../prog/en/modules/tools/cmspages.tt | 43 ++++--- t/db_dependent/Pages.t | 123 ++++++++++++--------- tools/cmspages.pl | 22 +++- 4 files changed, 145 insertions(+), 110 deletions(-) diff --git a/Koha/CmsPages.pm b/Koha/CmsPages.pm index 85a612f..a5ed1ea 100644 --- a/Koha/CmsPages.pm +++ b/Koha/CmsPages.pm @@ -49,49 +49,45 @@ sub object_class { } =head3 add + Adds a new page to the CMS database based on the input data. + =cut sub add { my ( $self, $input ) = @_; carp( 'Koha::CmsPages::add() undefined parameter: input' ) unless defined $input; + my $data = { - parent => scalar $input->param( 'parent' ) eq '' ? undef : scalar $input->param( 'parent' ), - location => scalar $input->param( 'disp' ) eq '' ? undef : scalar $input->param( 'disp'), - branchcode => scalar $input->param( 'branch' ) eq '' ? undef : scalar $input->param( 'branch' ), - lang => scalar $input->param( 'lang' ), - sortorder => scalar $input->param( 'number' ), - title => scalar $input->param( 'title' ), - title_link => scalar $input->param( 'title_link' ), - publish => defined (scalar $input->param( 'publish' )), - content => scalar $input->param( 'content' ) + parent => $input->{parent}, + location => $input->{location}, + branchcode => $input->{branchcode}, + lang => $input->{lang}, + sortorder => $input->{sortorder}, + title => $input->{title}, + title_link => $input->{title_link}, + publish => $input->{publish}, + content => $input->{content} }; - if (defined $input->param( 'id' )) { - $data->{'id'} = scalar $input->param( 'id' ); + if (defined $input->{id}){ + $data->{id} = $input->{id}; } # Ensuring link titles are unique - my $title_link = $input->param('title_link'); - if ( Koha::CmsPages->find({ title_link => $title_link }) ) { - my $existing_link = Koha::CmsPages->find({ title_link => $title_link }); - my $link = $existing_link->unblessed; - unless ( $link->{'id'} eq $input->param('id') ) { - return undef; + my $title_link = $input->{title_link}; + if ( Koha::CmsPages->find({ title_link => $title_link }) ){ + my $link = Koha::CmsPages->find({ title_link => $title_link }); + unless ( $link->id eq $input->{id} ){ + return; } } # Ensuring that, if page has parent, provided location suits parent location - my $parent = $input->param('parent'); - my $parent_obj = Koha::CmsPages->find($parent); - if ( $parent_obj ) { - my $parent_unblessed = $parent_obj->unblessed; - if ( $parent_unblessed->{'location'} ne "" ) { - # if parent location is not all interfaces - if ( $parent_unblessed->{'location'} != $input->param('disp') ) { - # if parent location is not the same as provided location - return undef; - } + my $parent = Koha::CmsPages->find($input->{parent}); + if ( $parent && $parent->location ne "" ){ + if ( $parent->location ne $input->{location} ){ + return; } } @@ -102,7 +98,7 @@ sub add { =head3 list -Lists pages based input filtering paramters for location, branch and language. +Lists pages based input filtering parameters for location, branch and language. =cut @@ -199,21 +195,6 @@ sub child_links { return $rs; } -=head3 remove - -Removes a page identified by id from the CMS database. - -=cut - -sub remove { - my ( $self, @ids ) = @_; - - carp( 'Koha::CmsPages::remove() undefined parameter ids' ) unless @ids; - - my $pages = $self->_resultset()->search({ id => \@ids }); - $pages->delete; -} - =head1 AUTHOR Martin Persson diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cmspages.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cmspages.tt index 901c94d..43dac1a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cmspages.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/cmspages.tt @@ -9,8 +9,6 @@ [% INCLUDE 'datatables.inc' %]