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

(-)a/installer/data/mysql/atomicupdate/bug_16122_atomicupdate.pl (-13 / +17 lines)
Lines 1-27 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
return {
2
return {
3
    bug_number => "16122",
3
    bug_number  => "16122",
4
    description => "Add localuser column to items table",
4
    description => "Add local use column to items table",
5
    up => sub {
5
    up          => sub {
6
        my ($args) = @_;
6
        my ($args) = @_;
7
        my ($dbh, $out) = @$args{qw(dbh out)};
7
        my ( $dbh, $out ) = @$args{qw(dbh out)};
8
        if( !column_exists( 'items', 'localuse' ) ) {
8
        if ( !column_exists( 'items', 'localuse' ) ) {
9
            $dbh->do(q{
9
            $dbh->do(
10
                q{
10
                ALTER TABLE items
11
                ALTER TABLE items
11
                ADD COLUMN localuse smallint(6) NULL DEFAULT NULL
12
                ADD COLUMN localuse smallint(6) NULL DEFAULT NULL
12
                COMMENT "item's local use count"
13
                COMMENT "number of times this item has been recorded as local use"
13
                AFTER renewals
14
                AFTER renewals
14
            });
15
            }
16
            );
15
            say $out "Added column 'items.localuse'";
17
            say $out "Added column 'items.localuse'";
16
        }
18
        }
17
        if( !column_exists( 'deleteditems', 'localuse' ) ) {
19
        if ( !column_exists( 'deleteditems', 'localuse' ) ) {
18
            $dbh->do(q{
20
            $dbh->do(
21
                q{
19
                ALTER TABLE deleteditems
22
                ALTER TABLE deleteditems
20
                ADD COLUMN localuse smallint(6) NULL DEFAULT NULL
23
                ADD COLUMN localuse smallint(6) NULL DEFAULT NULL
21
                COMMENT "deleteditems local use count"
24
                COMMENT "number of times this item has been recorded as local use"
22
                AFTER renewals
25
                AFTER renewals
23
            });
26
            }
27
            );
24
            say $out "Added column 'deleteditems.localuse'";
28
            say $out "Added column 'deleteditems.localuse'";
25
        }
29
        }
26
    },
30
    },
27
}
31
    }
(-)a/misc/maintenance/update_localuse_from_statistics.pl (-10 / +8 lines)
Lines 27-33 use Koha::Statistics; Link Here
27
use Getopt::Long qw( GetOptions );
27
use Getopt::Long qw( GetOptions );
28
use Pod::Usage qw( pod2usage );
28
use Pod::Usage qw( pod2usage );
29
29
30
31
sub usage {
30
sub usage {
32
    pod2usage( -verbose => 2 );
31
    pod2usage( -verbose => 2 );
33
    exit;
32
    exit;
Lines 40-59 sub update_localuse { Link Here
40
    my $items = Koha::Items->search();
39
    my $items = Koha::Items->search();
41
40
42
    # Loop through each item and update it with statistics info
41
    # Loop through each item and update it with statistics info
43
    while( my $item = $items->next ){
42
    while ( my $item = $items->next ) {
44
      my $itemnumber = $item->itemnumber;
43
        my $itemnumber = $item->itemnumber;
45
44
46
      my $localuse_count = Koha::Statistics->search( { itemnumber => $itemnumber, type => 'localuse' } )->count;
45
        my $localuse_count = Koha::Statistics->search( { itemnumber => $itemnumber, type => 'localuse' } )->count;
47
      $item->localuse( $localuse_count );
46
        $item->localuse($localuse_count);
48
      $item->store;
47
        $item->store;
49
48
50
      print "Updated item $itemnumber with localuse statistics info.\n";
49
        print "Updated item $itemnumber with localuse statistics info.\n";
51
    }
50
    }
52
}
51
}
53
52
54
my ( $help );
53
my ($help);
55
my $result = GetOptions(
54
my $result = GetOptions(
56
    'help|h'      => \$help,
55
    'help|h' => \$help,
57
);
56
);
58
57
59
usage() if $help;
58
usage() if $help;
60
- 

Return to bug 16122