Merge commit 'v7.10.24' into WebGUI8

This commit is contained in:
Colin Kuskie 2012-01-17 15:03:45 -08:00
commit 3b418ede3c
139 changed files with 699 additions and 32133 deletions

View file

@ -11,6 +11,7 @@ use WebGUI::Workflow;
use WebGUI::Workflow::Instance;
use WebGUI::User;
use WebGUI::Text;
use WebGUI::Fork;
=head1 NAME
@ -57,7 +58,7 @@ sub canView {
#----------------------------------------------------------------------------
=head2 exportSomething ( session, sth, filename )
=head2 exportSomething ( $process, $data )
Generates CSV data from the supplied statement handle and generates
a temporary WebGUI::Storage object containing that data in the requested
@ -66,31 +67,53 @@ filename.
This subroutine also does a setRedirect to the URL of the file in
the storage object.
=head3 session
=head3 $process
Session variable, to set the http redirect correctly.
A WebGUI::Fork object, to let the user know what's going on.
=head3 sth
=head3 $data
Statement handle for reading data and getting column names
Hash ref of data.
=head3 tableName
The name of the table where data will be pulled and translated into CSV.
=head3 filename
The name of the file to create inside the storage object.
The name of the file to generate
=cut
sub exportSomething {
my ($session, $sth, $filename) = @_;
my ($process, $data) = @_;
my $session = $process->session;
my $i18n = WebGUI::International->new($session, 'Asset_Thingy');
my $storage = WebGUI::Storage->createTemp($session);
open my $CSV, '>', $storage->getPath($data->{filename});
my $sth = $session->db->read('select SQL_CALC_FOUND_ROWS * from '.$data->{tableName});
my %status = (
current => 0,
message => '',
total => $session->db->quickScalar('select found_rows()') + 0,
);
my $update = sub {
$process->update( sub { JSON::to_json(\%status) } );
};
$update->();
my @columns = $sth->getColumnNames;
my $csvData = WebGUI::Text::joinCSV( @columns ). "\n";
print $CSV WebGUI::Text::joinCSV( @columns ). "\n";
my $rowCounter = 0;
$status{message} = $i18n->get('Writing data');
$update->();
while (my $row = $sth->hashRef()) {
my @row = @{ $row }{@columns};
$csvData .= WebGUI::Text::joinCSV(@row) . "\n";
print $CSV WebGUI::Text::joinCSV(@row) . "\n";
++$status{current };
$update->();
}
$storage->addFileFromScalar($filename, $csvData);
$session->response->setRedirect($storage->getUrl($filename));
close $CSV;
$sth->finish;
}
#-------------------------------------------------------------------
@ -334,8 +357,24 @@ Dump the contents of the bucket log.
sub www_exportBucketData {
my ($session) = @_;
my $bucket = $session->db->read('select * from bucketLog order by userId, Bucket, timeStamp');
exportSomething($session, $bucket, 'bucketData.csv');
my $process = WebGUI::Fork->start(
$session,
__PACKAGE__, 'exportSomething',
{ tableName => 'bucketLog', filename => 'bucketData.csv', },
);
my $i18n = WebGUI::International->new($session, 'PassiveAnalytics');
$session->http->setRedirect(
$session->url->page(
$process->contentPairs(
'ProgressBar', {
icon => 'passiveAnalytics',
title => $i18n->get('Export bucket data'),
proceed => $session->url->page('op=passiveAnalytics;func=editRuleflow'),
},
),
),
);
return "redirect";
}
@ -349,8 +388,23 @@ Dump the contents of the delta log.
sub www_exportDeltaData {
my ($session) = @_;
my $delta = $session->db->read('select * from deltaLog order by userId, timeStamp');
exportSomething($session, $delta, 'deltaData.csv');
my $process = WebGUI::Fork->start(
$session,
__PACKAGE__, 'exportSomething',
{ tableName => 'deltaLog', filename => 'deltaData.csv', },
);
my $i18n = WebGUI::International->new($session, 'PassiveAnalytics');
$session->http->setRedirect(
$session->url->page(
$process->contentPairs(
'ProgressBar', {
icon => 'passiveAnalytics',
title => $i18n->get('Export delta data'),
proceed => $session->url->page('op=passiveAnalytics;func=editRuleflow'),
},
),
),
);
return "redirect";
}
@ -364,8 +418,23 @@ Dump the contents of the raw log.
sub www_exportLogs {
my ($session) = @_;
my $raw = $session->db->read('select * from passiveLog order by userId, timeStamp');
exportSomething($session, $raw, 'passiveData.csv');
my $process = WebGUI::Fork->start(
$session,
__PACKAGE__, 'exportSomething',
{ tableName => 'passiveLog', filename => 'passiveData.csv', },
);
my $i18n = WebGUI::International->new($session, 'PassiveAnalytics');
$session->http->setRedirect(
$session->url->page(
$process->contentPairs(
'ProgressBar', {
icon => 'passiveAnalytics',
title => $i18n->get('Export raw logs'),
proceed => $session->url->page('op=passiveAnalytics;func=editRuleflow'),
},
),
),
);
return "redirect";
}