17 |
|
|
18 |
=head1 VERSION |
=head1 VERSION |
19 |
|
|
20 |
Version 0.05 |
Version 0.08 |
21 |
|
|
22 |
=cut |
=cut |
23 |
|
|
24 |
our $VERSION = '0.05'; |
our $VERSION = '0.08'; |
25 |
|
|
26 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
27 |
|
|
40 |
passwd => 'admin', |
passwd => 'admin', |
41 |
database => 'demo', |
database => 'demo', |
42 |
encoding => 'iso-8859-2', |
encoding => 'iso-8859-2', |
43 |
|
clean => 1, |
44 |
); |
); |
45 |
|
|
46 |
Options are: |
Options are: |
91 |
my $url = $self->{masterurl} . '/node/' . $self->{database}; |
my $url = $self->{masterurl} . '/node/' . $self->{database}; |
92 |
$self->{url} = $url; |
$self->{url} = $url; |
93 |
|
|
94 |
$log->info("opening Hyper Estraier index $self->{url}"); |
if ($self->{clean}) { |
95 |
|
$log->debug("nodedel $self->{database}"); |
96 |
|
$self->master( action => 'nodedel', name => $self->{database} ); |
97 |
|
} else { |
98 |
|
$log->debug("opening index $self->{url}"); |
99 |
|
} |
100 |
|
|
101 |
my $nodes = $self->master( action => 'nodelist' ); |
my $nodes = $self->master( action => 'nodelist' ); |
102 |
|
|
103 |
$log->debug("nodes found: $nodes"); |
$log->debug("nodes found: $nodes"); |
104 |
|
|
105 |
if ($nodes !~ m/^$self->{database}\t/sm) { |
if ($nodes !~ m/^$self->{database}\t/sm) { |
106 |
$log->info("creating index $url"); |
$log->warn("creating index $url"); |
107 |
$self->master( |
$self->master( |
108 |
action => 'nodeadd', |
action => 'nodeadd', |
109 |
name => $self->{database}, |
name => $self->{database}, |
115 |
$self->{'db'}->set_auth($self->{'user'}, $self->{passwd}); |
$self->{'db'}->set_auth($self->{'user'}, $self->{passwd}); |
116 |
|
|
117 |
my $encoding = $self->{'encoding'} || 'ISO-8859-2'; |
my $encoding = $self->{'encoding'} || 'ISO-8859-2'; |
118 |
$log->info("using encoding $encoding"); |
$log->info("using index $self->{url} with encoding $encoding"); |
119 |
|
|
120 |
$self->{'iconv'} = new Text::Iconv($encoding, 'UTF-8') or |
$self->{'iconv'} = new Text::Iconv($encoding, 'UTF-8') or |
121 |
$log->logdie("can't create conversion from $encoding to UTF-8"); |
$log->logdie("can't create conversion from $encoding to UTF-8"); |
199 |
} |
} |
200 |
|
|
201 |
$log->debug("adding ", sub { $doc->dump_draft } ); |
$log->debug("adding ", sub { $doc->dump_draft } ); |
202 |
$self->{'db'}->put_doc($doc) || $log->logdie("can't add document $uri to node " . $self->{url} . " status: " . $self->{db}->status()); |
$self->{'db'}->put_doc($doc) || $log->warn("can't add document $uri with draft " . $doc->dump_draft . " to node " . $self->{url} . " status: " . $self->{db}->status()); |
203 |
|
|
204 |
return 1; |
return 1; |
205 |
} |
} |
245 |
validate => 'master', |
validate => 'master', |
246 |
rest_url => $self->{masterurl} . '/master?action=' . $action , |
rest_url => $self->{masterurl} . '/master?action=' . $action , |
247 |
action => $action, |
action => $action, |
248 |
|
%{ $args }, |
249 |
); |
); |
250 |
} |
} |
251 |
|
|
269 |
|
|
270 |
$log->debug("got labels: ", join("|", @labels)); |
$log->debug("got labels: ", join("|", @labels)); |
271 |
|
|
272 |
@labels = grep(/^$args->{to}/, @labels); |
@labels = grep(/^$args->{to}\t/, @labels); |
273 |
|
my $label = shift @labels; |
274 |
my (undef,$label) = split(/\t/, shift @labels); |
(undef,$label) = split(/\t/, $label) if ($label); |
275 |
|
|
276 |
if (! $label) { |
if (! $label) { |
277 |
$log->warn("can't find label for $args->{to}, skipping link creaton"); |
$log->warn("can't find label for $args->{to}, skipping link creaton"); |
329 |
$del = '&'; |
$del = '&'; |
330 |
} |
} |
331 |
|
|
332 |
$url_args =~ s#^\&#?# if ($url =~ m#\?#); |
$url .= $url_args if ($url_args); |
|
$url .= $url_args; |
|
333 |
|
|
334 |
$log->debug("calling $url"); |
$log->debug("calling $url"); |
335 |
|
|
355 |
|
|
356 |
=cut |
=cut |
357 |
|
|
358 |
|
|
359 |
|
|
360 |
sub est_ua { |
sub est_ua { |
361 |
my $self = shift; |
my $self = shift; |
362 |
|
|
363 |
return $self->{_master_ua} if ($self->{_master_ua}); |
return $self->{_master_ua} if ($self->{_master_ua}); |
364 |
|
|
365 |
$self->{_master_ua} = LWP::UserAgent->new( ) || sub { |
{ |
366 |
|
package AdminUserAgent; |
367 |
|
use base qw/LWP::UserAgent/; |
368 |
|
sub new { |
369 |
|
my $self = LWP::UserAgent::new(@_); |
370 |
|
$self->agent("webpac/$VERSION"); |
371 |
|
$self; |
372 |
|
} |
373 |
|
sub get_basic_credentials { |
374 |
|
my($self, $realm, $uri) = @_; |
375 |
|
return ($self->{user}, $self->{passwd}); |
376 |
|
} |
377 |
|
sub set_basic_credentials { |
378 |
|
my ($self, $user, $passwd) = @_; |
379 |
|
$self->{user} = $user; |
380 |
|
$self->{passwd} = $passwd; |
381 |
|
} |
382 |
|
}; |
383 |
|
|
384 |
|
$self->{_master_ua} = AdminUserAgent->new( ) || sub { |
385 |
my $log = $self->_get_logger; |
my $log = $self->_get_logger; |
386 |
$log->logdie("can't create LWP::UserAgent: $!"); |
$log->logdie("can't create LWP::UserAgent: $!"); |
387 |
}; |
}; |
388 |
|
|
389 |
$self->{_master_ua}->credentials('localhost:1978','Super User', $self->{user} => $self->{passwd}); |
$self->{_master_ua}->set_basic_credentials($self->{user}, $self->{passwd}); |
390 |
|
|
391 |
return $self->{_master_ua}; |
return $self->{_master_ua}; |
392 |
} |
} |