View | Details | Raw Unified | Return to bug 13380
Collapse All | Expand All

(-)a/installer/data/mysql/updatedatabase.pl (-27 / +33 lines)
Lines 9834-9869 if ( CheckVersion($DBversion) ) { Link Here
9834
9834
9835
$DBversion = "3.19.00.016";
9835
$DBversion = "3.19.00.016";
9836
if(CheckVersion($DBversion)) {
9836
if(CheckVersion($DBversion)) {
9837
    $dbh->do(q{
9837
    my @order_cancellation_reason = $dbh->selectrow_array("SELECT count(*) FROM authorised_values WHERE category='ORDER_CANCELLATION_REASON'");
9838
        INSERT INTO authorised_values (category, authorised_value, lib) VALUES
9838
    if ($order_cancellation_reason[0] == 0) {
9839
         ('ORDER_CANCELLATION_REASON', 0, 'No reason provided'),
9839
        $dbh->do(q{
9840
         ('ORDER_CANCELLATION_REASON', 1, 'Out of stock'),
9840
            INSERT INTO authorised_values (category, authorised_value, lib) VALUES
9841
         ('ORDER_CANCELLATION_REASON', 2, 'Restocking')
9841
             ('ORDER_CANCELLATION_REASON', 0, 'No reason provided'),
9842
    });
9842
             ('ORDER_CANCELLATION_REASON', 1, 'Out of stock'),
9843
             ('ORDER_CANCELLATION_REASON', 2, 'Restocking')
9844
        });
9843
9845
9844
    my $already_existing_reasons = $dbh->selectcol_arrayref(q{
9846
        my $already_existing_reasons = $dbh->selectcol_arrayref(q{
9845
        SELECT DISTINCT( cancellationreason )
9847
            SELECT DISTINCT( cancellationreason )
9846
        FROM aqorders;
9848
            FROM aqorders;
9847
    }, { Slice => {} });
9849
        }, { Slice => {} });
9848
9850
9849
    my $update_orders_sth = $dbh->prepare(q{
9851
        my $update_orders_sth = $dbh->prepare(q{
9850
        UPDATE aqorders
9852
            UPDATE aqorders
9851
        SET cancellationreason = ?
9853
            SET cancellationreason = ?
9852
        WHERE cancellationreason = ?
9854
            WHERE cancellationreason = ?
9853
    });
9855
        });
9854
9856
9855
    my $insert_av_sth = $dbh->prepare(q{
9857
        my $insert_av_sth = $dbh->prepare(q{
9856
        INSERT INTO authorised_values (category, authorised_value, lib) VALUES
9858
            INSERT INTO authorised_values (category, authorised_value, lib) VALUES
9857
         ('ORDER_CANCELLATION_REASON', ?, ?)
9859
             ('ORDER_CANCELLATION_REASON', ?, ?)
9858
    });
9860
        });
9859
    my $i = 3;
9861
        my $i = 3;
9860
    for my $reason ( @$already_existing_reasons ) {
9862
        for my $reason ( @$already_existing_reasons ) {
9861
        next unless $reason;
9863
            next unless $reason;
9862
        $insert_av_sth->execute( $i, $reason );
9864
            $insert_av_sth->execute( $i, $reason );
9863
        $update_orders_sth->execute( $i, $reason );
9865
            $update_orders_sth->execute( $i, $reason );
9864
        $i++;
9866
            $i++;
9867
        }
9868
        print "Upgrade to $DBversion done (Bug 13380: Add the ORDER_CANCELLATION_REASON authorised value)\n";
9869
    }
9870
    else {
9871
        print "Upgrade to $DBversion done (Bug 13380: ORDER_CANCELLATION_REASON authorised value already existed from earlier update!)\n";
9865
    }
9872
    }
9866
    print "Upgrade to $DBversion done (Bug 13380: Add the ORDER_CANCELLATION_REASON authorised value)\n";
9873
9867
    SetVersion($DBversion);
9874
    SetVersion($DBversion);
9868
}
9875
}
9869
9876
9870
- 

Return to bug 13380