Real PA status, as described in the RFE.

This commit is contained in:
Colin Kuskie 2009-02-10 18:39:10 -08:00 committed by Patrick Donelan
parent b206ad1270
commit 0b0962096e
3 changed files with 40 additions and 5 deletions

View file

@ -11,6 +11,7 @@ use WebGUI::Utility;
use WebGUI::HTMLForm;
use WebGUI::Workflow;
use WebGUI::Workflow::Instance;
use WebGUI::User;
=head1 NAME
@ -33,7 +34,11 @@ Returns true if an instance of the PassiveAnalytics workflow is active.
sub analysisActive {
my $session = shift;
return $session->db->quickScalar(q!select count(*) from WorkflowInstance where workflowId='PassiveAnalytics000001'!);
my ($running, $startDate, $endDate, $userId) = $session->db->quickArray(q!select running, startDate, endDate, userId from passiveAnalyticsStatus!);
if (wantarray) {
return $running, $startDate, $endDate, WebGUI::User->new($session, $userId);
}
return $running;
}
#----------------------------------------------------------------------------
@ -103,9 +108,13 @@ sub www_editRuleflow {
my $session = shift;
my $error = shift;
return $session->privilege->insufficient() unless canView($session);
my ($running, $startDate, $endDate, $user) = analysisActive($session);
if ($error) {
$error = qq|<div class="error">$error</div>\n|;
}
elsif (!$running) {
$error = qq|<div class="error">Passive Analytics analysis completed on $endDate</div>\n|;
}
my $i18n = WebGUI::International->new($session, "PassiveAnalytics");
my $addmenu = '<div style="float: left; width: 200px; font-size: 11px;">';
$addmenu .= sprintf '<a href="%s">%s</a>',
@ -127,8 +136,10 @@ sub www_editRuleflow {
label => $i18n->get('pause interval'),
hoverHelp => $i18n->get('pause interval help'),
);
if (analysisActive($session)) {
$f->raw('<tr><td coldspan="2">Passive Analytics analysis is currently active</td></tr>');
if ($running) {
$f->raw(sprintf <<EOD, $startDate, $user->username);
<tr><td colspan="2">Passive Analytics analysis is currently active. Analysis was begun at %s by %s</td></tr>
EOD
}
else {
$f->submit(value => $i18n->get('Begin analysis'));
@ -182,6 +193,7 @@ sub www_editRuleflowSave {
return www_editRuleflow($session, "Error creating the workflow instance.");
}
$instance->start('skipRealtime');
$session->db->write('update passiveAnalyticsStatus set startDate=NOW(), userId=?, endDate=?, running=1', [$session->user->userId, '']);
return www_editRuleflow($session);
}
@ -247,7 +259,6 @@ sub www_editRuleSave {
'fooBarBaz' =~ qr/$regexp/;
};
if ($@) {
$session->log->warn("Error: $@");
my $error = $@;
$error =~ s/at \S+?\.pm line \d+.*$//;
my $i18n = WebGUI::International->new($session, 'PassiveAnalytics');

View file

@ -74,6 +74,7 @@ Analyze the deltaLog table, and generate the bucketLog table.
sub execute {
my ($self, undef, $instance) = @_;
my $session = $self->session;
sleep 45;
my $endTime = time() + $self->getTTL;
my $expired = 0;
@ -139,6 +140,7 @@ EOSQL1
userId => $self->get('userId'),
message => $message,
});
$session->db->write('update passiveAnalyticsStatus set endDate=NOW(), running=0');
return $self->COMPLETE;
}

View file

@ -34,8 +34,8 @@ installLoggingTables($session);
installPassiveAnalyticsRule($session);
installPassiveAnalyticsConfig($session);
installWorkflow($session);
#addAdminGroup($session);
addPassiveAnalyticsSettings($session);
addPassiveAnalyticsStatus($session);
finish($session);
@ -105,6 +105,28 @@ sub addPassiveAnalyticsSettings {
print "DONE!\n";
}
#----------------------------------------------------------------------------
# Add the PassiveAnalytics Rule table
sub addPassiveAnalyticsStatus {
my $session = shift;
my $db = $session->db;
print "\tInstall Passive Analytics status table... ";
# and here's our code
$db->write(<<EOT2);
DROP TABLE if exists passiveAnalyticsStatus;
EOT2
$db->write(<<EOT3);
CREATE TABLE `passiveAnalyticsStatus` (
`startDate` datetime,
`endDate` datetime,
`running` integer(2) DEFAULT 0,
`userId` varchar(22) character set utf8 collate utf8_bin NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
EOT3
$db->write('insert into passiveAnalyticsStatus (userId) VALUES (3)');
print "DONE!\n";
}
#----------------------------------------------------------------------------
# Add the Passive Analytics config file entry
# for the adminConsole and the content handler