Ignore:
Timestamp:
2018-11-09T22:33:51+13:00 (5 years ago)
Author:
ak19
Message:

Major tidying up: last remaining debug statements, lots of comments, removed TODO lists.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm

    r32592 r32595  
    3939
    4040
    41 # + TODO: SIGTERM rollback and disconnect?
    42 # + TODO Q: what about verbosity for debugging, instead of current situation of printing out upon debug set at the expense of writing to db
    43 #+ TODO Q: introduced site param to plugins and plugouts. Did I do it right? And should they have hiddengli = "yes". No longer a param
    44 # !!!! Did I do the pass by ref in docprint's escape and unescape textref functions correctly, and how they're called here?
    45 #   Any more optimisation I can do around this?
    46 
    47 # this plugout does not output the metadata and/or fulltxt xml to a file,
    48 # but outputs rows into a mysql table for metadata and/or a table for fulltxt
     41# This plugout does not output the metadata and/or fulltxt xml to a file,
     42# but outputs rows into a MySQL db table for metadata and/or a db table for fulltxt
     43
    4944sub BEGIN {
    5045    @GreenstoneSQLPlugout::ISA = ('GreenstoneXMLPlugout');
    5146}
    5247
    53 # + NOTTODO: die() statements need to be replaced with premature_termination
    54 # which should ensure the GreenstoneXMLPlugin (group)'s stuff is closed and cleaned up SOMEHOW
    55 # It's fine: the die() stmts all take place before setting up the super class' begin
    56 
    57 # + TODO Q: about build_mode: how to detect removeold. Now handled by
    58 #   GreenstoneSQLPlugout::remove_all(), which is inherited from a base plugin.
    59 # + TODO: deal with -removeold and everything? Or type out instructions for user
    60 
    61 # + TODO Q: what is "group" in GreenstoneXMLPlugout?
    6248
    6349my $process_mode_list =
     
    141127        return bless $self, $class;
    142128    }
    143     #print STDERR "***** GreenstoneSQLPlugout process mode = \"", $self->{'process_mode'}, "\"\n";
    144129   
    145130    return bless $self, $class;
     
    151136    my $self= shift (@_);
    152137   
    153     # The saveas.options
    154     #print STDERR "@@@@ PLUGOUT db_pwd: " . $self->{'db_client_pwd'} . "\n";
    155     #print STDERR "@@@@ user: " . $self->{'db_client_user'} . "\n";
    156     #print STDERR "@@@@ db_host: " . $self->{'db_host'} . "\n";
    157     #print STDERR "@@@@ db_driver: " . $self->{'db_driver'} . "\n";
    158     #print STDERR "@@@@ proc_mode: " . $self->{'process_mode'} . "\n";
    159 
    160     ############ LOAD NECESSARY OPTIONS ###########
    161     #print "@@@ plugout SITE NAME: ". $self->{'site'} . "\n" if defined $self->{'site'};
    162     #print STDERR "########## COLLECTION: ". $ENV{'GSDLCOLLECTION'}."\n";
    163 
    164     print STDERR "***** GreenstoneSQLPlugout process mode = \"", $self->{'process_mode'}, "\"\n";
    165 
    166138    my $db_params = {
    167139    'collection_name' => $ENV{'GSDLCOLLECTION'},
     
    192164    }
    193165
    194     #die("@@@@ TEST. Connected successfully. Testing gsmysql::destructor.\n"); # WORKS
    195    
    196166    my $db_name = $self->{'site'} || "greenstone2"; # one database per GS3 site, for GS2 the db is called greenstone2
    197167    my $proc_mode = $self->{'process_mode'};
     
    201171   
    202172    if($success && $proc_mode ne "text_only") {
    203     ##print STDERR "@@@@ Ensuring meta table exists\n";
    204173    $success = $gs_sql->ensure_meta_table_exists();
    205174    }   
    206175    if($success && $proc_mode ne "meta_only") {
    207     ##print STDERR "@@@@ Ensuring fulltxt table exists\n";
    208176    $success = $gs_sql->ensure_fulltxt_table_exists();
    209177    }
     
    213181    # PrintError would already have displayed the warning message on load fail
    214182    # And on die() perl will call gsmysql destroy which will ensure a disconnect() from db
    215     #$gs_sql->force_disconnect_from_db(); # disconnect_from_db() will issue a warning on error
    216183    die("Could not use db $db_name and/or prepare its tables. Can't proceed.\n");
    217184    }
     
    221188   
    222189   
    223     # if setting up to work with sql db failed, we'd have terminated and wouldn't come up to here:
    224     # won't bother preparing GreenstoneXMLPlugout by calling superclass' begin()
    225     # finally, can call begin on super - important as doc.xml is opened as a group etc
     190    # If setting up connection to sql db failed, we'd have terminated and wouldn't come up to here
     191    # and wouldn't have bothered preparing GreenstoneXMLPlugout by calling superclass' begin().
     192    # Finally, can call begin on super - important as doc.xml is opened as a group etc
    226193   
    227194    $self->SUPER::begin(@_);
     
    261228}
    262229 
    263 # + X TODO: check arc-inf.db for whether each entry is to be deleted/indexed/reindexed/been indexed?
    264 # That's only for indexing, not for this step which only generates the content in archives dir
     230# saveas() only generates the content in archives dir and in the SQL database
    265231sub saveas {
    266232    my $self = shift (@_);
     
    276242    $self->{'debug_outhandle'} = $docxml_outhandler if ($self->{'debug'}); # STDOUT if debug
    277243
    278     # TODO: also set debugging in begin()? Then stmts creating db and tables also sent to debug out and not executed
    279    
    280    
    281244    # 2. overriding saving behaviour to do what the superclass does (writing out doc.xml files,
    282245    # under new name of docsql.xml, with breadcrumbs pointing to sql db) PLUS saving to sql db   
     
    308271   
    309272   
    310     # database connection is closed in end() method
    311     # so we don't open and close over and over for each doc during a single build
     273    # database connection is closed once, in end() method
     274    # We're not opening and closing over and over for each doc during a single build
    312275}
    313276
     
    324287}
    325288
    326 # Perl: Reading or Writing to Another Program
    327 # https://nnc3.com/mags/Perl3/cookbook/ch16_05.htm
    328289sub recursive_write_meta_and_text {
    329290    my $self = shift (@_);
     
    345306    foreach my $data (@{$section_ptr->{'metadata'}}) {
    346307        my $meta_name = $data->[0];
    347         # TODO: does it need to be stored escaped, as it requires unescaping when read back in
    348         # from db (unlike for reading back in from doc.xml)
    349308
    350309        # Treat db like a text file instead of an html/xml file: don't need to escape text
    351         # going into it
    352         #my $escaped_meta_value = &docprint::escape_text($data->[1]);
     310        # going into it, unlike with doc(sql).xml
    353311        my $meta_value = $data->[1];
    354312       
     
    359317        # filling in the values
    360318        # OR if debugging, then it will print the SQL insert statement but not execute it
     319        # (a behaviour following what the GS XML Plugout superclass does on debug)
    361320       
    362321        $gs_sql->insert_row_into_metadata_table($doc_oid, $section_name, $meta_name, $meta_value, $self->{'debug'});
     
    368327
    369328    # See above, no need to html-escape for db
    370     my $section_text = $section_ptr->{'text'}; #&docprint::escape_textref(\$section_ptr->{'text'});
     329    my $section_text = $section_ptr->{'text'};
    371330   
    372     # fulltxt column can be SQL NULL. undef value gets written out as NULL:
     331    # fulltxt column can be SQL NULL. undef value for $section_text gets written out as NULL:
    373332    # https://stackoverflow.com/questions/12708633/which-one-represents-null-undef-or-empty-string
    374333    # The following will do the SQL insertion
Note: See TracChangeset for help on using the changeset viewer.