Lines 8845-8850
if ( CheckVersion($DBversion) ) {
Link Here
|
8845 |
SetVersion ($DBversion); |
8845 |
SetVersion ($DBversion); |
8846 |
} |
8846 |
} |
8847 |
|
8847 |
|
|
|
8848 |
|
8849 |
$DBversion = "3.17.00.XXX"; |
8850 |
if ( CheckVersion($DBversion) ) { |
8851 |
my $number_of_orders_not_linked = $dbh->selectcol_arrayref(q| |
8852 |
SELECT COUNT(*) |
8853 |
FROM aqorders o |
8854 |
WHERE NOT EXISTS ( |
8855 |
SELECT NULL |
8856 |
FROM aqbudgets b |
8857 |
WHERE b.budget_id = o.budget_id |
8858 |
); |
8859 |
|); |
8860 |
|
8861 |
if ( $number_of_orders_not_linked->[0] > 0 ) { |
8862 |
$dbh->do(q| |
8863 |
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) |
8864 |
|); |
8865 |
my $budget_period_id = $dbh->last_insert_id( undef, undef, 'aqbudgetperiods', undef ); |
8866 |
$dbh->do(qq| |
8867 |
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 ); |
8868 |
|); |
8869 |
my $budget_id = $dbh->last_insert_id( undef, undef, 'aqbudgets', undef ); |
8870 |
$dbh->do(qq| |
8871 |
UPDATE aqorders o |
8872 |
SET budget_id = $budget_id |
8873 |
WHERE NOT EXISTS ( |
8874 |
SELECT NULL |
8875 |
FROM aqbudgets b |
8876 |
WHERE b.budget_id = o.budget_id |
8877 |
) |
8878 |
|); |
8879 |
} |
8880 |
|
8881 |
$dbh->do(q| |
8882 |
ALTER TABLE aqorders |
8883 |
ADD CONSTRAINT aqorders_budget_id_fk FOREIGN KEY (budget_id) REFERENCES aqbudgets(budget_id) ON DELETE CASCADE ON UPDATE CASCADE |
8884 |
|); |
8885 |
|
8886 |
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"; |
8887 |
SetVersion($DBversion); |
8888 |
} |
8889 |
|
8848 |
=head1 FUNCTIONS |
8890 |
=head1 FUNCTIONS |
8849 |
|
8891 |
|
8850 |
=head2 TableExists($table) |
8892 |
=head2 TableExists($table) |