- Timestamp:
- 2018-11-09T22:33:51+13:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm
r32592 r32595 39 39 40 40 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 49 44 sub BEGIN { 50 45 @GreenstoneSQLPlugout::ISA = ('GreenstoneXMLPlugout'); 51 46 } 52 47 53 # + NOTTODO: die() statements need to be replaced with premature_termination54 # which should ensure the GreenstoneXMLPlugin (group)'s stuff is closed and cleaned up SOMEHOW55 # It's fine: the die() stmts all take place before setting up the super class' begin56 57 # + TODO Q: about build_mode: how to detect removeold. Now handled by58 # GreenstoneSQLPlugout::remove_all(), which is inherited from a base plugin.59 # + TODO: deal with -removeold and everything? Or type out instructions for user60 61 # + TODO Q: what is "group" in GreenstoneXMLPlugout?62 48 63 49 my $process_mode_list = … … 141 127 return bless $self, $class; 142 128 } 143 #print STDERR "***** GreenstoneSQLPlugout process mode = \"", $self->{'process_mode'}, "\"\n";144 129 145 130 return bless $self, $class; … … 151 136 my $self= shift (@_); 152 137 153 # The saveas.options154 #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 166 138 my $db_params = { 167 139 'collection_name' => $ENV{'GSDLCOLLECTION'}, … … 192 164 } 193 165 194 #die("@@@@ TEST. Connected successfully. Testing gsmysql::destructor.\n"); # WORKS195 196 166 my $db_name = $self->{'site'} || "greenstone2"; # one database per GS3 site, for GS2 the db is called greenstone2 197 167 my $proc_mode = $self->{'process_mode'}; … … 201 171 202 172 if($success && $proc_mode ne "text_only") { 203 ##print STDERR "@@@@ Ensuring meta table exists\n";204 173 $success = $gs_sql->ensure_meta_table_exists(); 205 174 } 206 175 if($success && $proc_mode ne "meta_only") { 207 ##print STDERR "@@@@ Ensuring fulltxt table exists\n";208 176 $success = $gs_sql->ensure_fulltxt_table_exists(); 209 177 } … … 213 181 # PrintError would already have displayed the warning message on load fail 214 182 # 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 error216 183 die("Could not use db $db_name and/or prepare its tables. Can't proceed.\n"); 217 184 } … … 221 188 222 189 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 etc190 # 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 226 193 227 194 $self->SUPER::begin(@_); … … 261 228 } 262 229 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 265 231 sub saveas { 266 232 my $self = shift (@_); … … 276 242 $self->{'debug_outhandle'} = $docxml_outhandler if ($self->{'debug'}); # STDOUT if debug 277 243 278 # TODO: also set debugging in begin()? Then stmts creating db and tables also sent to debug out and not executed279 280 281 244 # 2. overriding saving behaviour to do what the superclass does (writing out doc.xml files, 282 245 # under new name of docsql.xml, with breadcrumbs pointing to sql db) PLUS saving to sql db … … 308 271 309 272 310 # database connection is closed in end() method311 # so we don't open and closeover and over for each doc during a single build273 # 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 312 275 } 313 276 … … 324 287 } 325 288 326 # Perl: Reading or Writing to Another Program327 # https://nnc3.com/mags/Perl3/cookbook/ch16_05.htm328 289 sub recursive_write_meta_and_text { 329 290 my $self = shift (@_); … … 345 306 foreach my $data (@{$section_ptr->{'metadata'}}) { 346 307 my $meta_name = $data->[0]; 347 # TODO: does it need to be stored escaped, as it requires unescaping when read back in348 # from db (unlike for reading back in from doc.xml)349 308 350 309 # 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 353 311 my $meta_value = $data->[1]; 354 312 … … 359 317 # filling in the values 360 318 # 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) 361 320 362 321 $gs_sql->insert_row_into_metadata_table($doc_oid, $section_name, $meta_name, $meta_value, $self->{'debug'}); … … 368 327 369 328 # 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'}; 371 330 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: 373 332 # https://stackoverflow.com/questions/12708633/which-one-represents-null-undef-or-empty-string 374 333 # The following will do the SQL insertion
Note:
See TracChangeset
for help on using the changeset viewer.