Changeset 15872 for gsdl/trunk/perllib/plugins/DBPlugin.pm
- Timestamp:
- 2008-06-05T09:29:32+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/plugins/DBPlugin.pm
r15865 r15872 1 1 ########################################################################### 2 2 # 3 # DBPlug .pm -- plugin to import records from a database3 # DBPlugin.pm -- plugin to import records from a database 4 4 # 5 5 # A component of the Greenstone digital library software … … 34 34 # Mar, Apr 2003 35 35 36 package DBPlug ;36 package DBPlugin; 37 37 38 38 use strict; 39 39 no strict 'refs'; # allow variable as a filehandle 40 40 41 use BasPlug;41 use AutoExtractMetadata; 42 42 use unicode; 43 43 44 #use DBI; # database independent stuff45 46 44 sub BEGIN { 47 @DBPlug ::ISA = ('BasPlug');45 @DBPlugin::ISA = ('AutoExtractMetadata'); 48 46 } 49 47 50 48 my $arguments = 51 49 [ { 'name' => "process_exp", 52 'desc' => "{ BasPlug.process_exp}",50 'desc' => "{AutoExtractMetadata.process_exp}", 53 51 'type' => "regexp", 54 52 'deft' => &get_default_process_exp(), 55 53 'reqd' => "no" }]; 56 54 57 my $options = { 'name' => "DBPlug ",58 'desc' => "{DBPlug .desc}",55 my $options = { 'name' => "DBPlugin", 56 'desc' => "{DBPlugin.desc}", 59 57 'abstract' => "no", 60 58 'inherits' => "yes", … … 66 64 push(@$pluginlist, $class); 67 65 68 if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}69 if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};70 71 my $self = new BasPlug($pluginlist, $inputargs, $hashArgOptLists);66 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments}); 67 push(@{$hashArgOptLists->{"OptList"}},$options); 68 69 my $self = new AutoExtractMetadata($pluginlist, $inputargs, $hashArgOptLists); 72 70 73 71 return bless $self, $class; … … 78 76 79 77 return q^(?i)\.dbi$^; 80 }81 # we don't have a per-greenstone document process() function!82 sub process {83 84 78 } 85 79 … … 95 89 my $verbosity = $self->{'verbosity'}; 96 90 97 print $outhandle "DBPlug : processing $file\n"91 print $outhandle "DBPlugin: processing $file\n" 98 92 if $self->{'verbosity'} > 1; 99 93 … … 114 108 my $db=undef; 115 109 116 # get id of pages from "nonempty", get latest version number from "recent", and 117 #then get pagename from "page" and content from "version" !110 # get id of pages from "nonempty", get latest version number from 111 # "recent", and then get pagename from "page" and content from "version" ! 118 112 119 113 my $sql_query_prime = undef ; … … 126 120 # read in config file. 127 121 if (!open (CONF, $filename)) { 128 print $outhandle "DBPlug : can't read $filename: $!\n";122 print $outhandle "DBPlugin: can't read $filename: $!\n"; 129 123 return 0; 130 124 } … … 145 139 $callback =~ /[\`]|\|\-/) { 146 140 # no backticks or functions that start new processes allowed 147 print $outhandle "DBPlug : bad function in callback\n";141 print $outhandle "DBPlugin: bad function in callback\n"; 148 142 return 0; 149 143 } … … 152 146 my $ret = eval "\$callbacks{'$fieldname'} = $callback ; 1"; 153 147 if (!defined($ret)) { 154 print $outhandle "DBPlug : error eval'ing callback: $@\n";148 print $outhandle "DBPlugin: error eval'ing callback: $@\n"; 155 149 exit(1); 156 150 } 157 151 $callback=""; 158 print $outhandle "DBPlug : callback registered for '$fieldname'\n"152 print $outhandle "DBPlugin: callback registered for '$fieldname'\n" 159 153 if $dbplug_debug; 160 154 } elsif ($callback) { … … 176 170 chomp $err; 177 171 $err =~ s/\.$//; # remove a trailing . 178 print $outhandle "DBPlug : error evaluating `$statement'\n";172 print $outhandle "DBPlugin: error evaluating `$statement'\n"; 179 173 print $outhandle " $err (in $filename)\n"; 180 174 return 0; # there was an error reading the config file … … 185 179 $statement = ""; 186 180 } else { 187 print $outhandle "DBPlug : skipping statement `$statement'\n";181 print $outhandle "DBPlugin: skipping statement `$statement'\n"; 188 182 } 189 183 $statement = ""; … … 194 188 195 189 if (!defined($db)) { 196 print $outhandle "DBPlug : error: $filename does not specify a db!\n";190 print $outhandle "DBPlugin: error: $filename does not specify a db!\n"; 197 191 return 0; 198 192 } 199 193 if (!defined($sql_query)) { 200 print $outhandle "DBPlug : error: no SQL query specified!\n";194 print $outhandle "DBPlugin: error: no SQL query specified!\n"; 201 195 return 0; 202 196 } … … 205 199 206 200 if (!defined($dbhandle)) { 207 die "DBPlug : could not connect to database, exiting.\n";201 die "DBPlugin: could not connect to database, exiting.\n"; 208 202 } 209 203 if (defined($dbplug_debug) && $dbplug_debug==1) { 210 print $outhandle "DBPlug (debug): connected ok\n";204 print $outhandle "DBPlugin (debug): connected ok\n"; 211 205 } 212 206 … … 238 232 if (defined($db_to_greenstone_fields{$fieldname})) { 239 233 if (defined($dbplug_debug) && $dbplug_debug==1) { 240 print $outhandle "DBPlug (debug): mapping db field "234 print $outhandle "DBPlugin (debug): mapping db field " 241 235 . "'$fieldname' to " 242 236 . $db_to_greenstone_fields{$fieldname} . "\n"; … … 255 249 while (scalar(@row_array)) { 256 250 if (defined($dbplug_debug) && $dbplug_debug==1) { 257 print $outhandle "DBPlug (debug): retrieved a row from query\n";251 print $outhandle "DBPlugin (debug): retrieved a row from query\n"; 258 252 } 259 253 … … 263 257 my $cursection = $doc_obj->get_top_section(); 264 258 265 # if $language not set in config file, will use Bas Plug's default259 # if $language not set in config file, will use BasePlugin's default 266 260 if (defined($language)) { 267 261 $doc_obj->add_utf8_metadata($cursection, "Language", $language); 268 262 } 269 # if $encoding not set in config file, will use Bas Plug's default263 # if $encoding not set in config file, will use BasePlugin's default 270 264 if (defined($encoding)) { 271 265 # allow some common aliases … … 274 268 $doc_obj->add_utf8_metadata($cursection, "Encoding", $encoding); 275 269 } 276 $ doc_obj->add_utf8_metadata($cursection,277 "Source", &ghtml::dmsafe($db)); 270 $self->set_Source_metadata($doc_obj, $db, $encoding); 271 278 272 if ($self->{'cover_image'}) { 279 273 $self->associate_cover_image($doc_obj, $filename); … … 358 352 # check "$sth->err" if empty array for error 359 353 if ($statement_hand->err) { 360 print $outhandle "DBPlug : received error: \"" .354 print $outhandle "DBPlugin: received error: \"" . 361 355 $statement_hand->errstr . "\"\n"; 362 356 } … … 370 364 371 365 if (defined($dbplug_debug) && $dbplug_debug==1) { 372 print $outhandle "DBPlug : imported $count DB records as documents.\n";366 print $outhandle "DBPlugin: imported $count DB records as documents.\n"; 373 367 } 374 368 $count;
Note:
See TracChangeset
for help on using the changeset viewer.