blib/lib/oEdtk/trackEdtk.pm

filter: Statementstmt 66.6% 4 / 6 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 75.0% 6 / 8 CC 1 SCAR 1.4
CC
1
Cov
67%
BEGIN
1.3
BEGIN
1.0
CRAP 1.1
« blib/lib/oEdtk/dataEdtk.pm ↑ Summary blib/lib/oEdtk/Spool.pm »
1 package oEdtk::trackEdtk;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 BEGIN {
6 2 ▶ use oEdtk::Main;
Subroutine BEGIN: called CC=1 SCAR=2.6
7 use Config::IniFiles;
8 use Sys::Hostname;
9 use Digest::MD5 qw(md5_base64);
10 use DBI;
11 use Cwd qw(abs_path);
12  
13 use Exporter;
14 use vars qw($VERSION @ISA @EXPORT_OK); # @EXPORT %EXPORT_TAGS);
15  
16 $VERSION = 2.1126; # eventually this library should be taken over by oEdtk::Tracking
17 @ISA = qw(Exporter);
18  
19 # @EXPORT = qw(
20 # );
21  
22 @EXPORT_OK = qw(
23 ini_Edtk_Conf conf_To_Env
24 env_Var_Completion
25  
26 init_Tracking track_Obj
27 define_Mod_Ed define_Job_Evt
28 define_Track_Key
29  
30 edit_Track_Table
31 create_Track_Table prepare_Tracking_Env
32 drop_Track_Table
33 );
34  
35 }
36  
37 # 3 possible ways to feed it (config edtk.ini -> EDTK_TRACK_MODE):
38 # -1- DB : tracking directly in a DBMS (DB) -> slows down the production run (insert the tracking info at the end of the run to limit the impact => END of the module?)
39 # -2- FDB : tracking through SQLite -> no handling of several real-time accesses => create 1 db file per process (procDB) -> organize a data consolidation
40 # -3- LOG : flat tracking files -> organize a data consolidation
41 #
42 # ? TODO: bug in the dynamic creation of the SQLite file, TSTAMP/PROCESS_ID is not used ???
43  
44 my $DBI_DNS = "";
45 my $DBI_USER = "";
46 my $DBI_PASS = "";
47 my $TABLENAME = "tracking_oEdtk";
48  
49 my $ED_HOST = "";
50 my $ED_TSTAMP = "";
51 my $ED_PROC = "";
52 my $ED_SNGL_ID = "";
53 my $ED_USER = "";
54 my $ED_SEQ = "";
55 my $ED_APP = "";
56 my $ED_MOD_ED = "";
57 my $ED_JOB_EVT = "";
58 my $ED_OBJS = "";
59 my @ED_K_NAME;
60 my @ED_K_VAL;
61  
62 my @TRACKED_OBJ;
63 my @DB_USER_COL;
64  
65 my $NOK = -1;
66  
67 sub ini_Edtk_Conf {
68  
69 # look for the configuration file
70 # return the path to the valid configuration file
71 my $iniEdtk = $INC{'oEdtk/trackEdtk.pm'};
72 $iniEdtk =~ s/(trackEdtk\.pm)//;
73 $iniEdtk .= "iniEdtk/edtk.ini";
74 my $hostname = uc( hostname() );
75  
76 # OPEN THE CONFIGURATION FILE
77 my $tmpIniEdtk = $iniEdtk;
78 my $confIni;
79 while ( $tmpIniEdtk ne 'local' ) {
80 if ( !( -e $tmpIniEdtk ) ) { die "ERR. config file not found : $tmpIniEdtk\n"; }
81 $confIni = Config::IniFiles->new( -file => $tmpIniEdtk, -default => 'DEFAULT' );
82  
83 $iniEdtk = $tmpIniEdtk;
84  
85 # look for the iniEdtk variable in the '$hostname' section, or by default
86 # in the 'DEFAULT' section (see the new method)
87 $tmpIniEdtk = $confIni->val( $hostname, 'iniEdtk' );
88  
89 # if iniEdtk == current file then set the value to local (avoid infinite loops)
90 if ( $tmpIniEdtk eq $iniEdtk ) { last; }
91 }
92  
93 $ENV{EDTK_INIEDTK} = $iniEdtk;
94 return $iniEdtk;
95 }
96  
97 sub conf_To_Env {
98  
99 # load the requested sections of the config file into the environment configuration
100 # as parameters, pass the path to the ini file + the section to load
101 # if the HOSTNAME section exists it overrides the values from the section
102 my $confIni = shift;
103 my $section = shift;
104 $section ||= 'DEFAULT';
105  
106 our ( %hSpecific, %hConfig ); # package-scoped configuration hashes
107  
108 if ( -e $confIni ) {
109 }
110 else {
111 die "ERR. config file not found : $confIni\n";
112 }
113  
114 my $hostname = uc( hostname() );
115  
116 # OPEN THE CONFIGURATION FILE
117 my %hConfIni;
118 tie %hConfIni, 'Config::IniFiles', ( -file => $confIni );
119  
120 # LOAD THE VALUES FROM THE SECTION
121 my %hSection;
122 if ( exists $hConfIni{$section} ) {
123 %hSection = %{ $hConfIni{$section} };
124 }
125  
126 # LOAD THE HOSTNAME-SPECIFIC VALUES AS OVERRIDES
127 my %hHostname;
128 if ( exists $hConfIni{$hostname} ) {
129 undef %hSpecific;
130 %hHostname = %{ $hConfIni{$hostname} };
131 }
132 else {
133 warn "INFO machine '$hostname' unknown in the configuration";
134 }
135 %hConfig = ( %hSection, %hHostname );
136  
137 my $self = abs_path($0);
138 $self =~ /([\w\.\-]+)[\/\\]\w+\.\w+$/;
139  
140 # DEFINITION FOR THE DEV ENVIRONMENT OF THE CURRENT APPLICATION/PROGRAM
141 $hConfig{'EDTK_PRGNAME'} = $1;
142  
143 #$hConfig{'EDTK_OPTJOB'} =$EDTK_OPTJOB;
144  
145 # set up the environment variables
146 while ( ( my $cle, my $valeur ) = each(%hConfig) ) {
147 $valeur ||= "";
148 $ENV{$cle} = $valeur;
149 }
150 1;
151 }
152  
153 sub env_Var_Completion (\$) { ## no critic (ProhibitSubroutinePrototypes)
154  
155 # expand the paths, replacing the environment variables with their real values
156 # every nesting level defined in the environment variables is expanded
157 # requires the environment variables to be defined beforehand
158 my $rScript = shift;
159  
160 # there may be variables within the environment variables themselves
161 while ( ${$rScript} =~ /\$/g ) {
162 ${$rScript} =~ s/\$(\w+)/${ENV{$1}}/g;
163 }
164 ${$rScript} =~ s/(\/)/\\/g;
165 1;
166 }
167  
168 ################################################################################
169 # PRODUCTION TRACKING DEFINITION SECTION
170 #
171 #
172 my $DBH;
173 my %h_subInsert;
174 my %h_subCreate; # referenced by the mode check below; left empty on purpose
175  
176 # define the insertion method
177 $h_subInsert{'LOG'} = \&subInsert_Log;
178 $h_subInsert{'DB'} = \&subInsert_DB;
179 $h_subInsert{'FDB'} = \&subInsert_DB;
180 $h_subInsert{'none'} = \&noSub;
181  
182 my %h_subClose;
183 $h_subClose{'DB'} = \&subClose_DB;
184 $h_subClose{'FDB'} = \&subClose_DB;
185  
186 sub prepare_Tracking_Env() {
187 my $iniEdtk = ini_Edtk_Conf();
188 conf_To_Env( $iniEdtk, 'ENVDESC' );
189 conf_To_Env( $iniEdtk, 'EDTK_DB' );
190 oe_uc_sans_accents( $ENV{EDTK_TRACK_MODE} );
191  
192 1;
193 }
194  
195 sub open_Tracking_Env() {
196 if ( $ENV{EDTK_TRACK_MODE} =~ /FDB/i ) {
197  
198 # DB FILE oe_now_time/PROCESS
199 $ENV{EDTK_DBI_DNS} =~ s/(.+)\.(\w+)$/$1\.$ED_TSTAMP\.$ED_PROC\.$2/;
200 warn "INFO tracking to $ENV{EDTK_DBI_DSN}\n";
201 create_Track_Table( $ENV{EDTK_DBI_DSN} );
202 open_DBI();
203  
204 }
205 elsif ( $ENV{EDTK_TRACK_MODE} =~ /LOG/i ) {
206  
207 # log
208  
209 }
210 elsif ( $ENV{EDTK_TRACK_MODE} =~ /DB/i ) {
211  
212 # DB connection tracking
213 open_DBI();
214  
215 }
216 else {
217 $ENV{EDTK_TRACK_MODE} = "none";
218  
219 }
220  
221 if ( !( $h_subInsert{ $ENV{EDTK_TRACK_MODE} } ) && !( $h_subCreate{ $ENV{EDTK_TRACK_MODE} } ) )
222 {
223 warn "INFO $ENV{EDTK_TRACK_MODE} undefined - tracking halted\n";
224 $ENV{EDTK_TRACK_MODE} = "none";
225 }
226  
227 1;
228 }
229  
230 sub open_DBI() {
231 my $dbargs = {
232 AutoCommit => $ENV{EDTK_DBI_AutoCommit},
233 RaiseError => $ENV{EDTK_DBI_RaiseError},
234 PrintError => $ENV{EDTK_DBI_PrintError}
235 };
236  
237 $DBH = DBI->connect(
238 $ENV{EDTK_DBI_DSN},
239 $ENV{EDTK_DBI_DSN_USER},
240 $ENV{EDTK_DBI_DSN_PASS}
241  
242 # ,$dbargs
243 ) or die "ERR no connection to $ENV{EDTK_DBI_DSN} " . DBI->errstr;
244  
245 1;
246 }
247  
248 sub init_Tracking {
249 my $Mod_Ed = shift;
250 my $Typ_Job = shift;
251 my $Job_User = shift;
252 my @Track_Key = @_;
253 define_Mod_Ed($Mod_Ed); # U(ndef) by default
254 define_Job_Evt($Typ_Job); # S(pool) by default
255 define_Job_User($Job_User); # user job request, by default 'None'
256 $ED_HOST = hostname();
257 $ED_TSTAMP = oe_now_time();
258 $ED_PROC = $$;
259 $ED_SEQ = 0; # (dynamic, private)
260 $ED_SNGL_ID = md5_base64( $ED_HOST . $ED_TSTAMP . $ED_PROC );
261  
262 &prepare_Tracking_Env();
263 &open_Tracking_Env();
264  
265 my $indice = 0;
266 foreach my $element (@Track_Key) {
267 define_Track_Key( $element, $indice++ ); # default key for indiced col_name
268 }
269  
270 $0 =~ /([\w-]+)[\.plmex]*$/;
271 $1 ? $ED_APP = "application" : $ED_APP = $1;
272  
273 $ED_OBJS = 1; ## default insert unit count (dynamic)
274  
275 warn
276 "INFO tracking init ( track mode : $ENV{EDTK_TRACK_MODE}, edition mode : $ED_MOD_ED, job type : $ED_JOB_EVT, user : $ED_USER, optional Keys : @ED_K_NAME )\n";
277  
278 return $ED_SNGL_ID;
279 }
280  
281 sub track_Obj {
282  
283 # track_Obj ([$ED_OBJS, $ED_JOB_EVT, @ED_K_VAL])
284 # $ED_OBJS (optional) : number of units of the object (1 by default)
285 # $ED_JOB_EVT (optional) : event in question (see define_Job_Evt)
286 # @ED_K_VAL (optional) : values of the optional keys defined with init_Tracking (same order)
287  
288 $ED_SEQ++;
289 $ED_OBJS = shift;
290 $ED_OBJS ||= 1;
291 define_Job_Evt(shift);
292 @ED_K_VAL = @_;
293  
294 undef @TRACKED_OBJ;
295 push( @TRACKED_OBJ, oe_now_time() );
296 push( @TRACKED_OBJ, $ED_USER );
297 push( @TRACKED_OBJ, $ED_SEQ );
298 push( @TRACKED_OBJ, $ED_SNGL_ID );
299 push( @TRACKED_OBJ, $ED_APP );
300 push( @TRACKED_OBJ, $ED_MOD_ED );
301  
302 push( @TRACKED_OBJ, $ED_JOB_EVT );
303 push( @TRACKED_OBJ, $ED_OBJS );
304 undef @DB_USER_COL;
305 for ( my $i = 0 ; $i <= $#ED_K_VAL ; $i++ ) {
306 push( @TRACKED_OBJ, $ED_K_NAME[$i] || "" );
307 push( @TRACKED_OBJ, $ED_K_VAL[$i] || "" );
308 push( @DB_USER_COL, "ED_K${i}_NAME" );
309 push( @DB_USER_COL, "ED_K${i}_VAL" );
310 }
311  
312 &{ $h_subInsert{ $ENV{EDTK_TRACK_MODE} } }
313 or die "ERR. undefined EDTK_TRACK_MODE -> $ENV{EDTK_TRACK_MODE}\n";
314 1;
315 }
316  
317 sub define_Mod_Ed {
318  
319 # Printing Mode : looking for one of the following :
320 # Undef (default), Batch, Tp, Web, Mail
321 my $value = shift;
322  
323 if ($value) { $ED_MOD_ED = $value }
324 $ED_MOD_ED =~ /([NBTWM])/;
325 $ED_MOD_ED = $1;
326 $ED_MOD_ED ||= "U"; # Undef by default
327  
328 return $ED_MOD_ED;
329 }
330  
331 sub define_Job_Evt {
332  
333 # Job Event : looking for one of the following :
334 # Job (default), Spool, Document, Line, Warning, Error, Halt (critic), Reject
335 my $value = shift;
336  
337 if ($value) { $ED_JOB_EVT = $value }
338 $ED_JOB_EVT =~ /([JSDLWEHR])/;
339 $ED_JOB_EVT = $1;
340 $ED_JOB_EVT ||= "J"; # Job by default
341  
342 return $ED_JOB_EVT;
343 }
344  
345 sub define_Job_User {
346  
347 # USER JOB REQUEST : LOOKING FOR ONE OF THE FOLLOWING :
348 # None (default), user Id (max 10 alphanumerics)
349 my $value = shift;
350  
351 if ( $value =~ /(\w{1,10})/ ) {
352 $ED_USER = $1;
353 }
354 else {
355 $ED_USER = "None";
356 }
357  
358 return $ED_USER;
359 }
360  
361 sub define_Track_Key {
362  
363 # TO DEFINE THE COL_NAME OF THE N INDICED TRACKING KEY
364 my $value = shift;
365 my $indice = shift;
366 $indice ||= 0;
367  
368 if ( !defined $ENV{EDTK_MAX_USER_KEY} ) {
369 warn "INFO: tracking key undefined\n";
370 return 0;
371  
372 }
373 elsif ( $indice gt( $ENV{EDTK_MAX_USER_KEY} - 1 ) ) {
374 warn "INFO: tracking key not allowed (limit is $ENV{EDTK_MAX_USER_KEY})\n";
375 return 0;
376  
377 }
378 elsif ( length($value) > 5 ) {
379 $value =~ s/^(\w{5})(.*)/$1/;
380 warn "INFO: redefined col as '$value'";
381 }
382 if ($value) { $ED_K_NAME[$indice] = $value; }
383  
384 $ED_K_NAME[$indice] =~ s/\s/\_/g;
385 oe_uc_sans_accents( $ED_K_NAME[$indice] );
386  
387 return $ED_K_NAME[$indice];
388 }
389  
390 sub subInsert_Log() {
391  
392 # WHEN TRACKING IS DONE THROUGH LOG FILES
393 # TODO complete with the use of the Logger replacement
394  
395 my $request = join( ", ", @TRACKED_OBJ );
396 warn "$request\n";
397  
398 1;
399 }
400  
401 sub subInsert_DB() {
402  
403 # build the SQL command to insert into a DBI database (file/DB)
404  
405 my $request = "insert into $ENV{EDTK_DBI_TRACKING}";
406 $request .= " (";
407 $request .=
408 "ED_TSTAMP, ED_USER, ED_SEQ, ED_SNGL_ID, ED_APP, ED_MOD_ED, ED_JOB_EVT, ED_OBJ_COUNT";
409 if (@DB_USER_COL) {
410 $request .= ", ";
411 $request .= join( ", ", @DB_USER_COL );
412 }
413 $request .= " ) values ('";
414  
415 # DATE FORMATTING FOR THE DBMS
416 # $request .=sprintf ("to_date('%014.f', 'YYYYMMDDHH24MISS'), '", shift @TRACKED_OBJ);
417 $request .= join( "', '", @TRACKED_OBJ );
418 $request .= "')";
419  
420 $DBH->do($request);
421 if ( $DBH->err() ) {
422 warn "INFO " . $DBI::errstr . "\n";
423 }
424  
425 # $DBH->commit(); # needed when AutoCommit is 0
426 # $DBH->disconnect();
427 # if ($DBH->err()) { warn "$DBI::errstr\n"; }
428 1;
429 }
430  
431 sub noSub() {
432  
433 # EMPTY FUNCTION FOR THE %H_SUBINSERT FUNCTION POINTERS
434 # to avoid using tests in repetitive functions
435 # (fake switch/case)
436 return 1;
437 }
438  
439 sub test_exist_table() {
440 my $dbargs = {
441 AutoCommit => $ENV{EDTK_DBI_AutoCommit},
442 RaiseError => $ENV{EDTK_DBI_RaiseError},
443 PrintError => $ENV{EDTK_DBI_PrintError}
444 };
445 $DBH =
446 DBI->connect( $ENV{EDTK_DBI_DSN}, $ENV{EDTK_DBI_DSN_USER},
447 $ENV{EDTK_DBI_DSN_PASS}, $dbargs )
448 or die "ERR no connection to $ENV{EDTK_DBI_DSN} " . DBI->errstr;
449  
450 my $request = "select * from $ENV{EDTK_DBI_TABLENAME}";
451  
452 $DBH->do($request);
453 if ($DBI::errstr) {
454 if ( $DBI::errstr =~ /no such table/ ) {
455 $DBH->disconnect();
456 return 0;
457 }
458 warn "INFO " . $DBI::errstr . "\n";
459 $DBH->disconnect();
460 return $NOK;
461 }
462 $DBH->disconnect();
463  
464 1;
465 }
466  
467 sub edit_Track_Table {
468 my $request = shift;
469  
470 &open_DBI();
471  
472 my $ref_Tab = &fetchall_DBI($request);
473 &edit_All_rTab($ref_Tab);
474 1;
475 }
476  
477 sub create_Track_Table() {
478  
479 #my $dbi_dns=shift;
480  
481 # CREATE TABLE tablename [IF NOT EXISTS][TEMPORARY] (column1data_type, column2data_type, column3data_type);
482 #&prepare_Tracking_Env();
483 #$dbi_dns ||=$ENV{EDTK_DBI_DNS};
484  
485 my $dbargs = {
486 AutoCommit => 0,
487 RaiseError => 0,
488 PrintError => 0
489 };
490 $DBH =
491 DBI->connect( $ENV{EDTK_DBI_DSN}, $ENV{EDTK_DBI_DSN_USER}, $ENV{EDTK_DBI_DSN_PASS},
492 $dbargs )
493 or die "ERR no connection to $ENV{EDTK_DBI_DSN} " . DBI->errstr;
494  
495 my $struct = "CREATE TABLE $ENV{EDTK_DBI_TABLENAME} ";
496 $struct .=
497 "( ED_TSTAMP NUMBER(14) NOT NULL"; # interesting for formated date and interval search
498  
499 # $struct .="( ED_TSTAMP VARCHAR2(14) NOT NULL"; # most used
500 # $struct .="( ED_TSTAMP DATE NOT NULL"; # Not compatible
501 # $struct .=", ED_HOST VARCHAR2(15) NOT NULL"; # hostname
502 # $struct .=", ED_PROC VARCHAR2(6) NOT NULL"; # process
503 $struct .= ", ED_USER VARCHAR2(10) NOT NULL"; # job request user
504 $struct .= ", ED_SEQ NUMBER(9) NOT NULL"; # sequence
505 $struct .= ", ED_SNGL_ID VARCHAR2(22) NOT NULL"; # Single ID
506 $struct .= ", ED_APP VARCHAR2(15) NOT NULL"; # application name
507 $struct .= ", ED_MOD_ED CHAR"; # edition mode (Batch, Tp, Web, Mail)
508 $struct .=
509 ", ED_JOB_EVT CHAR"; # event level within the job (Spool, Document, Line, Warning, Error)
510 $struct .= ", ED_OBJ_COUNT NUMBER(15)"; # number of elements/objects attached to the event
511  
512 for ( my $i = 0 ; $i lt $ENV{EDTK_MAX_USER_KEY} ; $i++ ) {
513 $struct .= ", ED_K${i}_NAME VARCHAR2(5)"; # key name $i
514 $struct .= ", ED_K${i}_VAL VARCHAR2(30)"; # key value $i
515 }
516 $struct .=
517 ")"; #, CONSTRAINT pk_$ENV{EDTK_DBI_TABLENAME} PRIMARY KEY (ED_TSTAMP, ED_PROC, ED_SEQ)";
518  
519 $DBH->do($struct);
520 if ($DBI::errstr) {
521 warn "INFO " . $DBI::errstr . "\n";
522 }
523  
524 # my $seq ="CREATE SEQUENCE sq_$TABLENAME
525 # MINVALUE 1
526 # MAXVALUE 999999999
527 # START WITH 1
528 # INCREMENT BY 1;";
529 #$dbh->do("$seq");
530  
531 $DBH->commit(); # needed when AutoCommit is 0
532 $DBH->disconnect();
533 1;
534 }
535  
536 sub drop_Track_Table() {
537 &prepare_Tracking_Env();
538 &open_DBI();
539  
540 warn "=> Drop table $ENV{EDTK_DBI_TABLENAME} from $ENV{EDTK_DBI_DSN}, if exist\n\n";
541 $DBH->do("DROP TABLE $ENV{EDTK_DBI_TABLENAME}");
542 $DBH->disconnect;
543  
544 1;
545 }
546  
547 sub fetchall_DBI {
548  
549 # CONNECT TO A DBI TABLE TO SELECT INTO AN ARRAY REFERENCE
550 # select all the data matching a criterion
551 # option: query to pass, example "SELECT * FROM TRACKING_OEDTK WHERE ED_MOD_ED = 'T'"
552 # by default it is 'SELECT * from $ENV{EDTK_DBI_TABLENAME}'
553 my $request = shift;
554 $request ||= "SELECT * from $ENV{EDTK_DBI_TABLENAME}";
555  
556 my $sql = qq($request);
557 my $sth = $DBH->prepare($sql);
558 $sth->execute()
559 || warn "ERR. DBI exec " . $DBH->errstr;
560  
561 my $rTab = $sth->fetchall_arrayref;
562  
563 $sth->{Active} = 1
564 ; # fix for the SQLite bug "closing dbh with active statement" http://rt.cpan.org/Public/Bug/Display.html?id=9643
565 $sth->finish();
566  
567 #$DBH->commit(); # needed when AutoCommit is 0 ???
568 if ($DBI::errstr) {
569 warn $DBI::errstr . "\n";
570 }
571  
572 return $rTab;
573 }
574  
575 sub edit_All_rTab {
576  
577 # PRINT ALL THE DATA OF AN ARRAY PASSED BY REFERENCE
578 # display the array in columns
579 my $rTab = shift;
580  
581 for ( my $i = 0 ; $i <= $#{$rTab} ; $i++ ) {
582 my $cols = $#{ $$rTab[$i] };
583 print "\n$i:\t";
584  
585 for ( my $j = 0 ; $j <= $cols ; $j++ ) {
586 print "$$rTab[$i][$j]" if ( defined $$rTab[$i][$j] );
587 }
588 }
589 print "\n";
590  
591 1;
592 }
593  
594 sub subClose_DB() {
595 $DBH->commit() if ( $ENV{EDTK_DBI_AutoCommit} eq 0 ); # needed when AutoCommit is 0
596  
597 # $DBH->disconnect();
598 1;
599 }
600  
601 END {
602 if ( exists $h_subClose{EDTK_TRACK_MODE} ) {
603 &{ $h_subClose{ $ENV{EDTK_TRACK_MODE} } };
604 }
605 }
606 1;
607  
608 =head1 NAME
609  
610 oEdtk::trackEdtk - production tracking: configuration, environment and insert
611  
612 =head1 SYNOPSIS
613  
614 use oEdtk::trackEdtk qw(init_Tracking track_Obj);
615  
616 init_Tracking($mod_ed, $job_evt, $job_user, @keys);
617 # ... run the job ...
618 track_Obj($count, $job_evt, @key_values);
619  
620 =head1 DESCRIPTION
621  
622 Legacy production-tracking helper. It locates and loads the site configuration
623 into C<%ENV>, then records tracking events either in a database (C<DB>), in a
624 per-process SQLite file (C<FDB>) or in flat log files (C<LOG>), following
625 C<EDTK_TRACK_MODE>. L<oEdtk::Tracking> is its object-oriented successor; this
626 library is meant to be taken over by it.
627  
628 =head1 FUNCTIONS
629  
630 =head2 ini_Edtk_Conf
631  
632 my $ini = ini_Edtk_Conf();
633  
634 Locate and return the valid configuration file, following the C<iniEdtk> chain
635 declared in the hostname section, and set C<$ENV{EDTK_INIEDTK}>.
636  
637 =head2 conf_To_Env
638  
639 conf_To_Env($confIni, $section);
640  
641 Load a section of the configuration file into C<%ENV>, with the hostname section
642 overriding the section values when it exists.
643  
644 =head2 env_Var_Completion
645  
646 env_Var_Completion(\$script);
647  
648 Expand the environment variables nested inside C<$script>, level by level, until
649 none remains.
650  
651 =head2 init_Tracking
652  
653 my $single_id = init_Tracking($mod_ed, $job_evt, $job_user, @keys);
654  
655 Initialise the tracking environment: define the edition mode, the job event and
656 the user, then the optional keys, and return the single identifier of the run.
657  
658 =head2 track_Obj
659  
660 track_Obj($count, $job_evt, @key_values);
661  
662 Record one tracked object with the current settings. C<$count> defaults to one,
663 and the optional key values follow the order given to L</init_Tracking>.
664  
665 =head2 define_Mod_Ed
666  
667 my $code = define_Mod_Ed($value);
668  
669 Set the edition mode (Undef, Batch, Tp, Web or Mail) and return its one-letter
670 code (C<U> by default).
671  
672 =head2 define_Job_Evt
673  
674 my $code = define_Job_Evt($value);
675  
676 Set the job event (Job, Spool, Document, Line, Warning, Error, Halt or Reject)
677 and return its one-letter code (C<J> by default).
678  
679 =head2 define_Track_Key
680  
681 my $name = define_Track_Key($value, $index);
682  
683 Define the column name of the C<$index>-th optional tracking key. The name is
684 truncated to five characters and upper-cased without accents, and refused when
685 the index exceeds C<EDTK_MAX_USER_KEY>.
686  
687 =head2 edit_Track_Table
688  
689 edit_Track_Table($request);
690  
691 Run a C<SELECT> against the tracking table and display the resulting rows.
692  
693 =head2 create_Track_Table
694  
695 create_Track_Table();
696  
697 Create the tracking table for the current DSN, with one name/value column pair
698 per configured user key.
699  
700 =head2 prepare_Tracking_Env
701  
702 prepare_Tracking_Env();
703  
704 Load the tracking configuration and normalise the tracking mode.
705  
706 =head2 drop_Track_Table
707  
708 drop_Track_Table();
709  
710 Drop the tracking table for the current DSN, if it exists.
711  
712 The following subs are internal helpers and are not part of the public API:
713 C<open_Tracking_Env>, C<open_DBI>, C<define_Job_User>, C<subInsert_Log>,
714 C<subInsert_DB>, C<noSub>, C<test_exist_table>, C<fetchall_DBI>,
715 C<edit_All_rTab> and C<subClose_DB>.
716  
717 =head1 AUTHOR
718  
719 The oEdtk team.
720  
721 =cut
722  
723 # NOTES
724 #
725 # LIST OF TABLES
726 # select table_name from tabs;
727 #
728 # List the tables of the current user's schema:
729 # SELECT table_name FROM user_tables;
730 #
731 # List the tables accessible by the user:
732 # SELECT table_name FROM all_tables;
733 #
734 # List all the tables (ADMIN is required):
735 # SELECT table_name FROM dba_tables;
736 #
737 # TABLE DESCRIPTION:
738 # desc my_table; # returns the fields and their types
739  
740 # EXAMPLE QUERIES - http://fadace.developpez.com/sgbdcmp/fonctions/
741 #
742 # SELECT * FROM TRACKING_OEDTK WHERE ED_JOB_EVT='S';
743 # SELECT * FROM TRACKING_OEDTK WHERE ED_MOD_ED='T';
744 # SELECT SUM(ED_OBJ_COUNT) AS "OBJECTS" FROM TRACKING_OEDTK WHERE ED_JOB_EVT='D';
745 # SELECT COUNT(ED_OBJ_COUNT) AS "OBJECTS" FROM TRACKING_OEDTK WHERE ED_JOB_EVT='D';
746 # SELECT DISTINCT ED_SNGL_ID FROM TRACKING_OEDTK;
747 # SELECT COUNT (DISTINCT ED_SNGL_ID) FROM TRACKING_OEDTK ;
748 # SELECT COUNT (DISTINCT ED_SNGL_ID) FROM TRACKING_OEDTK WHERE ED_JOB_EVT='D';
749 # SELECT COUNT (DISTINCT ED_SNGL_ID) AS "TOTAL" FROM TRACKING_OEDTK WHERE ED_JOB_EVT='D' AND ED_MOD_ED='T';
750 # SELECT ED_TSTAMP, ED_APP, ED_SNGL_ID FROM TRACKING_OEDTK WHERE ED_MOD_ED='T' AND ED_JOB_EVT='S';
751 # SELECT to_char(ED_TSTAMP, 'DD/MM/YYYY HH24:MM:SS'), ED_APP, ED_SNGL_ID FROM TRACKING_OEDTK WHERE ED_MOD_ED='T' AND ED_JOB_EVT='S';
752 # SELECT to_char(ED_TSTAMP, 'DD/MM/YYYY HH24:MM:SS') AS TIME , ED_APP, ED_SNGL_ID FROM TRACKING_OEDTK WHERE ED_MOD_ED='B' AND ED_JOB_EVT='S';
753  
754 # update EDTK_FILIERES SET ed_postcomp =2020 where ed_postcomp<>'FilR100';
755  
756 #
757 # END
« blib/lib/oEdtk/dataEdtk.pm ↑ Summary blib/lib/oEdtk/Spool.pm »