Added two new hooks into the setup code: a start notification and an end notification. Added the ability to disable the string datasource (causes it to only use the default strings and not the database). Made the string datasource automatically disable itself during configuration, using the two hooks added to the setup code. This removes the warning messages that are output during a clean setup ('could not get string from database', etc).

This commit is contained in:
ian%hixie.ch 2001-11-08 16:42:42 +00:00
Родитель 9e592855e5
Коммит ade117cf45
2 изменённых файлов: 56 добавлений и 31 удалений

Просмотреть файл

@ -39,8 +39,10 @@ sub provides {
my $class = shift;
my($service) = @_;
# XXX this class should provide a 'clear caches' service (as should some others)
return ($service eq 'dataSource.strings' or
$service eq 'setup.install' or
return ($service eq 'dataSource.strings' or
$service eq 'setup.install' or
$service eq 'setup.events.start' or
$service eq 'setup.events.end' or
$class->SUPER::provides($service));
}
@ -49,6 +51,7 @@ sub init {
$self->SUPER::init(@_);
$self->variantsCache({});
$self->stringsCache({});
$self->enabled(1);
}
sub databaseName {
@ -60,37 +63,42 @@ sub get {
my $self = shift;
my($app, $session, $protocol, $string) = @_;
# error handling makes code ugly :-)
my $variant;
if (defined($session)) {
$variant = $session->selectVariant($protocol);
}
if (not defined($variant)) {
# default session or $session didn't care, get stuff from
# $app->input instead
$variant = $self->selectVariant($app, $protocol);
}
if (not defined($self->stringsCache->{$variant})) {
$self->stringsCache->{$variant} = {};
}
if (not defined($self->stringsCache->{$variant}->{$string})) {
my @results;
eval {
@results = $self->getString($app, $variant, $string);
};
if ($@) {
# ok, so, er, it seems that didn't go to well
# XXX do we want to do an error here or something?
$self->warn(4, "While I was looking for the string '$string' in protocol '$protocol' using variant '$variant', I failed with: $@");
if ($self->enabled) {
my $variant;
if (defined($session)) {
$variant = $session->selectVariant($protocol);
}
if (not scalar(@results)) {
$self->dump(9, "Did not find a string for '$string', going to look in the defaults...");
@results = $self->getDefaultString($app, $protocol, $string);
$self->assert(scalar(@results), 1, "Couldn't find a string to display for '$string' in protocol '$protocol'");
if (not defined($variant)) {
# default session or $session didn't care, get stuff from
# $app->input instead
$variant = $self->selectVariant($app, $protocol);
}
if (not defined($self->stringsCache->{$variant})) {
$self->stringsCache->{$variant} = {};
}
if (not defined($self->stringsCache->{$variant}->{$string})) {
my @results;
eval {
@results = $self->getString($app, $variant, $string);
};
if ($@) {
# ok, so, er, it seems that didn't go to well
# XXX do we want to do an error here or something?
$self->warn(4, "While I was looking for the string '$string' in protocol '$protocol' using variant '$variant', I failed with: $@");
}
if (not scalar(@results)) {
$self->dump(9, "Did not find a string for '$string', going to look in the defaults...");
@results = $self->getDefaultString($app, $protocol, $string);
$self->assert(scalar(@results), 1, "Couldn't find a string to display for '$string' in protocol '$protocol'");
}
$self->stringsCache->{$variant}->{$string} = \@results;
return @results;
} else {
return @{$self->stringsCache->{$variant}->{$string}};
}
$self->stringsCache->{$variant}->{$string} = \@results;
return @results;
} else {
return @{$self->stringsCache->{$variant}->{$string}};
$self->dump(9, "String datasource is disabled, going to use default for string '$string'.");
return $self->getDefaultString($app, $protocol, $string);
}
}
@ -146,6 +154,20 @@ sub variants {
return $self->variantsCache->{$protocol};
}
# setup.events.start
sub setupStarting {
my $self = shift;
my($app) = @_;
$self->enabled(0);
}
# setup.events.end
sub setupEnding {
my $self = shift;
my($app) = @_;
$self->enabled(1);
}
# XXX The next four SO have to change...
sub acceptType {

Просмотреть файл

@ -74,11 +74,14 @@ sub cmdSetup {
my($app) = @_;
my $result;
# call all the setup handlers until one fails:
# the setupX methods can call $app->output->setupProgress('name of component');
$app->getPipingServiceList('setup.events.start')->setupStarting($app);
$result = $app->getSelectingServiceList('setup.configure')->setupConfigure($app);
if (not $result) {
$result = $app->getSelectingServiceList('setup.install')->setupInstall($app);
}
# the setupConfigure and setupInstall methods can call $app->output->setupProgress('name of component');
$app->getPipingServiceList('setup.events.end')->setupEnding($app);
# report on the result
if ($result) {
$app->output->setupFailed($result);
} else {