| 1 | package oEdtk::EDMS; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Electronic Document Management (GED in French). | ||||||||||||||||||||||||||||
| 4 | # Merged at S54 from the fork's ECM-oriented rewrite (36 index columns, the | ||||||||||||||||||||||||||||
| 5 | # Alfresco header, _log / my_system) plus the mainline EDMS_package and the | ||||||||||||||||||||||||||||
| 6 | # edidx helpers (which the fork exported but never defined). | ||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 20 | ▶ | use Carp qw(carp croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 20 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 20 | our $VERSION = 2.1131; | |||||||||||||||||||||||||||
| 13 | 20 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 14 | 20 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 15 | EDMS_edidx_build | ||||||||||||||||||||||||||||
| 16 | EDMS_edidx_write | ||||||||||||||||||||||||||||
| 17 | EDMS_idldoc_seqpg | ||||||||||||||||||||||||||||
| 18 | EDMS_idx_create_csv | ||||||||||||||||||||||||||||
| 19 | EDMS_import | ||||||||||||||||||||||||||||
| 20 | EDMS_package | ||||||||||||||||||||||||||||
| 21 | EDMS_prepare | ||||||||||||||||||||||||||||
| 22 | EDMS_process | ||||||||||||||||||||||||||||
| 23 | EDMS_process_zip | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 20 | ▶ | use Archive::Zip qw(:ERROR_CODES); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 20 | ▶ | use Cwd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 20 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 20 | ▶ | use File::Copy; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 20 | ▶ | use IPC::Run3 qw(run3); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 20 | ▶ | use Net::FTP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 20 | ▶ | use oEdtk::Main; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 20 | ▶ | use oEdtk::Config qw(config_read); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 20 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 20 | ▶ | use Text::CSV; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 20 | ▶ | use Time::HiRes qw(gettimeofday); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 20 | ▶ | use XML::Writer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # use PDF; # add to the prerequisites | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # The per-page .idx1 read by EDMS_idx_process (and posted by | ||||||||||||||||||||||||||||
| 42 | # oEUser::DisseminationPlan) carries these 36 columns, in this exact order: the | ||||||||||||||||||||||||||||
| 43 | # ECM layout of the fork. oEUser::DisseminationPlan's INDEX_* constants pin the | ||||||||||||||||||||||||||||
| 44 | # same positions (ID_LOT=1, PAGE=2, DOC=3, NOM_PRENOM=7, DATE_EDITION=9, | ||||||||||||||||||||||||||||
| 45 | # CONTRAT_INDIV=13, TYPE_DOC=31). | ||||||||||||||||||||||||||||
| 46 | 20 | my @INDEX_ECM_COLS = ( | |||||||||||||||||||||||||||
| 47 | 'ED_REFIDDOC', # 1 id in the document repository | ||||||||||||||||||||||||||||
| 48 | 'ED_IDLDOC', # 2 unique document id within the page-layout batch | ||||||||||||||||||||||||||||
| 49 | 'ED_IDSEQPG', # 3 page sequence number within the page-layout batch | ||||||||||||||||||||||||||||
| 50 | 'ED_SEQDOC', # 4 document sequence number within the batch | ||||||||||||||||||||||||||||
| 51 | 'ED_CPDEST', # 5 recipient postal code | ||||||||||||||||||||||||||||
| 52 | 'ED_VILLDEST', # 6 recipient city | ||||||||||||||||||||||||||||
| 53 | 'ED_IDDEST', # 7 recipient id in the management system | ||||||||||||||||||||||||||||
| 54 | 'ED_NOMDEST', # 8 recipient name | ||||||||||||||||||||||||||||
| 55 | 'ED_IDEMET', # 9 sender id | ||||||||||||||||||||||||||||
| 56 | 'ED_DTEDTION', # 10 edition date printed on the document | ||||||||||||||||||||||||||||
| 57 | 'ED_TYPPROD', # 11 production type associated with the batch | ||||||||||||||||||||||||||||
| 58 | 'ED_PORTADR', # 12 flag: document carries an address | ||||||||||||||||||||||||||||
| 59 | 'ED_ADRLN1', # 13 address line 1 | ||||||||||||||||||||||||||||
| 60 | 'ED_CLEGED1', # 14 archiving system key | ||||||||||||||||||||||||||||
| 61 | 'ED_ADRLN2', # 15 address line 2 | ||||||||||||||||||||||||||||
| 62 | 'ED_CLEGED2', # 16 archiving system key | ||||||||||||||||||||||||||||
| 63 | 'ED_ADRLN3', # 17 address line 3 | ||||||||||||||||||||||||||||
| 64 | 'ED_CLEGED3', # 18 archiving system key | ||||||||||||||||||||||||||||
| 65 | 'ED_ADRLN4', # 19 address line 4 | ||||||||||||||||||||||||||||
| 66 | 'ED_CLEGED4', # 20 archiving system key | ||||||||||||||||||||||||||||
| 67 | 'ED_ADRLN5', # 21 address line 5 | ||||||||||||||||||||||||||||
| 68 | 'ED_CORP', # 22 issuing entity of the page | ||||||||||||||||||||||||||||
| 69 | 'ED_DOCLIB', # 23 merge library associated with the page | ||||||||||||||||||||||||||||
| 70 | 'ED_REFIMP', # 24 pre-printed, printed or insert reference | ||||||||||||||||||||||||||||
| 71 | 'ED_ADRLN6', # 25 address line 6 | ||||||||||||||||||||||||||||
| 72 | 'ED_SOURCE', # 26 index source or ed_corp entity | ||||||||||||||||||||||||||||
| 73 | 'ED_OWNER', # 27 document owner | ||||||||||||||||||||||||||||
| 74 | 'ED_HOST', # 28 hostname this entry came from | ||||||||||||||||||||||||||||
| 75 | 'ED_IDIDX', # 29 index id | ||||||||||||||||||||||||||||
| 76 | 'ED_CATDOC', # 30 document category | ||||||||||||||||||||||||||||
| 77 | 'ED_CODRUPT', # 31 burst forcing code | ||||||||||||||||||||||||||||
| 78 | 'ED_TYPDOC', # 32 document type (ECM) | ||||||||||||||||||||||||||||
| 79 | 'ED_IDCOLL', # 33 collection id (ECM) | ||||||||||||||||||||||||||||
| 80 | 'ED_IDMNT', # 34 archive id from the extension (ECM) | ||||||||||||||||||||||||||||
| 81 | 'ED_CLEGED5', # 35 extra archiving key (ECM) | ||||||||||||||||||||||||||||
| 82 | 'ED_IDPMSIR', # 36 legal-entity / SIRET id (ECM) | ||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # Timestamp of the previous _log call, so it can print the elapsed time. | ||||||||||||||||||||||||||||
| 86 | 20 | my $LOG_SEC0 = 0; | |||||||||||||||||||||||||||
| 87 | 20 | my $LOG_USEC0 = 0; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # Log one message on STDERR, with a timestamp, the caller location and (from the | ||||||||||||||||||||||||||||
| 90 | # second call on) the elapsed time. Kept file-scoped rather than 'state' so the | ||||||||||||||||||||||||||||
| 91 | # module stays free of feature pragmas. | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub _log { | ||||||||||||||||||||||||||
|
Subroutine
_log: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 93 | 0 | my ($str) = @_; | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | $str //= q{}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$str //= ""
MC/DC0%0/1
$str //= ""
$str
Truth table0%0/2
A
A= $str
| |||||||||||||||||||||||||||||
| 95 | 0 | $str =~ s{^\s*}{ }sx; | |||||||||||||||||||||||||||
| 96 | 0 | my ( $package, $filename, $line ) = caller; | |||||||||||||||||||||||||||
| 97 | 0 | my ( $seconds, $microseconds ) = gettimeofday; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | my $sec1 = $seconds - $LOG_SEC0; | |||||||||||||||||||||||||||
| 100 | 0 | my $usec1 = $microseconds - $LOG_USEC0; | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ( $usec1 < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $sec1--; | |||||||||||||||||||||||||||
| 103 | 0 | $usec1 += 1_000_000; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($LOG_SEC0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | print STDERR sprintf( '-- elapsed: %d.%06d sec', $sec1, $usec1 ), "\n"; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | 0 | ( $LOG_SEC0, $LOG_USEC0 ) = ( $seconds, $microseconds ); | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime($seconds); | |||||||||||||||||||||||||||
| 111 | 0 | my $timestamp = sprintf '%04d-%02d-%02d %02d:%02d:%02d.%06d', 1900 + $year, 1 + $mon, | |||||||||||||||||||||||||||
| 112 | $mday, $hour, $min, $sec, $microseconds; | ||||||||||||||||||||||||||||
| 113 | 0 | print STDERR sprintf( "\n%s %s %s +%d%s", $timestamp, $package, $filename, $line, $str ), "\n"; | |||||||||||||||||||||||||||
| 114 | 0 | return 0; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # Run a command, capture its streams and return its exit value. | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub my_system { | ||||||||||||||||||||||||||
|
Subroutine
my_system: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 0 | my ($cmd) = @_; | |||||||||||||||||||||||||||
| 120 | 0 | _log("Running command:\n$cmd"); | |||||||||||||||||||||||||||
| 121 | 0 | my ( $out, $err ); | |||||||||||||||||||||||||||
| 122 | 0 | run3 $cmd, undef, \$out, \$err; | |||||||||||||||||||||||||||
| 123 | 0 | my $ret = $?; | |||||||||||||||||||||||||||
| 124 | 0 | my ( $exit_value, $signal ) = ( $ret >> 8, $ret & 127 ); | |||||||||||||||||||||||||||
| 125 | 0 | _log("...done. exit_value=$exit_value signal=$signal"); | |||||||||||||||||||||||||||
| 126 | 0 | _log("...stdout:\n[[$out]]"); | |||||||||||||||||||||||||||
| 127 | 0 | _log("...stderr:\n[[$err]]"); | |||||||||||||||||||||||||||
| 128 | 0 | return $exit_value; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # Utility function to construct filenames. | ||||||||||||||||||||||||||||
| 132 | 4 | ▶ | sub EDMS_idldoc_seqpg { | ||||||||||||||||||||||||||
|
Subroutine
EDMS_idldoc_seqpg: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | 4 | my ( $idldoc, $page ) = @_; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 4 | return sprintf( "${idldoc}_%07d", $page ); | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # Package a DOC along with its index in a zip archive for later processing. | ||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub EDMS_prepare { | ||||||||||||||||||||||||||
|
Subroutine
EDMS_prepare: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 140 | 0 | my ( $app, $idldoc, $doc_path, $idx_path ) = @_; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ( !-e $doc_path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | carp "$doc_path don't exist"; | |||||||||||||||||||||||||||
| 144 | 0 | exit 0; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ( !-e $idx_path ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | carp "$idx_path don't exist"; | |||||||||||||||||||||||||||
| 148 | 0 | exit 0; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | my $cfg = config_read('EDOCMNGR'); | |||||||||||||||||||||||||||
| 152 | 0 | my $zip = Archive::Zip->new(); | |||||||||||||||||||||||||||
| 153 | 0 | $zip->addFile( $doc_path, "$app.$idldoc.pdf" ); | |||||||||||||||||||||||||||
| 154 | 0 | $zip->addFile( $idx_path, basename($idx_path) ); | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | my $zipfile = "$cfg->{'EDTK_DIR_EDOCMNGR'}/$app.$idldoc.out.zip"; | |||||||||||||||||||||||||||
| 157 | 0 | ▶ | die "ERROR: Could not create zip achive \"$zipfile\"\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | unless $zip->writeToFileNamed($zipfile) == AZ_OK; | ||||||||||||||||||||||||||||
| 159 | 0 | print "$zipfile\n"; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | return 1; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | # Package some documents along with one index in a zip archive. | ||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub EDMS_package { | ||||||||||||||||||||||||||
|
Subroutine
EDMS_package: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 0 | my $app = shift; | |||||||||||||||||||||||||||
| 167 | 0 | my $idldoc = shift; | |||||||||||||||||||||||||||
| 168 | 0 | my @elements = @_; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | my $cfg = config_read('EDOCMNGR'); | |||||||||||||||||||||||||||
| 171 | 0 | my $zip = Archive::Zip->new(); | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | foreach (@elements) { | |||||||||||||||||||||||||||
| 174 | 0 | $zip->addFile( $_, basename($_) ); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | my $zipfile = "$cfg->{'EDTK_DIR_EDOCMNGR'}/$app.$idldoc.out.zip"; | |||||||||||||||||||||||||||
| 178 | 0 | ▶ | die "ERROR: Could not create zip achive \"$zipfile\"\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | unless $zip->writeToFileNamed($zipfile) == AZ_OK; | ||||||||||||||||||||||||||||
| 180 | 0 | print "$zipfile\n"; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | return 1; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub EDMS_process_zip { | ||||||||||||||||||||||||||
|
Subroutine
EDMS_process_zip: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 0 | my ( $zipfile, $outdir ) = @_; | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 0 | my $zipname = basename($zipfile); | |||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ( $zipname !~ /^([^.]+)\.(.+)\.out\.zip$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | die "ERROR: Unexpected zip filename: $zipname\n"; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | 0 | my ( $app, $idldoc ) = ( $1, $2 ); | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 0 | my $zip = Archive::Zip->new(); | |||||||||||||||||||||||||||
| 195 | 0 | ▶ | if ( $zip->read($zipfile) != AZ_OK ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 0 | die "ERROR: Could not read zip archive \"$zipfile\"\n"; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | my @files = $zip->members(); | |||||||||||||||||||||||||||
| 200 | 0 | my ($idx_member) = $zip->membersMatching('\.idx1$'); | |||||||||||||||||||||||||||
| 201 | 0 | my ($doc_member) = $zip->membersMatching('\.pdf$'); | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | if ( !defined($doc_member) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 0 | ($doc_member) = $zip->membersMatching('\.xls$'); | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if ( !defined($doc_member) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 0 | ($doc_member) = $zip->membersMatching('\.doc$'); | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ( !defined($doc_member) || !defined($idx_member) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $doc_member and defined $idx_member
MC/DC0%0/2
defined $doc_member and defined $idx_member
defined $doc_member
defined $idx_member
Truth table0%0/3
A and B
A= defined $doc_memberB= defined $idx_member
| |||||||||||||||||||||||||||||
| 209 | 0 | die "ERROR: Could not find document(s) or index file in archive\n"; | |||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | 0 | my $doc_name = $doc_member->fileName(); | |||||||||||||||||||||||||||
| 212 | 0 | my $idx_name = $idx_member->fileName(); | |||||||||||||||||||||||||||
| 213 | 0 | my $doc_path = $doc_name; | |||||||||||||||||||||||||||
| 214 | 0 | my $idx_path = $idx_name; | |||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ( defined($outdir) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | $doc_path = "$outdir/$doc_path"; | |||||||||||||||||||||||||||
| 217 | 0 | $idx_path = "$outdir/$idx_path"; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ( $zip->extractMember( $doc_member, $doc_path ) != AZ_OK ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 0 | die "ERROR: Could not extract \"$doc_name\" from archive\n"; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ( $zip->extractMember( $idx_member, $idx_path ) != AZ_OK ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 0 | die "ERROR: Could not extract \"$idx_name\" from archive\n"; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | return EDMS_process( $app, $idldoc, $doc_name, $idx_name, $outdir ); | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | # Process document(s) with its index in a way suitable for the edms software. | ||||||||||||||||||||||||||||
| 230 | 0 | ▶ | sub EDMS_process { | ||||||||||||||||||||||||||
|
Subroutine
EDMS_process: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 231 | 0 | my ( $app, $idldoc, $doc, $index, $outdir ) = @_; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | _log("EDMS_process: app=$app idldoc=$idldoc doc=$doc index=$index outdir=$outdir"); | |||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | # Replace - and . with _ because Docubase cannot import names with dots. | ||||||||||||||||||||||||||||
| 236 | 0 | $idldoc =~ s/[-\.]/_/g; | |||||||||||||||||||||||||||
| 237 | 0 | $app =~ s/[-\.]/_/g; | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 0 | my $cfg = config_read('EDOCMNGR'); | |||||||||||||||||||||||||||
| 240 | 0 | my $format = $cfg->{'EDMS_IDX_FORMAT'}; | |||||||||||||||||||||||||||
| 241 | 0 | my @edmscols = split( /,/, $cfg->{'EDMS_INDEX_COLS'} ); | |||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | my $oldcwd; | |||||||||||||||||||||||||||
| 244 | 0 | ▶ | if ( defined($outdir) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 245 | 0 | $oldcwd = getcwd(); | |||||||||||||||||||||||||||
| 246 | 0 | ▶ | chdir($outdir) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | or die "ERROR: Cannot change current directory to \"$outdir\": $!\n"; | ||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | 0 | my @outfiles = (); | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ( $doc =~ /pdf$/i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | my $rv = | ||||||||||||||||||||||||||||
| 253 | 0 | my_system( $cfg->{'EDMS_BIN_PDFTK'} . " $doc burst output ${app}_${idldoc}_%07d.pdf " ); | |||||||||||||||||||||||||||
| 254 | 0 | ▶ | if ( $rv != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 255 | 0 | die "ERROR: Could not burst PDF file $doc!\n"; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | else { | ||||||||||||||||||||||||||||
| 259 | 0 | my $cible = _docubase_file_name($doc); | |||||||||||||||||||||||||||
| 260 | 0 | ▶ | move( $doc, $cible ) or die "ERROR: failed to move $cible ($doc)\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | 0 | push( @outfiles, $cible ); | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if ( $format eq 'DOCUBASE' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 265 | 0 | @outfiles = EDMS_idx_create_csv( $cfg, $index, $app, $idldoc, \@edmscols ); | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | elsif ( $format eq 'SCOPMASTER' ) { | ||||||||||||||||||||||||||||
| 268 | 0 | @outfiles = EDMS_idx_create_xml( $cfg, $index, $app, $idldoc, \@edmscols ); | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | else { | ||||||||||||||||||||||||||||
| 271 | 0 | die "ERROR: Unexpected index format: $format\n"; | |||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | if ( $cfg->{'EDTK_TYPE_ENV'} ne 'Test' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 275 | 0 | ▶ | unlink($doc) if ( $doc =~ /pdf$/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | 0 | unlink('doc_data.txt'); # pdftk creates this one. | |||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ( defined($outdir) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | # Restore the original working directory. | ||||||||||||||||||||||||||||
| 282 | 0 | chdir($oldcwd); | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 0 | return @outfiles; | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | # Transfer the PDF files and the index to the EDMS application. On success it | ||||||||||||||||||||||||||||
| 289 | # returns a true value: both callers guard with "EDMS_import(...) or die" | ||||||||||||||||||||||||||||
| 290 | # (oEdtk::Run), so a false success return would make that guard fatal. | ||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub EDMS_import { | ||||||||||||||||||||||||||
|
Subroutine
EDMS_import: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 292 | 0 | my ( $index, @docs ) = @_; | |||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 0 | my $cfg = config_read('EDOCMNGR'); | |||||||||||||||||||||||||||
| 295 | 0 | ▶ | my $ftp = Net::FTP->new( $cfg->{'EDMS_FTP_HOST'}, Port => $cfg->{'EDMS_FTP_PORT'} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | or die "ERROR: Cannot connect to $cfg->{'EDMS_FTP_HOST'}: $@\n"; | ||||||||||||||||||||||||||||
| 297 | 0 | ▶ | $ftp->login( $cfg->{'EDMS_FTP_USER'}, $cfg->{'EDMS_FTP_PASS'} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | or die "ERROR: Cannot login: " . $ftp->message() . "\n"; | ||||||||||||||||||||||||||||
| 299 | 0 | ▶ | $ftp->binary() | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | or die "ERROR: Cannot set binary mode: " . $ftp->message() . "\n"; | ||||||||||||||||||||||||||||
| 301 | 0 | ▶ | $ftp->cwd( $cfg->{'EDMS_FTP_DIR_DOCS'} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 302 | or die "ERROR: Cannot change working directory: " . $ftp->message() . "\n"; | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | # The index must be transferred last, otherwise the PDF files that have not | ||||||||||||||||||||||||||||
| 305 | # been transferred yet will not be processed. | ||||||||||||||||||||||||||||
| 306 | 0 | foreach my $doc (@docs) { | |||||||||||||||||||||||||||
| 307 | 0 | ▶ | $ftp->put($doc) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | or die "ERROR: Cannot upload DOC file: " . $ftp->message() . "\n"; | ||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | $ftp->cwd() | ||||||||||||||||||||||||||||
| 311 | 0 | ▶ | or die "ERROR: Cannot change working directory: " . $ftp->message() . "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 312 | 0 | ▶ | $ftp->cwd( $cfg->{'EDMS_FTP_DIR_IDX'} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | or die "ERROR: Cannot change working directory: " . $ftp->message() . "\n"; | ||||||||||||||||||||||||||||
| 314 | 0 | ▶ | $ftp->put($index) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | or die "ERROR: Cannot upload index file: " . $ftp->message() . "\n"; | ||||||||||||||||||||||||||||
| 316 | 0 | $ftp->quit(); | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 0 | return 1; | |||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | # Read the initial index file, and call the given function for each new | ||||||||||||||||||||||||||||
| 322 | # document. Also concatenate PDF files if needed (multi-page documents). | ||||||||||||||||||||||||||||
| 323 | 0 | ▶ | sub EDMS_idx_process($$$$&) { ## no critic (ProhibitSubroutinePrototypes) | ||||||||||||||||||||||||||
|
Subroutine
EDMS_idx_process: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 324 | 0 | my ( $app, $idx, $idldoc, $keys, $sub ) = @_; | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 0 | _log("EDMS_idx_process: app=$app idx=$idx idldoc=$idldoc"); | |||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 0 | ▶ | open( my $fh, '<', $idx ) or die "ERROR: Cannot open \"$idx\": $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 0 | my $csv = Text::CSV->new( { binary => 1, sep_char => ';' } ); | |||||||||||||||||||||||||||
| 330 | 0 | $csv->column_names(@INDEX_ECM_COLS); | |||||||||||||||||||||||||||
| 331 | 0 | my $lastdoc = 0; | |||||||||||||||||||||||||||
| 332 | 0 | my $firstpg = 0; | |||||||||||||||||||||||||||
| 333 | 0 | my $numpgs = 1; | |||||||||||||||||||||||||||
| 334 | 0 | my %docvals = (); | |||||||||||||||||||||||||||
| 335 | 0 | my $vals; | |||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | 0 | ▶ | while ( $vals = $csv->getline_hr($fh) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ( $vals->{'ED_SEQDOC'} != $lastdoc ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if ( $lastdoc != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 0 | EDMS_merge_docs( $app, $idldoc, $firstpg, $numpgs ); | |||||||||||||||||||||||||||
| 341 | 0 | $sub->( \%docvals, $firstpg, $numpgs ); | |||||||||||||||||||||||||||
| 342 | 0 | undef(%docvals); | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | 0 | $lastdoc = $vals->{'ED_SEQDOC'}; | |||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # Remember the values we are interested in for the edms. | ||||||||||||||||||||||||||||
| 347 | 0 | foreach (@$keys) { | |||||||||||||||||||||||||||
| 348 | 0 | $docvals{$_} = $vals->{$_}; | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | 0 | $docvals{'ED_DOCLIB'} = $vals->{'ED_DOCLIB'}; | |||||||||||||||||||||||||||
| 351 | 0 | $firstpg = $vals->{'ED_IDSEQPG'}; | |||||||||||||||||||||||||||
| 352 | 0 | $numpgs = 1; | |||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||
| 355 | else { | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | # Remember the values we are interested in for the edms. | ||||||||||||||||||||||||||||
| 358 | 0 | foreach (@$keys) { | |||||||||||||||||||||||||||
| 359 | 0 | ▶ | $docvals{$_} = $vals->{$_} if $vals->{$_}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | 0 | $docvals{'ED_DOCLIB'} = $vals->{'ED_DOCLIB'}; | |||||||||||||||||||||||||||
| 362 | 0 | $numpgs++; | |||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | 0 | close($fh); | |||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | # Handle the last document. | ||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if ( $lastdoc != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 0 | EDMS_merge_docs( $app, $idldoc, $firstpg, $numpgs ); | |||||||||||||||||||||||||||
| 370 | 0 | $sub->( \%docvals, $firstpg, $numpgs ); | |||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||
| 372 | 0 | return 0; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | 7 | ▶ | sub _docubase_file_name { | ||||||||||||||||||||||||||
|
Subroutine
_docubase_file_name: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 376 | 7 | my $filename = shift; | |||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 7 | $filename =~ s/(^.*)(\.\w{2,4}$)/$1/; | |||||||||||||||||||||||||||
| 379 | 7 | ▶ | my $ext = $2 || ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
$2 || ''
MC/DC100%1/1
$2 || ''
$2
Truth table100%2/2
A
A= $2
| |||||||||||||||||||||||||||||
| 380 | 7 | $filename =~ s/[-\.]/_/g; | |||||||||||||||||||||||||||
| 381 | 7 | $filename .= $ext; | |||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | 7 | return $filename; | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | # Prepend the Alfresco header line to the index CSV, when the site activates it | ||||||||||||||||||||||||||||
| 387 | # (EDMS_ACTIVATE_HEADER_ALFRESCO = YES). Default behaviour: do not activate. | ||||||||||||||||||||||||||||
| 388 | 0 | ▶ | sub preprend_alfresco_header_if_needed { | ||||||||||||||||||||||||||
|
Subroutine
preprend_alfresco_header_if_needed: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 389 | 0 | my ( $cfg, $fh, $csv ) = @_; | |||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | 0 | ▶ | if ( exists $cfg->{'EDMS_ACTIVATE_HEADER_ALFRESCO'} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $cfg->{"EDMS_ACTIVATE_HEADER_ALFRESCO"} and $cfg->{"EDMS_ACTIVATE_HEADER_ALFRESCO"} eq "YES"
MC/DC0%0/2
exists $cfg->{"EDMS_ACTIVATE_HEADER_ALFRESCO"} and $cfg->{"EDMS_ACTIVATE_HEADER_ALFRESCO"} eq "YES"
exists $cfg->{"EDMS_ACTIVATE_HEADER_ALFRESCO"}
$cfg->{"EDMS_ACTIVATE_HEADER_ALFRESCO"} eq "YES"
Truth table0%0/3
A and B
A= exists $cfg->{"EDMS_ACTIVATE_HEADER_ALFRESCO"}B= $cfg->{"EDMS_ACTIVATE_HEADER_ALFRESCO"} eq "YES"
| |||||||||||||||||||||||||||||
| 392 | && $cfg->{'EDMS_ACTIVATE_HEADER_ALFRESCO'} eq 'YES' ) | ||||||||||||||||||||||||||||
| 393 | { | ||||||||||||||||||||||||||||
| 394 | 0 | my $_csv = Text::CSV->new( { sep_char => ';' } ); | |||||||||||||||||||||||||||
| 395 | 0 | ▶ | if ( $_csv->parse( $cfg->{'EDMS_IDX_HEADER'} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 396 | 0 | $csv->print( $fh, [ $_csv->fields() ] ); | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | else { | ||||||||||||||||||||||||||||
| 399 | 0 | croak join( "\n", | |||||||||||||||||||||||||||
| 400 | 'Cannot parse config value EDMS_IDX_HEADER as a CSV record:', | ||||||||||||||||||||||||||||
| 401 | $_csv->error_diag(), '', 'Config value EDMS_IDX_HEADER is:', | ||||||||||||||||||||||||||||
| 402 | $_csv->error_input(), '' ); | ||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | 0 | return 0; | |||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | # Create an EDMS index file in CSV format (for the EDMS application). | ||||||||||||||||||||||||||||
| 409 | 0 | ▶ | sub EDMS_idx_create_csv { | ||||||||||||||||||||||||||
|
Subroutine
EDMS_idx_create_csv: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 410 | 0 | my ( $cfg, $idx, $app, $idldoc, $keys ) = @_; | |||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 0 | my $csv = Text::CSV->new( { binary => 1, sep_char => ';', eol => "\n", quote_space => 0 } ); | |||||||||||||||||||||||||||
| 413 | 0 | my $edmsidx = "${app}_$idldoc.idx"; | |||||||||||||||||||||||||||
| 414 | 0 | ▶ | open( my $fh, '>', $edmsidx ) or die "ERROR: Cannot create \"$edmsidx\": $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | 0 | preprend_alfresco_header_if_needed( $cfg, $fh, $csv ); | |||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | # Always return the index file as the first file in the list, see | ||||||||||||||||||||||||||||
| 419 | # EDMS_import() for why this is important. | ||||||||||||||||||||||||||||
| 420 | 0 | my @outfiles = ($edmsidx); | |||||||||||||||||||||||||||
| 421 | EDMS_idx_process( | ||||||||||||||||||||||||||||
| 422 | $app, $idx, $idldoc, $keys, | ||||||||||||||||||||||||||||
| 423 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 424 | 0 | my ( $vals, $firstpg, $numpgs ) = @_; | |||||||||||||||||||||||||||
| 425 | 0 | my $iddoc = $vals->{'ED_IDLDOC'}; | |||||||||||||||||||||||||||
| 426 | 0 | delete( $vals->{'ED_IDLDOC'} ); | |||||||||||||||||||||||||||
| 427 | 0 | ▶ | if ( $vals->{'ED_DOCLIB'} =~ /pdf$/i ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | 0 | $vals->{'EDMS_IDLDOC_SEQPG'} = EDMS_idldoc_seqpg( $iddoc, $firstpg ); | |||||||||||||||||||||||||||
| 429 | 0 | $vals->{'EDMS_FILENAME'} = | |||||||||||||||||||||||||||
| 430 | "${app}_" . EDMS_idldoc_seqpg( $idldoc, $firstpg ) . ".pdf"; | ||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||
| 432 | else { | ||||||||||||||||||||||||||||
| 433 | 0 | $vals->{'EDMS_FILENAME'} = _docubase_file_name( $vals->{'ED_DOCLIB'} ); | |||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | # Dates need to be in a specific format. | ||||||||||||||||||||||||||||
| 437 | 0 | my $datefmt = $cfg->{'EDMS_DATE_FORMAT'}; | |||||||||||||||||||||||||||
| 438 | 0 | ▶ | if ( $vals->{'ED_DTEDTION'} !~ /^(\d{4})(\d{2})(\d{2})$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | 0 | die "ERROR: Unexpected date format for ED_DTEDTION: $vals->{'ED_DTEDTION'}\n"; | |||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||
| 441 | 0 | my ( $year, $month, $day ) = ( $1, $2, $3 ); | |||||||||||||||||||||||||||
| 442 | 0 | $vals->{'EDMS_PROCESS_DT'} = | |||||||||||||||||||||||||||
| 443 | strftime( $datefmt, 0, 0, 0, $day, $month - 1, $year - 1900 ); | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | # Owner id for group access in edms. | ||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ( $vals->{'ED_IDEMET'} =~ /^\D{1}\d{3}/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | 0 | $vals->{'ED_OWNER'} = $vals->{'ED_IDEMET'}; | |||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||
| 449 | else { | ||||||||||||||||||||||||||||
| 450 | 0 | $vals->{'ED_OWNER'} = $vals->{'ED_SOURCE'}; | |||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | # Remove every ';' from the values (the fork's ECM constraint). | ||||||||||||||||||||||||||||
| 454 | 0 | foreach my $key (@$keys) { | |||||||||||||||||||||||||||
| 455 | 0 | $vals->{$key} =~ s/;//g; | |||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 0 | my @edmsvals = map { $vals->{$_} } @$keys; | |||||||||||||||||||||||||||
| 459 | 0 | $csv->print( $fh, \@edmsvals ); | |||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | 0 | push( @outfiles, $vals->{'EDMS_FILENAME'} ); | |||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||
| 463 | 0 | ); | |||||||||||||||||||||||||||
| 464 | 0 | close($fh); | |||||||||||||||||||||||||||
| 465 | 0 | return @outfiles; | |||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | # Create edms indexes in XML format (one per PDF file). | ||||||||||||||||||||||||||||
| 469 | 0 | ▶ | sub EDMS_idx_create_xml { | ||||||||||||||||||||||||||
|
Subroutine
EDMS_idx_create_xml: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 470 | 0 | my ( $cfg, $idx, $app, $idldoc, $keys ) = @_; | |||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 0 | my @outfiles = (); | |||||||||||||||||||||||||||
| 473 | EDMS_idx_process( | ||||||||||||||||||||||||||||
| 474 | $app, $idx, $idldoc, $keys, | ||||||||||||||||||||||||||||
| 475 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 476 | 0 | my ( $vals, $firstpg, $numpgs ) = @_; | |||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||
| 478 | 0 | my $docid = EDMS_idldoc_seqpg( $vals->{'ED_IDLDOC'}, $firstpg ); | |||||||||||||||||||||||||||
| 479 | 0 | delete( $vals->{'ED_IDLDOC'} ); | |||||||||||||||||||||||||||
| 480 | 0 | my $xmlfile = "$docid.edms.xml"; | |||||||||||||||||||||||||||
| 481 | 0 | $vals->{'ED_DOCLIB'} =~ /\.(\w{2,4})$/; | |||||||||||||||||||||||||||
| 482 | 0 | my $ext = $1; | |||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | 0 | ▶ | open( my $fh, '>', $xmlfile ) or die "ERROR: Cannot create \"$xmlfile\": $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 485 | 0 | my $xml = XML::Writer->new( OUTPUT => $fh, ENCODING => 'utf-8' ); | |||||||||||||||||||||||||||
| 486 | 0 | $xml->xmlDecl('utf-8'); | |||||||||||||||||||||||||||
| 487 | 0 | $xml->startTag('idxext'); | |||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 0 | foreach my $pagenum ( 1 .. $numpgs ) { | |||||||||||||||||||||||||||
| 490 | 0 | $xml->startTag( 'page', num => $pagenum ); | |||||||||||||||||||||||||||
| 491 | 0 | ▶ | if ( $pagenum == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 492 | 0 | ▶ | while ( my ( $key, $val ) = each(%$vals) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 493 | 0 | $xml->emptyTag( 'index', key => $key, value => $val ); | |||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | 0 | $xml->endTag('page'); | |||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||
| 498 | 0 | $xml->endTag('idxext'); | |||||||||||||||||||||||||||
| 499 | 0 | $xml->end(); | |||||||||||||||||||||||||||
| 500 | 0 | close($fh); | |||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | 0 | push( @outfiles, $xmlfile ); | |||||||||||||||||||||||||||
| 503 | 0 | push( @outfiles, "${app}_$docid.$ext" ); | |||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||
| 505 | 0 | ); | |||||||||||||||||||||||||||
| 506 | 0 | return @outfiles; | |||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | # Concatenate PDF documents if needed. | ||||||||||||||||||||||||||||
| 510 | 0 | ▶ | sub EDMS_merge_docs { | ||||||||||||||||||||||||||
|
Subroutine
EDMS_merge_docs: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 511 | 0 | my ( $app, $idldoc, $firstpg, $numpgs ) = @_; | |||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 0 | _log("EDMS_merge_docs: app=$app idldoc=$idldoc firstpg=$firstpg numpgs=$numpgs"); | |||||||||||||||||||||||||||
| 514 | 0 | my $cfg = config_read('EDOCMNGR'); | |||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | # A single-page document has nothing to concatenate. | ||||||||||||||||||||||||||||
| 517 | 0 | ▶ | return unless $numpgs > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | 0 | my $lastpg = $firstpg + $numpgs - 1; | |||||||||||||||||||||||||||
| 520 | my @pages = | ||||||||||||||||||||||||||||
| 521 | 0 | map { "${app}_" . EDMS_idldoc_seqpg( $idldoc, $_ ) . ".pdf" } ( $firstpg .. $lastpg ); | |||||||||||||||||||||||||||
| 522 | 0 | my $output = "$pages[0].tmp"; | |||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||
| 524 | 0 | ▶ | if ( defined $cfg->{'EDMS_BIN_GS'} && $cfg->{'EDMS_BIN_GS'} ne "" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cfg->{"EDMS_BIN_GS"} and $cfg->{"EDMS_BIN_GS"} ne ""
MC/DC0%0/2
defined $cfg->{"EDMS_BIN_GS"} and $cfg->{"EDMS_BIN_GS"} ne ""
defined $cfg->{"EDMS_BIN_GS"}
$cfg->{"EDMS_BIN_GS"} ne ""
Truth table0%0/3
A and B
A= defined $cfg->{"EDMS_BIN_GS"}B= $cfg->{"EDMS_BIN_GS"} ne ""
| |||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||
| 526 | # PDFs created with pdftk are too heavy, so change the operating mode. | ||||||||||||||||||||||||||||
| 527 | my $gs = | ||||||||||||||||||||||||||||
| 528 | 0 | my_system( $cfg->{'EDMS_BIN_GS'} | |||||||||||||||||||||||||||
| 529 | . " -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$output @pages " ); | ||||||||||||||||||||||||||||
| 530 | 0 | ▶ | if ( $gs != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 531 | 0 | die "ERROR: Could not concatenate pages $firstpg to $lastpg!\n"; | |||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||
| 534 | else { | ||||||||||||||||||||||||||||
| 535 | my $rv = | ||||||||||||||||||||||||||||
| 536 | my_system( | ||||||||||||||||||||||||||||
| 537 | 0 | $cfg->{'EDMS_BIN_PDFTK'} . " " . join( ' ', @pages ) . " cat output $output" ); | |||||||||||||||||||||||||||
| 538 | 0 | ▶ | if ( $rv != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 539 | 0 | die "ERROR: Could not concatenate pages $firstpg to $lastpg!\n"; | |||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | # Remove the old files and rename the concatenated PDF after the first page. | ||||||||||||||||||||||||||||
| 544 | 0 | foreach (@pages) { | |||||||||||||||||||||||||||
| 545 | 0 | unlink($_); | |||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||
| 547 | 0 | move( $output, $pages[0] ); | |||||||||||||||||||||||||||
| 548 | 0 | return; | |||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | # Build the ECM index keys of one document from the raw request parameters. The | ||||||||||||||||||||||||||||
| 552 | # fork exported this sub but never defined it; the mainline body is kept here. | ||||||||||||||||||||||||||||
| 553 | 0 | ▶ | sub EDMS_edidx_build(\%) { ## no critic (ProhibitSubroutinePrototypes) | ||||||||||||||||||||||||||
|
Subroutine
EDMS_edidx_build: not called CC=17 SCAR=57.2
Pod
documented
| |||||||||||||||||||||||||||||
| 554 | 0 | my ($refOpt) = @_; | |||||||||||||||||||||||||||
| 555 | 0 | my $cfg = config_read('EDOCMNGR'); | |||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||
| 557 | # required index keys : ED_REFIDDOC, ED_CORP, ED_SOURCE, ED_IDDEST, ED_NOMDEST, ED_IDEMET, ED_OWNER, ED_CORP | ||||||||||||||||||||||||||||
| 558 | # optional keys : ED_DTEDTION, ED_CLEGED1, ED_VILLDEST, ED_CLEGED2, ED_CLEGED3, ED_CLEGED4 | ||||||||||||||||||||||||||||
| 559 | # computed/(re)computed keys : ED_DTEDTION, EDMS_IDLDOC_SEQPG, EDMS_FILENAME | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | # REQUIRED KEYS | ||||||||||||||||||||||||||||
| 562 | 0 | ▶ | if ( !defined $$refOpt{'ED_REFIDDOC'} or $$refOpt{'ED_REFIDDOC'} eq "" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $refOpt->{"ED_REFIDDOC"} or $refOpt->{"ED_REFIDDOC"} eq ""
MC/DC0%0/2
not defined $refOpt->{"ED_REFIDDOC"} or $refOpt->{"ED_REFIDDOC"} eq ""
not defined $refOpt->{"ED_REFIDDOC"}
$refOpt->{"ED_REFIDDOC"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $refOpt->{"ED_REFIDDOC"}B= $refOpt->{"ED_REFIDDOC"} eq ""
| |||||||||||||||||||||||||||||
| 563 | 0 | die "ERROR: ED_REFIDDOC required.\n"; | |||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||
| 565 | 0 | ▶ | if ( !defined $$refOpt{'ED_SOURCE'} or $$refOpt{'ED_SOURCE'} eq "" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $refOpt->{"ED_SOURCE"} or $refOpt->{"ED_SOURCE"} eq ""
MC/DC0%0/2
not defined $refOpt->{"ED_SOURCE"} or $refOpt->{"ED_SOURCE"} eq ""
not defined $refOpt->{"ED_SOURCE"}
$refOpt->{"ED_SOURCE"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $refOpt->{"ED_SOURCE"}B= $refOpt->{"ED_SOURCE"} eq ""
| |||||||||||||||||||||||||||||
| 566 | 0 | die "ERROR: ED_SOURCE required.\n"; | |||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||
| 568 | 0 | ▶ | if ( !defined $$refOpt{'ED_IDDEST'} or $$refOpt{'ED_IDDEST'} eq "" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $refOpt->{"ED_IDDEST"} or $refOpt->{"ED_IDDEST"} eq ""
MC/DC0%0/2
not defined $refOpt->{"ED_IDDEST"} or $refOpt->{"ED_IDDEST"} eq ""
not defined $refOpt->{"ED_IDDEST"}
$refOpt->{"ED_IDDEST"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $refOpt->{"ED_IDDEST"}B= $refOpt->{"ED_IDDEST"} eq ""
| |||||||||||||||||||||||||||||
| 569 | 0 | die "ERROR: ED_IDDEST required.\n"; | |||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||
| 571 | 0 | ▶ | if ( !defined $$refOpt{'ED_NOMDEST'} or $$refOpt{'ED_NOMDEST'} eq "" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $refOpt->{"ED_NOMDEST"} or $refOpt->{"ED_NOMDEST"} eq ""
MC/DC0%0/2
not defined $refOpt->{"ED_NOMDEST"} or $refOpt->{"ED_NOMDEST"} eq ""
not defined $refOpt->{"ED_NOMDEST"}
$refOpt->{"ED_NOMDEST"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $refOpt->{"ED_NOMDEST"}B= $refOpt->{"ED_NOMDEST"} eq ""
| |||||||||||||||||||||||||||||
| 572 | 0 | die "ERROR: ED_NOMDEST required.\n"; | |||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||
| 574 | 0 | ▶ | if ( !defined $$refOpt{'ED_IDEMET'} or $$refOpt{'ED_IDEMET'} eq "" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $refOpt->{"ED_IDEMET"} or $refOpt->{"ED_IDEMET"} eq ""
MC/DC0%0/2
not defined $refOpt->{"ED_IDEMET"} or $refOpt->{"ED_IDEMET"} eq ""
not defined $refOpt->{"ED_IDEMET"}
$refOpt->{"ED_IDEMET"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $refOpt->{"ED_IDEMET"}B= $refOpt->{"ED_IDEMET"} eq ""
| |||||||||||||||||||||||||||||
| 575 | 0 | die "ERROR: ED_IDEMET required.\n"; | |||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||
| 577 | 0 | ▶ | if ( !defined $$refOpt{'ED_OWNER'} or $$refOpt{'ED_OWNER'} eq "" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $refOpt->{"ED_OWNER"} or $refOpt->{"ED_OWNER"} eq ""
MC/DC0%0/2
not defined $refOpt->{"ED_OWNER"} or $refOpt->{"ED_OWNER"} eq ""
not defined $refOpt->{"ED_OWNER"}
$refOpt->{"ED_OWNER"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $refOpt->{"ED_OWNER"}B= $refOpt->{"ED_OWNER"} eq ""
| |||||||||||||||||||||||||||||
| 578 | 0 | die "ERROR: ED_OWNER required.\n"; | |||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||
| 580 | 0 | ▶ | if ( !defined $$refOpt{'ED_CORP'} or $$refOpt{'ED_CORP'} eq "" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $refOpt->{"ED_CORP"} or $refOpt->{"ED_CORP"} eq ""
MC/DC0%0/2
not defined $refOpt->{"ED_CORP"} or $refOpt->{"ED_CORP"} eq ""
not defined $refOpt->{"ED_CORP"}
$refOpt->{"ED_CORP"} eq ""
Truth table0%0/3
not(A) or B
A= not defined $refOpt->{"ED_CORP"}B= $refOpt->{"ED_CORP"} eq ""
| |||||||||||||||||||||||||||||
| 581 | 0 | die "ERROR: ED_CORP required.\n"; | |||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | # COMPUTED KEYS | ||||||||||||||||||||||||||||
| 585 | 0 | my $FILE_EXT = $$refOpt{'ED_FILENAME'}; | |||||||||||||||||||||||||||
| 586 | 0 | $FILE_EXT =~ s/^(.*\.)(\w+)$/$2/; | |||||||||||||||||||||||||||
| 587 | 0 | $$refOpt{'ED_FORMFLUX'} = uc($FILE_EXT); | |||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | 0 | my ( $sec, $min, $hour, $day, $month, $year ); | |||||||||||||||||||||||||||
| 590 | 0 | ▶ | if ( !defined $$refOpt{'ED_DTEDTION'} || $$refOpt{'ED_DTEDTION'} !~ /^(\d{4})(\d{2})(\d{2})$/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $refOpt->{'ED_DTEDTION'} && $refOpt->{'ED_DTEDTION'} =~ /^(\d{4})(\d{2})(\d{2})$/
MC/DC0%0/2
defined $refOpt->{'ED_DTEDTION'} && $refOpt->{'ED_DTEDTION'} =~ /^(\d{4})(\d{2})(\d{2})$/
defined $refOpt->{'ED_DTEDTION'}
$refOpt->{'ED_DTEDTION'} =~ /^(\d{4})(\d{2})(\d{2})$/
Truth table0%0/3
A && B
A= defined $refOpt->{'ED_DTEDTION'}B= $refOpt->{'ED_DTEDTION'} =~ /^(\d{4})(\d{2})(\d{2})$/
| |||||||||||||||||||||||||||||
| 591 | { | ||||||||||||||||||||||||||||
| 592 | 0 | ( $sec, $min, $hour, $day, $month, $year ) = localtime(); | |||||||||||||||||||||||||||
| 593 | 0 | $month++; | |||||||||||||||||||||||||||
| 594 | 0 | $year += 1900; | |||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||
| 596 | else { | ||||||||||||||||||||||||||||
| 597 | 0 | ( $year, $month, $day ) = ( $1, $2, $3 ); | |||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||
| 600 | # DATES NEED TO BE IN A SPECIFIC FORMAT. | ||||||||||||||||||||||||||||
| 601 | 0 | my $datefmt = $cfg->{'EDMS_DATE_FORMAT'}; | |||||||||||||||||||||||||||
| 602 | 0 | $$refOpt{'ED_DTEDTION'} = strftime( $datefmt, 0, 0, 0, $day, $month - 1, $year - 1900 ); | |||||||||||||||||||||||||||
| 603 | 0 | $$refOpt{'ED_IDLDOC'} = oEdtk::Main::oe_ID_LDOC(); | |||||||||||||||||||||||||||
| 604 | 0 | $$refOpt{'ED_IDSEQPG'} = 1; | |||||||||||||||||||||||||||
| 605 | 0 | $$refOpt{'ED_SEQDOC'} = 1; | |||||||||||||||||||||||||||
| 606 | $$refOpt{'EDMS_IDLDOC_SEQPG'} = | ||||||||||||||||||||||||||||
| 607 | 0 | EDMS_idldoc_seqpg( $$refOpt{'ED_IDLDOC'}, $$refOpt{'ED_IDSEQPG'} ); | |||||||||||||||||||||||||||
| 608 | 0 | $$refOpt{'EDMS_FILENAME'} = $$refOpt{'ED_REFIDDOC'} . "_" . $$refOpt{'EDMS_IDLDOC_SEQPG'}; | |||||||||||||||||||||||||||
| 609 | 0 | $$refOpt{'EDMS_FILENAME'} =~ s/[-\.\s]/_/g; | |||||||||||||||||||||||||||
| 610 | 0 | $$refOpt{'EDMS_FILENAME'} = $$refOpt{'EDMS_FILENAME'} . "." . $FILE_EXT; | |||||||||||||||||||||||||||
| 611 | 0 | $$refOpt{'ED_DOCLIB'} = $$refOpt{'EDMS_FILENAME'}; | |||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | # OPTIONAL KEYS | ||||||||||||||||||||||||||||
| 614 | 0 | $$refOpt{'ED_VILLDEST'} |= ""; | |||||||||||||||||||||||||||
| 615 | 0 | $$refOpt{'ED_CLEGED1'} |= ""; | |||||||||||||||||||||||||||
| 616 | 0 | $$refOpt{'ED_CLEGED2'} |= ""; | |||||||||||||||||||||||||||
| 617 | 0 | $$refOpt{'ED_CLEGED3'} |= ""; | |||||||||||||||||||||||||||
| 618 | 0 | $$refOpt{'ED_CLEGED4'} |= ""; | |||||||||||||||||||||||||||
| 619 | 0 | return; | |||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | # Append one index line, in the EDMS_INDEX_COLS order, to the EDMS index file. | ||||||||||||||||||||||||||||
| 623 | 0 | ▶ | sub EDMS_edidx_write(\%) { ## no critic (ProhibitSubroutinePrototypes) | ||||||||||||||||||||||||||
|
Subroutine
EDMS_edidx_write: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 624 | 0 | my ($refOpt) = shift; | |||||||||||||||||||||||||||
| 625 | 0 | my $cfg = config_read('EDOCMNGR'); | |||||||||||||||||||||||||||
| 626 | 0 | my @edms_cols = split( /,/, $cfg->{'EDMS_INDEX_COLS'} ); | |||||||||||||||||||||||||||
| 627 | 0 | my $index = $$refOpt{'ED_REFIDDOC'} . "_" . $$refOpt{'ED_IDLDOC'} . ".idx"; | |||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||
| 629 | 0 | ▶ | open( my $fh, '>>', $index ) or die "ERROR: can't open $index : $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 630 | 0 | my $csv = Text::CSV->new( { binary => 1, sep_char => ';', eol => "\n", quote_space => 0 } ); | |||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | 0 | my @fields; | |||||||||||||||||||||||||||
| 633 | 0 | foreach my $key (@edms_cols) { | |||||||||||||||||||||||||||
| 634 | 0 | push( @fields, $$refOpt{$key} ); | |||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | 0 | $csv->print( $fh, \@fields ); | |||||||||||||||||||||||||||
| 638 | 0 | close($fh); | |||||||||||||||||||||||||||
| 639 | 0 | return; | |||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||
| 642 | 20 | 1; | |||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||
| 644 | =head1 NAME | ||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||
| 646 | oEdtk::EDMS - electronic document management output: index files and archive transfer | ||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | use oEdtk::EDMS qw(EDMS_process EDMS_import); | ||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | my @files = EDMS_process($app, $idldoc, $doc, $index, $outdir); | ||||||||||||||||||||||||||||
| 653 | EDMS_import($index, @files) or die "transfer failed\n"; | ||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||
| 655 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | Builds the index files that feed an electronic document management system and | ||||||||||||||||||||||||||||
| 658 | transfers them to it. A document and its per-page index are packed into a zip | ||||||||||||||||||||||||||||
| 659 | archive, then unpacked and processed: PDF pages are burst or concatenated with | ||||||||||||||||||||||||||||
| 660 | the configured helpers, and the index is rewritten in the format the site | ||||||||||||||||||||||||||||
| 661 | expects (C<DOCUBASE> CSV or C<SCOPMASTER> XML). C<EDMS_import> uploads the | ||||||||||||||||||||||||||||
| 662 | result over FTP, the index last so that the documents are already in place. | ||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||
| 664 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||
| 666 | =head2 EDMS_edidx_build | ||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | EDMS_edidx_build(\%options); | ||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||
| 670 | Fill the required ECM index keys of one document from the raw request | ||||||||||||||||||||||||||||
| 671 | parameters. Dies when a required key is missing, and computes the derived keys | ||||||||||||||||||||||||||||
| 672 | (the edition date, the document id, the page sequence and the file name). | ||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||
| 674 | =head2 EDMS_edidx_write | ||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||
| 676 | EDMS_edidx_write(\%options); | ||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||
| 678 | Append one index line, in the C<EDMS_INDEX_COLS> order, to the per-document | ||||||||||||||||||||||||||||
| 679 | index file. | ||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||
| 681 | =head2 EDMS_idldoc_seqpg | ||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | my $id = EDMS_idldoc_seqpg($idldoc, $page); | ||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | Build the C<idldoc_NNNNNNN> identifier that names one page of a document. | ||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | =head2 EDMS_idx_create_csv | ||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||
| 689 | my @files = EDMS_idx_create_csv($cfg, $idx, $app, $idldoc, $keys); | ||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | Build the C<DOCUBASE> index in CSV form, one line per document, and return the | ||||||||||||||||||||||||||||
| 692 | index file first followed by each document file name. | ||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||
| 694 | =head2 EDMS_import | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | EDMS_import($index, @docs) or die; | ||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | Upload the documents and then the index to the EDMS application over FTP. | ||||||||||||||||||||||||||||
| 699 | Returns true on success, so callers can guard with C<or die>. | ||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||
| 701 | =head2 EDMS_package | ||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||
| 703 | EDMS_package($app, $idldoc, @elements); | ||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||
| 705 | Pack some documents together with one index into the standard out zip archive | ||||||||||||||||||||||||||||
| 706 | and print the path of the archive. Returns true on success. | ||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||
| 708 | =head2 EDMS_prepare | ||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||
| 710 | EDMS_prepare($app, $idldoc, $doc_path, $idx_path); | ||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||
| 712 | Pack a document and its index into the standard out zip archive, or stop when | ||||||||||||||||||||||||||||
| 713 | either file is missing. Returns true on success. | ||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | =head2 EDMS_process | ||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||
| 717 | my @files = EDMS_process($app, $idldoc, $doc, $index, $outdir); | ||||||||||||||||||||||||||||
| 718 | |||||||||||||||||||||||||||||
| 719 | Burst or move the document, build its index in the configured format, and | ||||||||||||||||||||||||||||
| 720 | return the produced files. The optional C<$outdir> is used as a working | ||||||||||||||||||||||||||||
| 721 | directory and restored afterwards. | ||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||
| 723 | =head2 EDMS_process_zip | ||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||
| 725 | my @files = EDMS_process_zip($zipfile, $outdir); | ||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||
| 727 | Read a standard out zip archive, extract its document and index, and return | ||||||||||||||||||||||||||||
| 728 | L</EDMS_process> of the pair. | ||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||
| 730 | The following subs are internal helpers and are not part of the public API: | ||||||||||||||||||||||||||||
| 731 | C<_log>, C<my_system>, C<EDMS_idx_process>, C<EDMS_merge_docs>, | ||||||||||||||||||||||||||||
| 732 | C<EDMS_idx_create_xml>, C<_docubase_file_name> and | ||||||||||||||||||||||||||||
| 733 | C<preprend_alfresco_header_if_needed>. | ||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||
| 735 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||
| 737 | The oEdtk team. | ||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||
| 739 | =cut | ||||||||||||||||||||||||||||