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

(-)a/Koha/Exporter/Record.pm (+54 lines)
Lines 11-16 use Koha::CsvProfiles; Link Here
11
use Koha::Logger;
11
use Koha::Logger;
12
use List::Util qw(all any);
12
use List::Util qw(all any);
13
13
14
sub new {
15
    my ($class, $args) = @_;
16
    my $self = {};
17
    $self->{record_ids} = delete $args->{record_ids};
18
    $self->{params} = $args // {};
19
    return bless ($self, $class);
20
}
21
22
sub has_next {
23
    my ($self) = @_;
24
    my $has_next;
25
    if ( $self->{record_ids} && scalar @{ $self->{record_ids} } > 0 ){
26
        $has_next = 1;
27
    }
28
    return $has_next;
29
}
30
31
sub next {
32
    my ($self) = @_;
33
    my $output;
34
    my $record_ids = $self->{record_ids};
35
    my $record_id = pop @$record_ids;
36
    if ($record_id){
37
        my $record = _get_record_for_export({
38
                %{ $self->{params} },
39
                record_id => $record_id,
40
        });
41
        if ($record){
42
            my $format =$self->{params}->{format};
43
            if ($format){
44
               if ($format eq 'iso2709'){
45
                    my $errorcount_on_decode = eval { scalar( MARC::File::USMARC->decode( $record->as_usmarc )->warnings() ) };
46
                    if ( $errorcount_on_decode or $@ ) {
47
                        my $msg = "Record $record_id could not be exported. " .
48
                            ( $@ // '' );
49
                        chomp $msg;
50
                        Koha::Logger->get->info( $msg );
51
                        return;
52
                    }
53
                    $output = $record->as_usmarc();
54
55
                }
56
                elsif ($format eq 'xml'){
57
                    $output = MARC::File::XML::record($record) . "\n";
58
                }
59
                elsif ($format eq 'csv'){
60
                    #FIXME
61
                }
62
            }
63
        }
64
    }
65
    return $output;
66
}
67
14
sub _get_record_for_export {
68
sub _get_record_for_export {
15
    my ($params)           = @_;
69
    my ($params)           = @_;
16
    my $record_type        = $params->{record_type};
70
    my $record_type        = $params->{record_type};
(-)a/Koha/Staff/Controller/Tools/Export.pm (-5 / +55 lines)
Lines 6-11 use Koha::Exporter::Record; Link Here
6
use C4::Biblio qw//;
6
use C4::Biblio qw//;
7
use Encode;
7
use Encode;
8
use Carp;
8
use Carp;
9
use List::MoreUtils qw(uniq);
9
10
10
use Koha::ItemTypes;
11
use Koha::ItemTypes;
11
use Koha::Authority::Types;
12
use Koha::Authority::Types;
Lines 77-84 sub _getbackupfilelist { Link Here
77
        }
78
        }
78
        closedir($dir);
79
        closedir($dir);
79
    }
80
    }
80
    use Data::Dumper;
81
    warn Dumper(\@files);
82
    return \@files;
81
    return \@files;
