Bug 7688: Set firstacquidate in updatedatabase if it's not set

firstacquidate is now a mandatory field, so it must be set.
The updatedatabase process set firstacquidate value to one of:
- the planned date of the first serial for this subscription, or if not
  found,
- the subscription start date.

+ auto-select the numbering pattern when modifying a subscription.

Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
This commit is contained in:
Julian Maurice 2013-03-22 09:53:51 +00:00 committed by Jared Camins-Esakov
parent a4d25333b4
commit 21fbc0b878
2 changed files with 33 additions and 1 deletions

View file

@ -6940,6 +6940,38 @@ if ( CheckVersion($DBversion) ) {
ADD CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE
|);
# Set firstacquidate if not already set (firstacquidate is now mandatory)
my $get_first_planneddate_sth = $dbh->prepare(qq|
SELECT planneddate
FROM serial
WHERE subscriptionid = ?
ORDER BY serialid
LIMIT 1
|);
my $update_firstacquidate_sth = $dbh->prepare(qq|
UPDATE subscription
SET firstacquidate = ?
WHERE subscriptionid = ?
|);
my $get_subscriptions_sth = $dbh->prepare(qq|
SELECT subscriptionid, startdate
FROM subscription
WHERE firstacquidate IS NULL
OR firstacquidate = '0000-00-00'
|);
$get_subscriptions_sth->execute;
while ( my ($subscriptionid, $startdate) = $get_subscriptions_sth->fetchrow ) {
# Try to get the planned date of the first serial
$get_first_planneddate_sth->execute($subscriptionid);
my ($first_planneddate) = $get_first_planneddate_sth->fetchrow;
if ($first_planneddate and $first_planneddate =~ /^\d{4}-\d{2}-\d{2}$/) {
$update_firstacquidate_sth->execute($first_planneddate, $subscriptionid);
} else {
# Defaults to subscription start date
$update_firstacquidate_sth->execute($startdate, $subscriptionid);
}
}
print "Upgrade to $DBversion done (Bug 7688: Add subscription_frequencies and subscription_numberpatterns tables)\n";
SetVersion($DBversion);
}

View file

@ -693,7 +693,7 @@ $(document).ready(function() {
<option value="">-- please choose --</option>
[% FOREACH numberpattern IN numberpatterns %]
[% IF (numberpattern.selected) %]
<option value="[% numberpattern.id %]">
<option value="[% numberpattern.id %]" selected="selected">
[% ELSE %]
<option value="[% numberpattern.id %]">
[% END %]