Lines 6019-6024
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
Link Here
|
6019 |
SetVersion ($DBversion); |
6019 |
SetVersion ($DBversion); |
6020 |
} |
6020 |
} |
6021 |
|
6021 |
|
|
|
6022 |
$DBversion = "3.09.00.XXX"; |
6023 |
if (C4::Context->preference("Version") < TransformToNum($DBversion)) { |
6024 |
$dbh->do("ALTER TABLE serial ADD published_end_date DATE NULL DEFAULT NULL AFTER publisheddate"); |
6025 |
$dbh->do(" |
6026 |
ALTER TABLE serial ADD serialseq_x VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq, |
6027 |
ADD serialseq_y VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq_x, |
6028 |
ADD serialseq_z VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq_y |
6029 |
"); |
6030 |
$dbh->do(" |
6031 |
ALTER TABLE subscription ADD serialseq_x_label VARCHAR( 100 ) NULL DEFAULT NULL AFTER numberingmethod, |
6032 |
ADD serialseq_y_label VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq_x_label, |
6033 |
ADD serialseq_z_label VARCHAR( 100 ) NULL DEFAULT NULL AFTER serialseq_y_label |
6034 |
"); |
6035 |
|
6036 |
my $trim = sub { |
6037 |
my $string = shift; |
6038 |
$string =~ s/^\s+//; |
6039 |
$string =~ s/\s+$//; |
6040 |
return $string; |
6041 |
}; |
6042 |
|
6043 |
my $dbh = C4::Context->dbh; |
6044 |
my $sth = $dbh->prepare("SELECT * FROM subscription ORDER BY numberingmethod ASC"); |
6045 |
$sth->execute(); |
6046 |
while ( my $subscription = $sth->fetchrow_hashref() ) { |
6047 |
## parse out the labels and save them |
6048 |
my $nm = $subscription->{'numberingmethod'}; |
6049 |
print "NUMBERING METHOD: '$nm'\n"; |
6050 |
my @labels = split(/\{[XYZ]\}[, ]?/, $nm); |
6051 |
@labels = map( $trim->( $_ ), @labels ); |
6052 |
my ( $x_label, $y_label, $z_label ) = @labels; |
6053 |
|
6054 |
$dbh->do( |
6055 |
"UPDATE subscription SET serialseq_x_label = ?, serialseq_y_label = ?, serialseq_z_label = ? WHERE subscriptionid = ?", |
6056 |
undef, |
6057 |
( $x_label, $y_label, $z_label, $subscription->{'subscriptionid'} ) |
6058 |
); |
6059 |
|
6060 |
## parse of the data and save |
6061 |
my @splits = split(/\{[XYZ]\}/, $nm); |
6062 |
foreach my $s ( @splits ) { |
6063 |
$s = quotemeta( $s ); |
6064 |
} |
6065 |
|
6066 |
my $sth2 = $dbh->prepare("SELECT * FROM serial WHERE subscriptionid = ?"); |
6067 |
$sth2->execute( $subscription->{'subscriptionid'} ); |
6068 |
while( my $serial = $sth2->fetchrow_hashref() ) { |
6069 |
my $serialseq = $serial->{'serialseq'}; |
6070 |
my ( $x, $y, $z ); |
6071 |
## We cannot split on multiple values at once, |
6072 |
## so let's replace each of those values with __SPLIT__ |
6073 |
if ( @splits ) { |
6074 |
map( $serialseq =~ s/$_/__SPLIT__/ , @splits ); |
6075 |
( undef, $x, $y, $z ) = split(/__SPLIT__/, $serialseq); |
6076 |
} else { ## Nothing to split on means the only thing in serialseq is {X} |
6077 |
$x = $serialseq; |
6078 |
} |
6079 |
|
6080 |
$dbh->do( |
6081 |
"UPDATE serial SET serialseq_x = ?, serialseq_y = ?, serialseq_z = ? WHERE serialid = ?", |
6082 |
undef, |
6083 |
( $x, $y, $z, $serial->{'serialid'} ) |
6084 |
); |
6085 |
} |
6086 |
} |
6087 |
|
6088 |
print "Upgrade to $DBversion done ( Split serials enumeration data into separate fields )\n"; |
6089 |
SetVersion ($DBversion); |
6090 |
|
6091 |
} |
6092 |
|
6022 |
=head1 FUNCTIONS |
6093 |
=head1 FUNCTIONS |
6023 |
|
6094 |
|
6024 |
=head2 TableExists($table) |
6095 |
=head2 TableExists($table) |
6025 |
- |
|
|