Lines 5677-5682
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
Link Here
|
5677 |
VALUES |
5677 |
VALUES |
5678 |
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
5678 |
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
5679 |
|); |
5679 |
|); |
|
|
5680 |
my $check_numberpatterns_sth = $dbh->prepare(qq| |
5681 |
SELECT * FROM subscription_numberpatterns |
5682 |
WHERE add1 = ? AND add2 = ? AND add3 = ? |
5683 |
AND every1 = ? AND every2 = ? AND every3 = ? |
5684 |
AND whenmorethan1 = ? AND whenmorethan2 = ? AND whenmorethan3 = ? |
5685 |
AND setto1 = ? AND setto2 = ? AND setto3 = ? |
5686 |
AND numberingmethod = ? |
5687 |
LIMIT 1 |
5688 |
|); |
5680 |
my $update_subscription_sth = $dbh->prepare(qq| |
5689 |
my $update_subscription_sth = $dbh->prepare(qq| |
5681 |
UPDATE subscription |
5690 |
UPDATE subscription |
5682 |
SET numberpattern = ?, |
5691 |
SET numberpattern = ?, |
Lines 5686-5705
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
Link Here
|
5686 |
|
5695 |
|
5687 |
my $i = 1; |
5696 |
my $i = 1; |
5688 |
while(my $sub = $sth->fetchrow_hashref) { |
5697 |
while(my $sub = $sth->fetchrow_hashref) { |
5689 |
# Create a new numbering pattern for each subscription |
5698 |
$check_numberpatterns_sth->execute( |
5690 |
my $ok = $insert_numberpatterns_sth->execute( |
5699 |
$sub->{add1}, $sub->{add2}, $sub->{add3}, |
5691 |
"Backup pattern $i", 4+$i, "Automatically created pattern by updatedatabase", $sub->{numberingmethod}, |
5700 |
$sub->{every1}, $sub->{every2}, $sub->{every3}, |
5692 |
"X", $sub->{add1}, $sub->{every1}, $sub->{whenmorethan1}, $sub->{setto1}, undef, |
5701 |
$sub->{whenmorethan1}, $sub->{whenmorethan2}, $sub->{whenmorethan3}, |
5693 |
"Y", $sub->{add2}, $sub->{every2}, $sub->{whenmorethan2}, $sub->{setto2}, undef, |
5702 |
$sub->{setto1}, $sub->{setto2}, $sub->{setto3}, |
5694 |
"Z", $sub->{add3}, $sub->{every3}, $sub->{whenmorethan3}, $sub->{setto3}, undef |
5703 |
$sub->{numberingmethod} |
5695 |
); |
5704 |
); |
5696 |
if($ok) { |
5705 |
my $p = $check_numberpatterns_sth->fetchrow_hashref; |
5697 |
my $id = $dbh->last_insert_id(undef, undef, 'subscription_numberpatterns', undef); |
5706 |
if (defined $p) { |
5698 |
# Link to subscription_numberpatterns and subscription_frequencies |
5707 |
# Pattern already exists, link to it |
5699 |
$update_subscription_sth->execute($id, |
5708 |
$update_subscription_sth->execute($p->{id}, |
5700 |
$frequencies_mapping->{$sub->{periodicity}}, $sub->{subscriptionid}); |
5709 |
$frequencies_mapping->{$sub->{periodicity}}, |
|
|
5710 |
$sub->{subscriptionid}); |
5711 |
} else { |
5712 |
# Create a new numbering pattern for this subscription |
5713 |
my $ok = $insert_numberpatterns_sth->execute( |
5714 |
"Backup pattern $i", 4+$i, "Automatically created pattern by updatedatabase", $sub->{numberingmethod}, |
5715 |
"X", $sub->{add1}, $sub->{every1}, $sub->{whenmorethan1}, $sub->{setto1}, undef, |
5716 |
"Y", $sub->{add2}, $sub->{every2}, $sub->{whenmorethan2}, $sub->{setto2}, undef, |
5717 |
"Z", $sub->{add3}, $sub->{every3}, $sub->{whenmorethan3}, $sub->{setto3}, undef |
5718 |
); |
5719 |
if($ok) { |
5720 |
my $id = $dbh->last_insert_id(undef, undef, 'subscription_numberpatterns', undef); |
5721 |
# Link to subscription_numberpatterns and subscription_frequencies |
5722 |
$update_subscription_sth->execute($id, |
5723 |
$frequencies_mapping->{$sub->{periodicity}}, |
5724 |
$sub->{subscriptionid}); |
5725 |
} |
5726 |
$i++; |
5701 |
} |
5727 |
} |
5702 |
$i++; |
|
|
5703 |
} |
5728 |
} |
5704 |
|
5729 |
|
5705 |
# Remove now useless columns |
5730 |
# Remove now useless columns |
Lines 5724-5731
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
Link Here
|
5724 |
ADD COLUMN countissuesperunit INTEGER NOT NULL DEFAULT 1 AFTER periodicity, |
5749 |
ADD COLUMN countissuesperunit INTEGER NOT NULL DEFAULT 1 AFTER periodicity, |
5725 |
ADD COLUMN skip_serialseq BOOLEAN NOT NULL DEFAULT 0 AFTER irregularity, |
5750 |
ADD COLUMN skip_serialseq BOOLEAN NOT NULL DEFAULT 0 AFTER irregularity, |
5726 |
ADD COLUMN locale VARCHAR(80) DEFAULT NULL AFTER numberpattern, |
5751 |
ADD COLUMN locale VARCHAR(80) DEFAULT NULL AFTER numberpattern, |
5727 |
ADD CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id), |
5752 |
ADD CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE, |
5728 |
ADD CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) |
5753 |
ADD CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE |
5729 |
|); |
5754 |
|); |
5730 |
|
5755 |
|
5731 |
print "Upgrade to $DBversion done (Add subscription_frequencies and subscription_numberpatterns tables)\n"; |
5756 |
print "Upgrade to $DBversion done (Add subscription_frequencies and subscription_numberpatterns tables)\n"; |