83
}
82
}
84
83
Lines 88-101 sub download { Link Here
88
    my ($flags,$loggedinuser) = $c->staff_authorize({ flagsrequired => { 'tools' => 'export_catalog' } });
87
    my ($flags,$loggedinuser) = $c->staff_authorize({ flagsrequired => { 'tools' => 'export_catalog' } });
89
88
90
	my $record_type = $c->param('record_type') || 'bibs'; #FIXME: Remove bibs?
89
	my $record_type = $c->param('record_type') || 'bibs'; #FIXME: Remove bibs?
91
	my $backupdir         = C4::Context->config('backupdir');
92
93
    if ( $record_type eq 'bibs' or $record_type eq 'auths' ){
90
    if ( $record_type eq 'bibs' or $record_type eq 'auths' ){
91
        my $output_format = $c->param('output_format') || 'iso2709';
92
        my $filename = $c->param('filename') || ( $output_format eq 'csv' ? 'koha.csv' : 'koha.mrc' );
93
        my $csv_profile_id = $c->param('csv_profile_id');
94
        my $export_remove_fields = $c->param('export_remove_fields') || q();
95
        my $dont_export_items = $c->param('dont_export_item') || 0; #FIXME: Shouldn't this be bibs specific?
96
        my $itemnumbers = $c->every_param('itemnumbers'); #FIXME: Shouldn't this be bibs specific?
97
98
        my $branch = $c->every_param('branch');
99
        my $strip_items_not_from_libraries =  $c->param('strip_items_not_from_libraries');
100
        my $only_export_items_for_branches = $strip_items_not_from_libraries ? $branch : undef;
101
102
        my $record_ids = ();
103
        if ($record_type eq 'bibs'){
104
            my $biblionumbers = $c->every_param('biblionumbers');
105
106
            $record_ids = $biblionumbers;
107
        }
108
109
        #FIXME: Move this to module
110
        #NOTE: Ensure record IDs are unique
111
        #@record_ids = uniq @record_ids;
112
113
        #FIXME: Add "id_list_file" filter...
114
115
        my $content_type = 'application/octet-stream';
116
        $c->res->headers->content_type($content_type);
117
        $c->res->headers->content_disposition("attachment; filename=$filename;");
118
119
        my $exporter = Koha::Exporter::Record->new({
120
            record_type => $record_type,
121
            record_ids => $record_ids,
122
            format => $output_format,
123
            filename => $filename,
124
            itemnumbers => $itemnumbers,
125
            dont_export_fields => $export_remove_fields,
126
            csv_profile_id => $csv_profile_id,
127
            export_items => (not $dont_export_items),
128
            only_export_items_for_branches => $only_export_items_for_branches,
129
        });
130
        my $drain;
131
        $drain = sub {
132
            my $c = shift;
133
            if ( $exporter->has_next() ){
134
                my $record = $exporter->next;
135
                $c->write($record,$drain);
136
            }
137
            else {
138
                $c->write('');
139
            }
140
        };
141
        $c->$drain;
142
94
        #TODO: Refactor code from export.pl
143
        #TODO: Refactor code from export.pl
95
        $c->render( text => 'TODO: I need to rewrite the handler for this but it is coming.' );
144
        #$c->render( text => 'TODO: I need to rewrite the handler for this but it is coming.' );
96
    }
145
    }
97
    elsif ( $record_type eq 'db' or $record_type eq 'conf' ){
146
    elsif ( $record_type eq 'db' or $record_type eq 'conf' ){
98
        #TODO: Most of this code should go in a model module
147
        #TODO: Most of this code should go in a model module
148
	    my $backupdir         = C4::Context->config('backupdir');
99
		if ( $flags->{superlibrarian}
149
		if ( $flags->{superlibrarian}
100
		and (
150
		and (
101
                    $record_type eq 'db' and C4::Context->config('backup_db_via_tools')
151
                    $record_type eq 'db' and C4::Context->config('backup_db_via_tools')
(-)a/Koha/Template.pm (+1 lines)
Lines 14-19 sub prepare_template { Link Here
14
    my $template_filename = $args->{template_filename};
14
    my $template_filename = $args->{template_filename};
15
    my $interface = $args->{interface};
15
    my $interface = $args->{interface};
16
    if ($template_filename && $interface){
16
    if ($template_filename && $interface){
17
        #FIXME: See Bug 27293 about refactoring C4::Templates::gettemplate for providing the "language" param and "KohaOpacLanguage" cookie
17
        $template = C4::Templates::gettemplate($template_filename,$interface);
18
        $template = C4::Templates::gettemplate($template_filename,$interface);
18
        if ($template){
19
        if ($template){
19
            if ($session){
20
            if ($session){
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/checkouts-table.inc (-3 / +1 lines)
Lines 6-12 Link Here
6
                <a id="issues-table-load-now-button" href="#" class="btn btn-default"><i class="fa fa-book"></i> Show checkouts</a>
6
                <a id="issues-table-load-now-button" href="#" class="btn btn-default"><i class="fa fa-book"></i> Show checkouts</a>
7
            </p>
7
            </p>
8
        </div>
8
        </div>
9
        <form name="issues" action="/cgi-bin/koha/tools/export.pl" method="post">
9
        <form name="issues" action="/cgi-bin/koha/staff/tools/export/download" method="post">
10
            <table id="issues-table" style="width: 100% !Important;">
10
            <table id="issues-table" style="width: 100% !Important;">
11
                <thead>
11
                <thead>
12
                    <tr>
12
                    <tr>
Lines 77-83 Link Here
77
                            </select>
77
                            </select>
78
                        [% END %]
78
                        [% END %]
79
                       <label for="export_remove_fields">Don't export fields:</label> <input type="text" id="export_remove_fields" name="export_remove_fields" value="[% Koha.Preference('ExportRemoveFields') | html %]" title="Use for MARC exports" />
79
                       <label for="export_remove_fields">Don't export fields:</label> <input type="text" id="export_remove_fields" name="export_remove_fields" value="[% Koha.Preference('ExportRemoveFields') | html %]" title="Use for MARC exports" />
80
                        <input type="hidden" name="op" value="export" />
81
                        <input type="hidden" id="output_format" name="output_format" value="iso2709" />
80
                        <input type="hidden" id="output_format" name="output_format" value="iso2709" />
82
                        <input type="hidden" id="dont_export_item" name="dont_export_item" value="0" />
81
                        <input type="hidden" id="dont_export_item" name="dont_export_item" value="0" />
83
                        <input type="hidden" id="record_type" name="record_type" value="bibs" />
82
                        <input type="hidden" id="record_type" name="record_type" value="bibs" />
84
- 

Return to bug 26791