Skip to content

Instantly share code, notes, and snippets.

@perlDreamer
Created October 25, 2010 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perlDreamer/645726 to your computer and use it in GitHub Desktop.
Save perlDreamer/645726 to your computer and use it in GitHub Desktop.
diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt
index 3a23b57..c25f9a7 100644
--- a/docs/changelog/7.x.x.txt
+++ b/docs/changelog/7.x.x.txt
@@ -4,6 +4,7 @@
- fixed #11922: Help tempalte is squatting on a good URL
- fixed #11923: Collaboration System Mail Cron Errors
- fixed #11925: Some problems in Thingy export (metaData values in CSV export)
+ - fixed #11925: Some problems in Thingy export (export times out on Things with many rows)
7.10.3
- fixed #11903: Unnecessary debug in Thingy
diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm
index 98496fd..e1f54da 100644
--- a/lib/WebGUI/Asset/Wobject/Thingy.pm
+++ b/lib/WebGUI/Asset/Wobject/Thingy.pm
@@ -21,6 +21,7 @@ use WebGUI::DateTime;
use base 'WebGUI::Asset::Wobject';
use Data::Dumper;
use PerlIO::eol qw/NATIVE/;
+use WebGUI::ProgressBar;
#-------------------------------------------------------------------
@@ -2686,6 +2687,11 @@ sub www_export {
my $thingProperties = $self->getThing($thingId);
return $session->privilege->insufficient() unless $self->hasPrivileges($thingProperties->{groupIdExport});
+ my $i18n = WebGUI::International->new($session, 'Asset_Thingy');
+ my $pb = WebGUI::ProgressBar->new($session);
+ $pb->start($i18n->get('export label').' '.$thingProperties->{label}, $session->url->extras('assets/thingy.gif'));
+ $pb->update($i18n->get('Creating column headers'));
+ my $tempStorage = WebGUI::Storage->createTemp($session);
$fields = $session->db->read('select * from Thingy_fields where assetId =? and thingId = ? order by sequenceNumber',
[$self->get("assetId"),$thingId]);
while (my $field = $fields->hashRef) {
@@ -2707,9 +2713,13 @@ sub www_export {
### Loop through the returned structure and put it through Text::CSV
# Column heads
- $out = WebGUI::Text::joinCSV(@fieldLabels);
+ my $csv_filename = 'export_'.$thingProperties->{label}.'.csv';
+ $tempStorage->addFileFromScalar($csv_filename, WebGUI::Text::joinCSV(@fieldLabels));
+ open my $CSV, '>', $tempStorage->getPath($csv_filename);
# Data lines
+ $pb->update($i18n->get('Writing data'));
+ my $rowCounter = 0;
while (my $data = $sth->hashRef) {
my @fieldValues;
foreach my $field (@fields){
@@ -2723,14 +2733,15 @@ sub www_export {
push(@fieldValues,$data->{$metaDataField});
}
}
- $out .= "\n".WebGUI::Text::joinCSV( @fieldValues );
+ print $CSV "\n".WebGUI::Text::joinCSV( @fieldValues );
+ #if (! ++$rowCounter % 25) {
+ $pb->update($i18n->get('Writing data'));
+ #}
}
-
- $fileName = "export_".$thingProperties->{label}.".csv";
- $self->session->http->setFilename($fileName,"application/octet-stream");
- $self->session->http->sendHeader;
- return $out;
+ close $CSV;
+ $pb->update(sprintf q|<a href="%s">%s</a>|, $session->url->getBackToSiteURL, $i18n->get('493', 'WebGUI'));
+ return $pb->finish($tempStorage->getUrl($csv_filename));
}
#-------------------------------------------------------------------
diff --git a/lib/WebGUI/i18n/English/Asset_Thingy.pm b/lib/WebGUI/i18n/English/Asset_Thingy.pm
index ccf77e1..eeff14e 100644
--- a/lib/WebGUI/i18n/English/Asset_Thingy.pm
+++ b/lib/WebGUI/i18n/English/Asset_Thingy.pm
@@ -1127,6 +1127,18 @@ search has been done.|,
lastUpdated => 1231180362,
},
+ 'Creating column headers' => {
+ message => q|Creating column headers.|,
+ lastUpdated => 1231180362,
+ context => q|Status message in the Export Thingy progress bar.|,
+ },
+
+ 'Writing data' => {
+ message => q|Writing data.|,
+ lastUpdated => 1231180362,
+ context => q|Status message in the Export Thingy progress bar.|,
+ },
+
};
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment