View | Details | Raw Unified | Return to bug 8956
Collapse All | Expand All

(-)a/installer/data/mysql/updatedatabase.pl (-1 / +70 lines)
Lines 6444-6449 if ( CheckVersion($DBversion) ) { Link Here
6444
    SetVersion($DBversion);
6444
    SetVersion($DBversion);
6445
}
6445
}
6446
6446
6447
$DBversion = "3.11.00.XXX";
6448
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
6449
   $dbh->do("ALTER TABLE serial ADD published_end_date DATE NULL DEFAULT NULL AFTER publisheddate");
6450
   $dbh->do("
6451
       ALTER TABLE  serial ADD serialseq_x VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq,
6452
       ADD serialseq_y VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq_x,
6453
       ADD serialseq_z VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq_y
6454
   ");
6455
   $dbh->do("
6456
       ALTER TABLE subscription ADD serialseq_x_label VARCHAR( 100 ) NULL DEFAULT NULL AFTER numberingmethod,
6457
       ADD serialseq_y_label VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq_x_label,
6458
       ADD serialseq_z_label VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq_y_label
6459
   ");
6460
6461
    my $trim = sub {
6462
        my $string = shift;
6463
        $string =~ s/^\s+//;
6464
        $string =~ s/\s+$//;
6465
        return $string;
6466
    };
6467
6468
   my $dbh = C4::Context->dbh;
6469
   my $sth = $dbh->prepare("SELECT * FROM subscription ORDER BY numberingmethod ASC");
6470
   $sth->execute();
6471
   while ( my $subscription = $sth->fetchrow_hashref() ) {
6472
       ## parse out the labels and save them
6473
       my $nm = $subscription->{'numberingmethod'};
6474
       print "NUMBERING METHOD: '$nm'\n";
6475
       my @labels = split(/\{[XYZ]\}[, ]?/, $nm);
6476
       @labels = map( $trim->( $_ ), @labels );
6477
       my ( $x_label, $y_label, $z_label ) = @labels;
6478
6479
       $dbh->do(
6480
           "UPDATE subscription SET serialseq_x_label = ?, serialseq_y_label = ?, serialseq_z_label = ? WHERE subscriptionid = ?",
6481
           undef,
6482
           ( $x_label, $y_label, $z_label, $subscription->{'subscriptionid'} )
6483
       );
6484
6485
       ## parse of the data and save
6486
       my @splits = split(/\{[XYZ]\}/, $nm);
6487
       foreach my $s ( @splits ) {
6488
           $s = quotemeta( $s );
6489
       }
6490
6491
       my $sth2 = $dbh->prepare("SELECT * FROM serial WHERE subscriptionid = ?");
6492
       $sth2->execute( $subscription->{'subscriptionid'} );
6493
       while( my $serial = $sth2->fetchrow_hashref() ) {
6494
           my $serialseq = $serial->{'serialseq'};
6495
           my ( $x, $y, $z );
6496
           ## We cannot split on multiple values at once,
6497
           ## so let's replace each of those values with __SPLIT__
6498
           if ( @splits ) {
6499
               map( $serialseq =~ s/$_/__SPLIT__/ , @splits );
6500
               ( undef, $x, $y, $z ) = split(/__SPLIT__/, $serialseq);
6501
           } else { ## Nothing to split on means the only thing in serialseq is {X}
6502
               $x = $serialseq;
6503
           }
6504
6505
           $dbh->do(
6506
               "UPDATE serial SET serialseq_x = ?, serialseq_y = ?, serialseq_z = ? WHERE serialid = ?",
6507
               undef,
6508
               ( $x, $y, $z, $serial->{'serialid'} )
6509
           );
6510
       }
6511
   }
6512
6513
   print "Upgrade to $DBversion done ( Split serials enumeration data into separate fields )\n";
6514
   SetVersion ($DBversion);
6515
6516
}
6447
6517
6448
$DBversion = "3.11.00.024";
6518
$DBversion = "3.11.00.024";
6449
if ( CheckVersion($DBversion) ) {
6519
if ( CheckVersion($DBversion) ) {
6450
- 

Return to bug 8956