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

(-)a/ill/ill-requests.pl (-1 / +1 lines)
Lines 174-180 if ( $backends_available ) { Link Here
174
            $request->price_paid($params->{price_paid});
174
            $request->price_paid($params->{price_paid});
175
            $request->notesopac($params->{notesopac});
175
            $request->notesopac($params->{notesopac});
176
            $request->notesstaff($params->{notesstaff});
176
            $request->notesstaff($params->{notesstaff});
177
            my $alias = ($params->{status_alias} =~ /\d/) ?
177
            my $alias = ($params->{status_alias}) ?
178
                $params->{status_alias} :
178
                $params->{status_alias} :
179
                undef;
179
                undef;
180
            $request->status_alias($alias);
180
            $request->status_alias($alias);
(-)a/installer/data/mysql/atomicupdate/bug_20581-add_new_illrequests_status_alias_column.perl (-2 / +29 lines)
Lines 2-11 $DBversion = 'XXX'; # will be replaced by the RM Link Here
2
if( CheckVersion( $DBversion ) ) {
2
if( CheckVersion( $DBversion ) ) {
3
3
4
    if ( !column_exists( 'illrequests', 'status_alias' ) ) {
4
    if ( !column_exists( 'illrequests', 'status_alias' ) ) {
5
        $dbh->do( "ALTER TABLE illrequests ADD COLUMN status_alias integer DEFAULT NULL AFTER status" );
5
        # Fresh upgrade, just add the column and constraint
6
        $dbh->do( "ALTER TABLE illrequests ADD COLUMN status_alias varchar(80) DEFAULT NULL AFTER status" );
7
    } else {
8
        # Migrate all existing foreign keys from referencing authorised_values.id
9
        # to referencing authorised_values.authorised_value
10
        # First remove the foreign key constraint and index
11
        if ( foreign_key_exists( 'illrequests', 'illrequests_safk' ) ) {
12
            $dbh->do( "ALTER TABLE illrequests DROP FOREIGN KEY illrequests_safk");
13
        }
14
        if ( index_exists( 'illrequests', 'illrequests_safk' ) ) {
15
            $dbh->do( "DROP INDEX illrequests_safk IN illrequests" );
16
        }
17
        # Now change the illrequests.status_alias column definition from int to varchar
18
        $dbh->do( "ALTER TABLE illrequests MODIFY COLUMN status_alias varchar(80)" );
19
        # Now replace all references to authorised_values.id with their
20
        # corresponding authorised_values.authorised_value
21
        my $sth = $dbh->prepare( "SELECT illrequest_id, status_alias FROM illrequests WHERE status_alias IS NOT NULL" );
22
        $sth->execute();
23
        while (my @row = $sth->fetchrow_array()) {
24
            my $r_id = $row[0];
25
            my $av_id = $row[1];
26
            # Get the authorised value's authorised_value value
27
            my ($av_val) = $dbh->selectrow_array( "SELECT authorised_value FROM authorised_values WHERE id = ?", {}, $av_id );
28
            # Now update illrequests.status_alias
29
            if ($av_val) {
30
                $dbh->do( "UPDATE illrequests SET status_alias = ? WHERE illrequest_id = ?", {}, ($av_val, $r_id) );
31
            }
32
        }
6
    }
33
    }
7
    if ( !foreign_key_exists( 'illrequests', 'illrequests_safk' ) ) {
34
    if ( !foreign_key_exists( 'illrequests', 'illrequests_safk' ) ) {
8
        $dbh->do( "ALTER TABLE illrequests ADD CONSTRAINT illrequests_safk FOREIGN KEY (status_alias) REFERENCES authorised_values(id) ON UPDATE CASCADE ON DELETE SET NULL" );
35
        $dbh->do( "ALTER TABLE illrequests ADD CONSTRAINT illrequests_safk FOREIGN KEY (status_alias) REFERENCES authorised_values(authorised_value) ON UPDATE CASCADE ON DELETE SET NULL" );
9
    }
36
    }
10
    $dbh->do( "INSERT IGNORE INTO authorised_value_categories SET category_name = 'ILLSTATUS'");
37
    $dbh->do( "INSERT IGNORE INTO authorised_value_categories SET category_name = 'ILLSTATUS'");
11
38
(-)a/installer/data/mysql/kohastructure.sql (-2 / +2 lines)
Lines 4171-4177 CREATE TABLE illrequests ( Link Here
4171
    biblio_id integer DEFAULT NULL,             -- Potential bib linked to request
4171
    biblio_id integer DEFAULT NULL,             -- Potential bib linked to request
4172
    branchcode varchar(50) NOT NULL,            -- The branch associated with the request
4172
    branchcode varchar(50) NOT NULL,            -- The branch associated with the request
4173
    status varchar(50) DEFAULT NULL,            -- Current Koha status of request
4173
    status varchar(50) DEFAULT NULL,            -- Current Koha status of request
4174
    status_alias integer DEFAULT NULL,          -- Foreign key to relevant authorised_values.id
4174
    status_alias varchar(80) DEFAULT NULL,      -- Foreign key to relevant authorised_values.authorised_value
4175
    placed date DEFAULT NULL,                   -- Date the request was placed
4175
    placed date DEFAULT NULL,                   -- Date the request was placed
4176
    replied date DEFAULT NULL,                  -- Last API response
4176
    replied date DEFAULT NULL,                  -- Last API response
4177
    updated timestamp DEFAULT CURRENT_TIMESTAMP -- Last modification to request
4177
    updated timestamp DEFAULT CURRENT_TIMESTAMP -- Last modification to request
Lines 4195-4201 CREATE TABLE illrequests ( Link Here
4195
      ON UPDATE CASCADE ON DELETE CASCADE,
4195
      ON UPDATE CASCADE ON DELETE CASCADE,
4196
    CONSTRAINT `illrequests_safk`
4196
    CONSTRAINT `illrequests_safk`
4197
      FOREIGN KEY (`status_alias`)
4197
      FOREIGN KEY (`status_alias`)
4198
      REFERENCES `authorised_values` (`id`)
4198
      REFERENCES `authorised_values` (`authorised_value`)
4199
      ON UPDATE CASCADE ON DELETE SET NULL
4199
      ON UPDATE CASCADE ON DELETE SET NULL
4200
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4200
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4201
4201
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt (-5 / +4 lines)
Lines 204-213 Link Here
204
                                            [% request.capabilities.$stat.name | html %]
204
                                            [% request.capabilities.$stat.name | html %]
205
                                        </option>
205
                                        </option>
206
                                        [% FOREACH alias IN AuthorisedValues.Get('ILLSTATUS') %]
206
                                        [% FOREACH alias IN AuthorisedValues.Get('ILLSTATUS') %]
207
                                            [% IF alias.id == current_alias %]
207
                                            [% IF alias.authorised_value == current_alias %]
208
                                            <option value="[% alias.id | html %]" selected>
208
                                            <option value="[% alias.authorised_value | html %]" selected>
209
                                            [% ELSE %]
209
                                            [% ELSE %]
210
                                            <option value="[% alias.id | html %]">
210
                                            <option value="[% alias.authorised_value | html %]">
211
                                            [% END %]
211
                                            [% END %]
212
                                                [% alias.lib | html %]
212
                                                [% alias.lib | html %]
213
                                            </option>
213
                                            </option>
Lines 874-880 Link Here
874
            // Get our data from the API and process it prior to passing
874
            // Get our data from the API and process it prior to passing
875
            // it to datatables
875
            // it to datatables
876
            var ajax = $.ajax(
876
            var ajax = $.ajax(
877
                '/api/v1/illrequests?embed=metadata,patron,capabilities,library'
877
                '/api/v1/illrequests?embed=metadata,patron,capabilities,library,status_alias'
878
                ).done(function() {
878
                ).done(function() {
879
                    var data = JSON.parse(ajax.responseText);
879
                    var data = JSON.parse(ajax.responseText);
880
                    // Make a copy, we'll be removing columns next and need
880
                    // Make a copy, we'll be removing columns next and need
881
- 

Return to bug 20581