bug 5327 added unit test for C4/Csv.pm
[koha.git] / cataloguing / merge.pl
index 6398016..0b881f1 100755 (executable)
@@ -2,6 +2,7 @@
 
 
 # Copyright 2009 BibLibre
+# Parts Copyright Catalyst IT 2011
 #
 # This file is part of Koha.
 #
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
+#use warnings; FIXME - Bug 2505
 use CGI;
 use C4::Output;
 use C4::Auth;
 use C4::Items;
 use C4::Biblio;
 use C4::Serials;
-use YAML;
+use C4::Reserves qw/MergeHolds/;
 
 my $input = new CGI;
 my @biblionumber = $input->param('biblionumber');
@@ -48,12 +50,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 #------------------------
 if ($merge) {
 
-    my @params = $input->param();
     my $dbh = C4::Context->dbh;
     my $sth;
 
     # Creating a new record from the html code
-    my $record       = TransformHtmlToMarc( \@params , $input );
+    my $record       = TransformHtmlToMarc( $input );
     my $tobiblio     =  $input->param('biblio1');
     my $frombiblio   =  $input->param('biblio2');
 
@@ -68,7 +69,6 @@ if ($merge) {
 
     # Moving items from the other record to the reference record
     my $itemnumbers = get_itemnumbers_of($frombiblio);
-    use Data::Dumper;
     foreach my $itloop ($itemnumbers->{$frombiblio}) {
        foreach my $itemnumber (@$itloop) {
            my $res = MoveItemFromBiblio($itemnumber, $frombiblio, $tobiblio);
@@ -102,6 +102,8 @@ if ($merge) {
 
     # Deleting the other record
     if (scalar(@errors) == 0) {
+       # Move holds
+       MergeHolds($dbh,$tobiblio,$frombiblio);
        my $error = DelBiblio($frombiblio);
        push @errors, $error if ($error); 
     }
@@ -110,11 +112,11 @@ if ($merge) {
     my @errors_loop  = map{{error => $_}}@errors;
 
     # Parameters
-    $template->param({
+    $template->param(
        errors  => \@errors_loop,
        result => 1,
        biblio1 => $input->param('biblio1')
-    });
+    );
 
 
 #-------------------------
@@ -130,13 +132,13 @@ if ($merge) {
 
     # Ask the user to choose which record will be the kept
     if (not $mergereference) {
-       $template->param({
+       $template->param(
            choosereference => 1,       
            biblio1 => $biblionumber[0],
            biblio2 => $biblionumber[1],
            title1 => $data1->{'title'},
            title2 => $data2->{'title'}
-           });
+           );
     } else {
 
        if (scalar(@biblionumber) != 2) {
@@ -166,7 +168,7 @@ if ($merge) {
        my @errors_loop  = map{{error => $_}}@errors;
 
        # Parameters
-       $template->param({
+       $template->param(
            errors  => \@errors_loop,
            biblio1 => $mergereference,
            biblio2 => $notreference,
@@ -174,12 +176,15 @@ if ($merge) {
            record1 => @record1,
            record2 => @record2,
            framework => $framework
-           });
+           );
     }
 }
 output_html_with_http_headers $input, $cookie, $template->output;
 exit;
 
+=head1 FUNCTIONS
+
+=cut
 
 # ------------------------
 # Functions
@@ -239,14 +244,15 @@ sub _createMarcHash {
 
 }
 
-=item CreateKey
+=head2 CreateKey
 
-    Create a random value to set it into the input name
+Create a random value to set it into the input name
 
 =cut
 
-sub createKey(){
+sub createKey {
     return int(rand(1000000));
 }
 
 
+