2 use strict; use warnings;
4 # --------------------------------------------------------------------
5 # Loads the offline script files for a given org, sorts and runs the
6 # scripts, and returns the exception list
7 # --------------------------------------------------------------------
11 require 'offline-lib.pl';
16 my $evt = $U->check_perms(&offline_requestor->id, &offline_org, 'OFFLINE_VIEW');
17 handle_event($evt) if $evt;
18 &report_json(&gather_workstations) if &offline_cgi->param('detail');
19 &report_sessions() if &offline_cgi->param('seslist');
25 my $sessions = &offline_org_sessions(&offline_org);
27 for my $s (@$sessions) {
30 my $meta = &_offline_file_to_perl("$file/meta", 'workstation');
31 my $done = ($file =~ m#/archive/#o) ? 1 : 0;
32 push( @$results, { session => $name, meta => $meta, complete => $done } );
34 &offline_handle_json($results);
38 # --------------------------------------------------------------------
39 # Collects a list of workstations that have pending files
40 # --------------------------------------------------------------------
41 sub gather_workstations {
42 my $dir = &offline_pending_dir;
43 $dir = &offline_archive_dir unless -e $dir;
44 return [] unless -e $dir;
45 my @files = <$dir/*.log>;
46 $_ =~ s/\.log//og for @files; # remove .log
47 $_ =~ s#/.*/(\w+)#$1#og for @files; # remove leading file path
52 # --------------------------------------------------------------------
53 # Just resturns whether or not the transaction is complete and how
54 # many items have been processed
55 # --------------------------------------------------------------------
56 sub report_json_summary {
61 if( -e &offline_pending_dir ) {
62 $results = &offline_read_results
64 } elsif( -e &offline_archive_dir ) {
65 $results = &offline_read_archive_results;
69 handle_event(OpenILS::Event->new('OFFLINE_SESSION_NOT_FOUND'));
73 {complete => $complete, num_complete => scalar(@$results)});
77 # --------------------------------------------------------------------
78 # Reports the workstations and their results as JSON
79 # --------------------------------------------------------------------
84 my $meta = &offline_read_meta;
85 my $results = &offline_read_results;
89 $logger->debug("offline: attempting to report on archived files for session ".&offline_seskey);
90 $meta = &offline_read_archive_meta;
91 $results = &offline_read_archive_results;
95 for my $ws (@$wslist) {
96 my ($m) = grep { $_ and $_->{'log'} and $_->{'log'} =~ m#/.*/$ws.log# } @$meta;
97 my @res = grep { $_->{command}->{_workstation} eq $ws } @$results;
99 push( @data, { meta => $m, workstation => $ws, results => \@res } );
102 &offline_handle_json({ complete => $complete, data => \@data});