Lines 8949-8954
if ( CheckVersion($DBversion) ) {
Link Here
|
8949 |
ADD COLUMN cancellationreason TEXT DEFAULT NULL AFTER datecancellationprinted |
8949 |
ADD COLUMN cancellationreason TEXT DEFAULT NULL AFTER datecancellationprinted |
8950 |
"); |
8950 |
"); |
8951 |
print "Upgrade to $DBversion done (Bug 7162: Add aqorders.cancellationreason)\n"; |
8951 |
print "Upgrade to $DBversion done (Bug 7162: Add aqorders.cancellationreason)\n"; |
|
|
8952 |
SetVersion ($DBversion); |
8953 |
} |
8954 |
|
8955 |
$DBversion = "3.17.00.XXX"; |
8956 |
if ( CheckVersion($DBversion) ) { |
8957 |
my $number_of_orders_not_linked = $dbh->selectcol_arrayref(q| |
8958 |
SELECT COUNT(*) |
8959 |
FROM aqorders o |
8960 |
WHERE NOT EXISTS ( |
8961 |
SELECT NULL |
8962 |
FROM aqbudgets b |
8963 |
WHERE b.budget_id = o.budget_id |
8964 |
); |
8965 |
|); |
8966 |
|
8967 |
if ( $number_of_orders_not_linked->[0] > 0 ) { |
8968 |
$dbh->do(q| |
8969 |
INSERT INTO aqbudgetperiods(budget_period_startdate, budget_period_enddate, budget_period_active, budget_period_description, budget_period_total) VALUES ( CAST(NOW() AS date), CAST(NOW() AS date), 0, "WARNING: This budget has been automatically created by the updatedatabase script, please see bug 12601 for more information", 0) |
8970 |
|); |
8971 |
my $budget_period_id = $dbh->last_insert_id( undef, undef, 'aqbudgetperiods', undef ); |
8972 |
$dbh->do(qq| |
8973 |
INSERT INTO aqbudgets(budget_code, budget_name, budget_amount, budget_period_id) VALUES ( "BACKUP_TMP", "WARNING: fund created by the updatedatabase script, please see bug 12601", 0, $budget_period_id ); |
8974 |
|); |
8975 |
my $budget_id = $dbh->last_insert_id( undef, undef, 'aqbudgets', undef ); |
8976 |
$dbh->do(qq| |
8977 |
UPDATE aqorders o |
8978 |
SET budget_id = $budget_id |
8979 |
WHERE NOT EXISTS ( |
8980 |
SELECT NULL |
8981 |
FROM aqbudgets b |
8982 |
WHERE b.budget_id = o.budget_id |
8983 |
) |
8984 |
|); |
8985 |
} |
8986 |
|
8987 |
$dbh->do(q| |
8988 |
ALTER TABLE aqorders |
8989 |
ADD CONSTRAINT aqorders_budget_id_fk FOREIGN KEY (budget_id) REFERENCES aqbudgets(budget_id) ON DELETE CASCADE ON UPDATE CASCADE |
8990 |
|); |
8991 |
|
8992 |
print "Upgrade to $DBversion done (Bug 12601 - Add new foreign key aqorders.budget_id" . ( ( $number_of_orders_not_linked->[0] > 0 ) ? ' WARNING: temporary budget and fund have been created (search for "BACKUP_TMP"). At least one of your order was not linked to a budget' : '' ) . ")\n"; |
8952 |
SetVersion($DBversion); |
8993 |
SetVersion($DBversion); |
8953 |
} |
8994 |
} |
8954 |
|
8995 |
|