| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use oEdtk::Main; | ||
| 7 | use oEdtk::Config qw(config_read); | ||
| 8 | use oEdtk::DBAdmin qw(db_connect); | ||
| 9 | use Term::ReadKey; | ||
| 10 | use Sys::Hostname; | ||
| 11 | |||
| 12 | sub usage () { | ||
| 13 | warn "Usage: $0 <ANO|DUPLE|STOP|RESET> <idldoc|seqlot> [idseqpg|STOP_status] \n\n" | ||
| 14 | . "\tThis changes docs status for omgr administration.\n\n" | ||
| 15 | . "\t ANO\tblock doc(s) for anomaly in doc\n" | ||
| 16 | . "\t DUPLE\tblock duplicated doc(s)\n" | ||
| 17 | . "\t STOP\tblock to stop doc(s)\t(index_Purge_DCLIB won't delete DCLIB)\n" | ||
| 18 | . "\t RESET\tunblock to redo doc(s)\t(index_Purge_DCLIB won't delete DCLIB)\n\n" | ||
| 19 | . "\t idldoc is a complete UUID (ie. 5ADF7A26-C0B7-11EC-B330-EC8130CC0BFB),\n" | ||
| 20 | . "\t or its legacy 16-digit form (ie. 2241234567894561)\n" | ||
| 21 | . "\t or idldoc is a part of idldoc (ie. 2241% or 5ADF7A26%), with at least 4 chars \n" | ||
| 22 | . "\t STOP_status to change only documents set previously as 'STOP' \n"; | ||
| 23 | exit 1; | ||
| 24 | } | ||
| 25 | |||
| 26 | if ( @ARGV < 2 or $ARGV[0] =~ /-h/i ) { | ||
| 27 | usage(); | ||
| 28 | } | ||
| 29 | |||
| 30 | my ( $event, $key1, $key2 ) = ( $ARGV[0], $ARGV[1], $ARGV[2] ); | ||
| 31 | if ( $event =~ /^ANO$/i ) { | ||
| 32 | } | ||
| 33 | elsif ( $event =~ /^DUPLE$/i ) { | ||
| 34 | } | ||
| 35 | elsif ( $event =~ /^STOP$/i ) { | ||
| 36 | } | ||
| 37 | elsif ( $event =~ /^RESET$/i ) { | ||
| 38 | } | ||
| 39 | else { | ||
| 40 | usage(); | ||
| 41 | } | ||
| 42 | |||
| 43 | my $type = ""; | ||
| 44 | if ( oe_is_IDLDOC($key1) ) { # 1392153206001881 or a 36-char UUID | ||
| 45 | $type = 'idldoc'; | ||
| 46 | |||
| 47 | } | ||
| 48 | elsif ( $key1 =~ /^[0-9A-Fa-f-]{4,35}\%$/ ) { # 2241% or a UUID prefix | ||
| 49 | $type = 'idldoc'; | ||
| 50 | |||
| 51 | } | ||
| 52 | elsif ( $key1 =~ /^\d{7}$/ ) { # 1411123 | ||
| 53 | $type = 'seqlot'; | ||
| 54 | |||
| 55 | } | ||
| 56 | else { | ||
| 57 | usage(); | ||
| 58 | } | ||
| 59 | $key2 = $key2 || 0; | ||
| 60 | |||
| 61 | my $cfg = config_read('EDTK_STATS'); | ||
| 62 | my $dbh = db_connect( $cfg, 'EDTK_DBI_STATS', { AutoCommit => 1, RaiseError => 1 } ); | ||
| 63 | |||
| 64 | ################################################################################ | ||
| 65 | |||
| 66 | my $sql = | ||
| 67 | "SELECT ED_REFIDDOC, ED_SOURCE, ED_IDLDOC, ED_SEQDOC, ED_DTEDTION, ED_NOMDEST" | ||
| 68 | . " FROM " | ||
| 69 | . $cfg->{'EDTK_DBI_OUTMNGR'}; | ||
| 70 | |||
| 71 | # . " FROM EDTK_INDEX "; | ||
| 72 | my $where; | ||
| 73 | my @values; | ||
| 74 | push( @values, $key1 ); | ||
| 75 | my $sequence = 0; | ||
| 76 | |||
| 77 | if ( $type eq 'idldoc' ) { | ||
| 78 | if ( $key1 =~ /\%$/ ) { | ||
| 79 | $where .= " WHERE ED_IDLDOC like ? "; | ||
| 80 | } | ||
| 81 | else { | ||
| 82 | $where .= " WHERE ED_IDLDOC = ? "; | ||
| 83 | } | ||
| 84 | |||
| 85 | if ( defined $key2 && ( $key2 =~ /^STOP$/i ) ) { | ||
| 86 | $where .= " AND ED_STATUS = ? "; | ||
| 87 | push( @values, $key2 ); | ||
| 88 | |||
| 89 | } | ||
| 90 | elsif ( defined $key2 && $key2 > 0 && $key1 !~ /\%$/ ) { # key2 is the page number | ||
| 91 | #} elsif (defined $key2 && $key2 > 0 ){ | ||
| 92 | $where .= | ||
| 93 | " AND ED_SEQDOC = (SELECT ED_SEQDOC FROM " | ||
| 94 | . $cfg->{'EDTK_DBI_OUTMNGR'} | ||
| 95 | . " WHERE ED_IDLDOC = ? AND ED_IDSEQPG = ? )"; | ||
| 96 | |||
| 97 | # $where .=" AND ED_SEQDOC = (SELECT ED_SEQDOC FROM EDTK_INDEX WHERE ED_IDLDOC = ? AND ED_IDSEQPG = ? )"; | ||
| 98 | push( @values, $key1, $key2 ); | ||
| 99 | $sequence = $key2; | ||
| 100 | } | ||
| 101 | |||
| 102 | } | ||
| 103 | elsif ( $type eq 'seqlot' ) { | ||
| 104 | $where .= " WHERE ED_SEQLOT = ? "; | ||
| 105 | } | ||
| 106 | |||
| 107 | my $present = " GROUP BY ED_REFIDDOC, ED_IDLDOC, ED_SEQDOC, ED_NOMDEST, ED_DTEDTION, ED_SOURCE "; | ||
| 108 | $present .= " ORDER BY ED_REFIDDOC, ED_IDLDOC, ED_SEQDOC, ED_NOMDEST, ED_DTEDTION, ED_SOURCE "; | ||
| 109 | |||
| 110 | my $sth = $dbh->prepare( $sql . $where . $present ); | ||
| 111 | $sth->execute(@values); | ||
| 112 | my $rows = $sth->fetchall_arrayref(); | ||
| 113 | |||
| 114 | if ( !scalar @{$rows} ) { | ||
| 115 | warn "INFO: no associated data.\n"; | ||
| 116 | |||
| 117 | # track the action | ||
| 118 | exit; | ||
| 119 | } | ||
| 120 | |||
| 121 | my $row_count = $#$rows + 1; | ||
| 122 | if ( $row_count <= 10 ) { | ||
| 123 | foreach my $row (@$rows) { | ||
| 124 | printf "%14s %6s %16s %09d %8s %-30s \n", @$row, ""; # 1391152325098839 | ||
| 125 | } | ||
| 126 | } | ||
| 127 | warn "INFO: Confirm Block request to set " . $row_count . " doc(s) for '$event' event ? (y/n)\n"; | ||
| 128 | |||
| 129 | ReadMode('raw'); | ||
| 130 | my $key = ReadKey(); | ||
| 131 | if ( $key !~ /^y$/i ) { | ||
| 132 | die "INFO: abort request\n"; | ||
| 133 | } | ||
| 134 | ReadMode('restore'); | ||
| 135 | |||
| 136 | my $updt = | ||
| 137 | "UPDATE " | ||
| 138 | . $cfg->{'EDTK_DBI_OUTMNGR'} | ||
| 139 | . " SET ED_DTLOT = ?, ED_SEQLOT = ?, ED_DTPOSTE = ?, ED_STATUS = ? "; | ||
| 140 | |||
| 141 | #my $updt = "UPDATE EDTK_INDEX SET ED_DTLOT = ?, ED_SEQLOT = ?, ED_DTPOSTE = ?, ED_STATUS = ? "; | ||
| 142 | $sth = $dbh->prepare( $updt . $where ); | ||
| 143 | |||
| 144 | if ( $event !~ /^RESET$/i && $event !~ /^STOP$/i ) { | ||
| 145 | |||
| 146 | # for all other events the docs are not replayed; they will be purged (index_Purge_DCLIB) | ||
| 147 | # warn "INFO: $updt \n $event, $event, $event, $event, @values\n"; | ||
| 148 | $sth->execute( $event, $event, $event, $event, @values ); | ||
| 149 | |||
| 150 | } | ||
| 151 | else { | ||
| 152 | my $NULL = ""; | ||
| 153 | |||
| 154 | # warn "INFO: $updt \n $NULL, $NULL, $NULL, $event, @values\n"; | ||
| 155 | $sth->execute( $NULL, $NULL, $NULL, $event, @values ); | ||
| 156 | } | ||
| 157 | |||
| 158 | # REVIEW THE TRACKING: SET A REAL TIMESTAMP, THE RIGHT ED_APP | ||
| 159 | $sql = | ||
| 160 | "INSERT INTO EDTK_TRACKING(ED_TSTAMP, ED_USER, ED_SEQ, ED_SNGL_ID, ED_APP, ED_JOB_EVT, ED_OBJ_COUNT, ED_CORP, ED_HOST, ED_K4_VAL) "; | ||
| 161 | $sql .= " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; | ||
| 162 | my $trk = $dbh->prepare($sql); | ||
| 163 | $trk->execute( | ||
| 164 | '20111003111111', 'idx_Block', $sequence, $key1, | ||
| 165 | 'idx_Block', 'W', $row_count, $cfg->{'EDTK_CORP'}, | ||
| 166 | hostname(), "$event for @values" | ||
| 167 | ); | ||
| 168 | |||
| 169 | print "DONE "; | ||
| 170 | ################################################################################ | ||
| 171 | |||
| 172 | 1; |