|
Lines 5392-5397
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
Link Here
|
| 5392 |
SetVersion ($DBversion); |
5392 |
SetVersion ($DBversion); |
| 5393 |
} |
5393 |
} |
| 5394 |
|
5394 |
|
|
|
5395 |
$DBversion = "XXX"; |
| 5396 |
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { |
| 5397 |
$dbh->do(qq| |
| 5398 |
DROP TABLE IF EXISTS subscription_frequencies |
| 5399 |
|); |
| 5400 |
$dbh->do(qq| |
| 5401 |
CREATE TABLE subscription_frequencies ( |
| 5402 |
id INTEGER NOT NULL AUTO_INCREMENT, |
| 5403 |
description TEXT NOT NULL, |
| 5404 |
displayorder INT DEFAULT NULL, |
| 5405 |
unit ENUM('day','week','month','year') DEFAULT NULL, |
| 5406 |
unitsperissue INTEGER NOT NULL DEFAULT '1', |
| 5407 |
issuesperunit INTEGER NOT NULL DEFAULT '1', |
| 5408 |
PRIMARY KEY (id) |
| 5409 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
| 5410 |
|); |
| 5411 |
|
| 5412 |
$dbh->do(qq| |
| 5413 |
DROP TABLE IF EXISTS subscription_numberpatterns |
| 5414 |
|); |
| 5415 |
$dbh->do(qq| |
| 5416 |
CREATE TABLE subscription_numberpatterns ( |
| 5417 |
id INTEGER NOT NULL AUTO_INCREMENT, |
| 5418 |
label VARCHAR(255) NOT NULL, |
| 5419 |
displayorder INTEGER DEFAULT NULL, |
| 5420 |
description TEXT NOT NULL, |
| 5421 |
numberingmethod VARCHAR(255) NOT NULL, |
| 5422 |
label1 VARCHAR(255) DEFAULT NULL, |
| 5423 |
add1 INTEGER DEFAULT NULL, |
| 5424 |
every1 INTEGER DEFAULT NULL, |
| 5425 |
whenmorethan1 INTEGER DEFAULT NULL, |
| 5426 |
setto1 INTEGER DEFAULT NULL, |
| 5427 |
numbering1 VARCHAR(255) DEFAULT NULL, |
| 5428 |
label2 VARCHAR(255) DEFAULT NULL, |
| 5429 |
add2 INTEGER DEFAULT NULL, |
| 5430 |
every2 INTEGER DEFAULT NULL, |
| 5431 |
whenmorethan2 INTEGER DEFAULT NULL, |
| 5432 |
setto2 INTEGER DEFAULT NULL, |
| 5433 |
numbering2 VARCHAR(255) DEFAULT NULL, |
| 5434 |
label3 VARCHAR(255) DEFAULT NULL, |
| 5435 |
add3 INTEGER DEFAULT NULL, |
| 5436 |
every3 INTEGER DEFAULT NULL, |
| 5437 |
whenmorethan3 INTEGER DEFAULT NULL, |
| 5438 |
setto3 INTEGER DEFAULT NULL, |
| 5439 |
numbering3 VARCHAR(255) DEFAULT NULL, |
| 5440 |
PRIMARY KEY (id) |
| 5441 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
| 5442 |
|); |
| 5443 |
|
| 5444 |
$dbh->do(qq| |
| 5445 |
INSERT INTO subscription_frequencies (description, unit, unitsperissue, issuesperunit, displayorder) |
| 5446 |
VALUES |
| 5447 |
('2/day', 'day', 1, 2, 1), |
| 5448 |
('1/day', 'day', 1, 1, 2), |
| 5449 |
('3/week', 'week', 1, 3, 3), |
| 5450 |
('1/week', 'week', 1, 1, 4), |
| 5451 |
('1/2 weeks', 'week', 2, 1, 5), |
| 5452 |
('1/3 weeks', 'week', 3, 1, 6), |
| 5453 |
('1/month', 'month', 1, 1, 7), |
| 5454 |
('1/2 months', 'month', 2, 1, 8), |
| 5455 |
('1/3 months', 'month', 3, 1, 9), |
| 5456 |
('2/year', 'month', 6, 1, 10), |
| 5457 |
('1/year', 'year', 1, 1, 11), |
| 5458 |
('1/2 year', 'year', 2, 1, 12), |
| 5459 |
('Irregular', NULL, 1, 1, 13) |
| 5460 |
|); |
| 5461 |
|
| 5462 |
# Used to link existing subscription to newly created frequencies |
| 5463 |
my $frequencies_mapping = { # keys are old frequency numbers, values are the new ones |
| 5464 |
1 => 2, # daily (n/week) |
| 5465 |
2 => 4, # 1/week |
| 5466 |
3 => 5, # 1/2 weeks |
| 5467 |
4 => 6, # 1/3 weeks |
| 5468 |
5 => 7, # 1/month |
| 5469 |
6 => 8, # 1/2 months (6/year) |
| 5470 |
7 => 9, # 1/3 months (1/quarter) |
| 5471 |
8 => 9, # 1/quarter (seasonal) |
| 5472 |
9 => 10, # 2/year |
| 5473 |
10 => 11, # 1/year |
| 5474 |
11 => 12, # 1/2 years |
| 5475 |
12 => 1, # 2/day |
| 5476 |
16 => 13, # Without periodicity |
| 5477 |
32 => 13, # Irregular |
| 5478 |
48 => 13 # Unknown |
| 5479 |
}; |
| 5480 |
|
| 5481 |
$dbh->do(qq| |
| 5482 |
INSERT INTO subscription_numberpatterns |
| 5483 |
(label, displayorder, description, numberingmethod, |
| 5484 |
label1, add1, every1, whenmorethan1, setto1, numbering1, |
| 5485 |
label2, add2, every2, whenmorethan2, setto2, numbering2, |
| 5486 |
label3, add3, every3, whenmorethan3, setto3, numbering3) |
| 5487 |
VALUES |
| 5488 |
('Number', 1, 'Simple Numbering method', 'No.{X}', |
| 5489 |
'Number', 1, 1, 99999, 1, NULL, |
| 5490 |
NULL, NULL, NULL, NULL, NULL, NULL, |
| 5491 |
NULL, NULL, NULL, NULL, NULL, NULL), |
| 5492 |
|
| 5493 |
('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}', |
| 5494 |
'Volume', 1, 48, 99999, 1, NULL, |
| 5495 |
'Number', 1, 4, 12, 1, NULL, |
| 5496 |
'Issue', 1, 1, 4, 1, NULL), |
| 5497 |
|
| 5498 |
('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}', |
| 5499 |
'Volume', 1, 12, 99999, 1, NULL, |
| 5500 |
'Number', 1, 1, 12, 1, NULL, |
| 5501 |
NULL, NULL, NULL, NULL, NULL, NULL), |
| 5502 |
|
| 5503 |
('Seasonal', 4, 'Season Year', '{X} {Y}', |
| 5504 |
'Season', 1, 1, 3, 0, 'season', |
| 5505 |
'Year', 1, 4, 99999, 1, NULL, |
| 5506 |
NULL, NULL, NULL, NULL, NULL, NULL) |
| 5507 |
|); |
| 5508 |
|
| 5509 |
$dbh->do(qq| |
| 5510 |
ALTER TABLE subscription |
| 5511 |
MODIFY COLUMN numberpattern INTEGER DEFAULT NULL, |
| 5512 |
MODIFY COLUMN periodicity INTEGER DEFAULT NULL |
| 5513 |
|); |
| 5514 |
|
| 5515 |
# Update existing subscriptions |
| 5516 |
|
| 5517 |
my $query = qq| |
| 5518 |
SELECT subscriptionid, periodicity, numberingmethod, |
| 5519 |
add1, every1, whenmorethan1, setto1, |
| 5520 |
add2, every2, whenmorethan2, setto2, |
| 5521 |
add3, every3, whenmorethan3, setto3 |
| 5522 |
FROM subscription |
| 5523 |
ORDER BY subscriptionid |
| 5524 |
|; |
| 5525 |
my $sth = $dbh->prepare($query); |
| 5526 |
$sth->execute; |
| 5527 |
my $insert_numberpatterns_sth = $dbh->prepare(qq| |
| 5528 |
INSERT INTO subscription_numberpatterns |
| 5529 |
(label, displayorder, description, numberingmethod, |
| 5530 |
label1, add1, every1, whenmorethan1, setto1, numbering1, |
| 5531 |
label2, add2, every2, whenmorethan2, setto2, numbering2, |
| 5532 |
label3, add3, every3, whenmorethan3, setto3, numbering3) |
| 5533 |
VALUES |
| 5534 |
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
| 5535 |
|); |
| 5536 |
my $update_subscription_sth = $dbh->prepare(qq| |
| 5537 |
UPDATE subscription |
| 5538 |
SET numberpattern = ?, |
| 5539 |
periodicity = ? |
| 5540 |
WHERE subscriptionid = ? |
| 5541 |
|); |
| 5542 |
|
| 5543 |
my $i = 1; |
| 5544 |
while(my $sub = $sth->fetchrow_hashref) { |
| 5545 |
# Create a new numbering pattern for each subscription |
| 5546 |
my $ok = $insert_numberpatterns_sth->execute( |
| 5547 |
"Backup pattern $i", 4+$i, "Automatically created pattern by updatedatabase", $sub->{numberingmethod}, |
| 5548 |
"X", $sub->{add1}, $sub->{every1}, $sub->{whenmorethan1}, $sub->{setto1}, undef, |
| 5549 |
"Y", $sub->{add2}, $sub->{every2}, $sub->{whenmorethan2}, $sub->{setto2}, undef, |
| 5550 |
"Z", $sub->{add3}, $sub->{every3}, $sub->{whenmorethan3}, $sub->{setto3}, undef |
| 5551 |
); |
| 5552 |
if($ok) { |
| 5553 |
my $id = $dbh->last_insert_id(undef, undef, 'subscription_numberpatterns', undef); |
| 5554 |
# Link to subscription_numberpatterns and subscription_frequencies |
| 5555 |
$update_subscription_sth->execute($id, |
| 5556 |
$frequencies_mapping->{$sub->{periodicity}}, $sub->{subscriptionid}); |
| 5557 |
} |
| 5558 |
$i++; |
| 5559 |
} |
| 5560 |
|
| 5561 |
# Remove now useless columns |
| 5562 |
$dbh->do(qq| |
| 5563 |
ALTER TABLE subscription |
| 5564 |
DROP COLUMN numberingmethod, |
| 5565 |
DROP COLUMN add1, |
| 5566 |
DROP COLUMN every1, |
| 5567 |
DROP COLUMN whenmorethan1, |
| 5568 |
DROP COLUMN setto1, |
| 5569 |
DROP COLUMN add2, |
| 5570 |
DROP COLUMN every2, |
| 5571 |
DROP COLUMN whenmorethan2, |
| 5572 |
DROP COLUMN setto2, |
| 5573 |
DROP COLUMN add3, |
| 5574 |
DROP COLUMN every3, |
| 5575 |
DROP COLUMN whenmorethan3, |
| 5576 |
DROP COLUMN setto3, |
| 5577 |
DROP COLUMN dow, |
| 5578 |
DROP COLUMN issuesatonce, |
| 5579 |
DROP COLUMN hemisphere, |
| 5580 |
ADD COLUMN countissuesperunit INTEGER NOT NULL DEFAULT 0 AFTER periodicity, |
| 5581 |
ADD COLUMN skip_serialseq BOOLEAN NOT NULL DEFAULT 0 AFTER irregularity, |
| 5582 |
ADD COLUMN locale VARCHAR(80) DEFAULT NULL AFTER numberpattern, |
| 5583 |
ADD CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id), |
| 5584 |
ADD CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) |
| 5585 |
|); |
| 5586 |
|
| 5587 |
print "Upgrade to $DBversion done (Add subscription_frequencies and subscription_numberpatterns tables)\n"; |
| 5588 |
SetVersion($DBversion); |
| 5589 |
} |
| 5590 |
|
| 5395 |
=head1 FUNCTIONS |
5591 |
=head1 FUNCTIONS |
| 5396 |
|
5592 |
|
| 5397 |
=head2 TableExists($table) |
5593 |
=head2 TableExists($table) |
| 5398 |
- |
|
|