Lines 5343-5348
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
Link Here
|
5343 |
SetVersion($DBversion); |
5343 |
SetVersion($DBversion); |
5344 |
} |
5344 |
} |
5345 |
|
5345 |
|
|
|
5346 |
$DBversion = "XXX"; |
5347 |
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { |
5348 |
$dbh->do(qq| |
5349 |
DROP TABLE IF EXISTS subscription_frequencies |
5350 |
|); |
5351 |
$dbh->do(qq| |
5352 |
CREATE TABLE subscription_frequencies ( |
5353 |
id INTEGER NOT NULL AUTO_INCREMENT, |
5354 |
description TEXT NOT NULL, |
5355 |
displayorder INT DEFAULT NULL, |
5356 |
unit ENUM('day','week','month','year') DEFAULT NULL, |
5357 |
unitsperissue INTEGER NOT NULL DEFAULT '1', |
5358 |
issuesperunit INTEGER NOT NULL DEFAULT '1', |
5359 |
PRIMARY KEY (id) |
5360 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
5361 |
|); |
5362 |
|
5363 |
$dbh->do(qq| |
5364 |
DROP TABLE IF EXISTS subscription_numberpatterns |
5365 |
|); |
5366 |
$dbh->do(qq| |
5367 |
CREATE TABLE subscription_numberpatterns ( |
5368 |
id INTEGER NOT NULL AUTO_INCREMENT, |
5369 |
label VARCHAR(255) NOT NULL, |
5370 |
displayorder INTEGER DEFAULT NULL, |
5371 |
description TEXT NOT NULL, |
5372 |
numberingmethod VARCHAR(255) NOT NULL, |
5373 |
label1 VARCHAR(255) DEFAULT NULL, |
5374 |
add1 INTEGER DEFAULT NULL, |
5375 |
every1 INTEGER DEFAULT NULL, |
5376 |
whenmorethan1 INTEGER DEFAULT NULL, |
5377 |
setto1 INTEGER DEFAULT NULL, |
5378 |
numbering1 VARCHAR(255) DEFAULT NULL, |
5379 |
label2 VARCHAR(255) DEFAULT NULL, |
5380 |
add2 INTEGER DEFAULT NULL, |
5381 |
every2 INTEGER DEFAULT NULL, |
5382 |
whenmorethan2 INTEGER DEFAULT NULL, |
5383 |
setto2 INTEGER DEFAULT NULL, |
5384 |
numbering2 VARCHAR(255) DEFAULT NULL, |
5385 |
label3 VARCHAR(255) DEFAULT NULL, |
5386 |
add3 INTEGER DEFAULT NULL, |
5387 |
every3 INTEGER DEFAULT NULL, |
5388 |
whenmorethan3 INTEGER DEFAULT NULL, |
5389 |
setto3 INTEGER DEFAULT NULL, |
5390 |
numbering3 VARCHAR(255) DEFAULT NULL, |
5391 |
PRIMARY KEY (id) |
5392 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
5393 |
|); |
5394 |
|
5395 |
$dbh->do(qq| |
5396 |
INSERT INTO subscription_frequencies (description, unit, unitsperissue, issuesperunit, displayorder) |
5397 |
VALUES |
5398 |
('2/day', 'day', 1, 2, 1), |
5399 |
('1/day', 'day', 1, 1, 2), |
5400 |
('3/week', 'week', 1, 3, 3), |
5401 |
('1/week', 'week', 1, 1, 4), |
5402 |
('1/2 weeks', 'week', 2, 1, 5), |
5403 |
('1/3 weeks', 'week', 3, 1, 6), |
5404 |
('1/month', 'month', 1, 1, 7), |
5405 |
('1/2 months', 'month', 2, 1, 8), |
5406 |
('1/3 months', 'month', 3, 1, 9), |
5407 |
('2/year', 'month', 6, 1, 10), |
5408 |
('1/year', 'year', 1, 1, 11), |
5409 |
('1/2 year', 'year', 2, 1, 12), |
5410 |
('Irregular', NULL, 1, 1, 13) |
5411 |
|); |
5412 |
|
5413 |
# Used to link existing subscription to newly created frequencies |
5414 |
my $frequencies_mapping = { # keys are old frequency numbers, values are the new ones |
5415 |
1 => 2, # daily (n/week) |
5416 |
2 => 4, # 1/week |
5417 |
3 => 5, # 1/2 weeks |
5418 |
4 => 6, # 1/3 weeks |
5419 |
5 => 7, # 1/month |
5420 |
6 => 8, # 1/2 months (6/year) |
5421 |
7 => 9, # 1/3 months (1/quarter) |
5422 |
8 => 9, # 1/quarter (seasonal) |
5423 |
9 => 10, # 2/year |
5424 |
10 => 11, # 1/year |
5425 |
11 => 12, # 1/2 years |
5426 |
12 => 1, # 2/day |
5427 |
16 => 13, # Without periodicity |
5428 |
32 => 13, # Irregular |
5429 |
48 => 13 # Unknown |
5430 |
}; |
5431 |
|
5432 |
$dbh->do(qq| |
5433 |
INSERT INTO subscription_numberpatterns |
5434 |
(label, displayorder, description, numberingmethod, |
5435 |
label1, add1, every1, whenmorethan1, setto1, numbering1, |
5436 |
label2, add2, every2, whenmorethan2, setto2, numbering2, |
5437 |
label3, add3, every3, whenmorethan3, setto3, numbering3) |
5438 |
VALUES |
5439 |
('Number', 1, 'Simple Numbering method', 'No.{X}', |
5440 |
'Number', 1, 1, 99999, 1, NULL, |
5441 |
NULL, NULL, NULL, NULL, NULL, NULL, |
5442 |
NULL, NULL, NULL, NULL, NULL, NULL), |
5443 |
|
5444 |
('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}', |
5445 |
'Volume', 1, 48, 99999, 1, NULL, |
5446 |
'Number', 1, 4, 12, 1, NULL, |
5447 |
'Issue', 1, 1, 4, 1, NULL), |
5448 |
|
5449 |
('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}', |
5450 |
'Volume', 1, 12, 99999, 1, NULL, |
5451 |
'Number', 1, 1, 12, 1, NULL, |
5452 |
NULL, NULL, NULL, NULL, NULL, NULL), |
5453 |
|
5454 |
('Seasonal', 4, 'Season Year', '{X} {Y}', |
5455 |
'Season', 1, 1, 3, 0, 'season', |
5456 |
'Year', 1, 4, 99999, 1, NULL, |
5457 |
NULL, NULL, NULL, NULL, NULL, NULL) |
5458 |
|); |
5459 |
|
5460 |
$dbh->do(qq| |
5461 |
ALTER TABLE subscription |
5462 |
MODIFY COLUMN numberpattern INTEGER DEFAULT NULL, |
5463 |
MODIFY COLUMN periodicity INTEGER DEFAULT NULL |
5464 |
|); |
5465 |
|
5466 |
# Update existing subscriptions |
5467 |
|
5468 |
my $query = qq| |
5469 |
SELECT subscriptionid, periodicity, numberingmethod, |
5470 |
add1, every1, whenmorethan1, setto1, |
5471 |
add2, every2, whenmorethan2, setto2, |
5472 |
add3, every3, whenmorethan3, setto3 |
5473 |
FROM subscription |
5474 |
ORDER BY subscriptionid |
5475 |
|; |
5476 |
my $sth = $dbh->prepare($query); |
5477 |
$sth->execute; |
5478 |
my $insert_numberpatterns_sth = $dbh->prepare(qq| |
5479 |
INSERT INTO subscription_numberpatterns |
5480 |
(label, displayorder, description, numberingmethod, |
5481 |
label1, add1, every1, whenmorethan1, setto1, numbering1, |
5482 |
label2, add2, every2, whenmorethan2, setto2, numbering2, |
5483 |
label3, add3, every3, whenmorethan3, setto3, numbering3) |
5484 |
VALUES |
5485 |
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) |
5486 |
|); |
5487 |
my $update_subscription_sth = $dbh->prepare(qq| |
5488 |
UPDATE subscription |
5489 |
SET numberpattern = ?, |
5490 |
periodicity = ? |
5491 |
WHERE subscriptionid = ? |
5492 |
|); |
5493 |
|
5494 |
my $i = 1; |
5495 |
while(my $sub = $sth->fetchrow_hashref) { |
5496 |
# Create a new numbering pattern for each subscription |
5497 |
my $ok = $insert_numberpatterns_sth->execute( |
5498 |
"Backup pattern $i", 4+$i, "Automatically created pattern by updatedatabase", $sub->{numberingmethod}, |
5499 |
"X", $sub->{add1}, $sub->{every1}, $sub->{whenmorethan1}, $sub->{setto1}, undef, |
5500 |
"Y", $sub->{add2}, $sub->{every2}, $sub->{whenmorethan2}, $sub->{setto2}, undef, |
5501 |
"Z", $sub->{add3}, $sub->{every3}, $sub->{whenmorethan3}, $sub->{setto3}, undef |
5502 |
); |
5503 |
if($ok) { |
5504 |
my $id = $dbh->last_insert_id(undef, undef, 'subscription_numberpatterns', undef); |
5505 |
# Link to subscription_numberpatterns and subscription_frequencies |
5506 |
$update_subscription_sth->execute($id, |
5507 |
$frequencies_mapping->{$sub->{periodicity}}, $sub->{subscriptionid}); |
5508 |
} |
5509 |
$i++; |
5510 |
} |
5511 |
|
5512 |
# Remove now useless columns |
5513 |
$dbh->do(qq| |
5514 |
ALTER TABLE subscription |
5515 |
DROP COLUMN numberingmethod, |
5516 |
DROP COLUMN add1, |
5517 |
DROP COLUMN every1, |
5518 |
DROP COLUMN whenmorethan1, |
5519 |
DROP COLUMN setto1, |
5520 |
DROP COLUMN add2, |
5521 |
DROP COLUMN every2, |
5522 |
DROP COLUMN whenmorethan2, |
5523 |
DROP COLUMN setto2, |
5524 |
DROP COLUMN add3, |
5525 |
DROP COLUMN every3, |
5526 |
DROP COLUMN whenmorethan3, |
5527 |
DROP COLUMN setto3, |
5528 |
DROP COLUMN dow, |
5529 |
DROP COLUMN issuesatonce, |
5530 |
DROP COLUMN hemisphere, |
5531 |
ADD COLUMN countissuesperunit INTEGER NOT NULL DEFAULT 0 AFTER periodicity, |
5532 |
ADD COLUMN skip_serialseq BOOLEAN NOT NULL DEFAULT 0 AFTER irregularity, |
5533 |
ADD COLUMN locale VARCHAR(80) DEFAULT NULL AFTER numberpattern, |
5534 |
ADD CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id), |
5535 |
ADD CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) |
5536 |
|); |
5537 |
|
5538 |
print "Upgrade to $DBversion done (Add subscription_frequencies and subscription_numberpatterns tables)\n"; |
5539 |
SetVersion($DBversion); |
5540 |
} |
5541 |
|
5346 |
=head1 FUNCTIONS |
5542 |
=head1 FUNCTIONS |
5347 |
|
5543 |
|
5348 |
=head2 TableExists($table) |
5544 |
=head2 TableExists($table) |
5349 |
- |
|
|