Make the asset exporter use one session per asset, so as to avoid breaking

state that relies on only one asset being viewed per session.
This commit is contained in:
Drake 2006-10-12 02:45:43 +00:00
parent dad217b7fe
commit 57f7fe1c6f
2 changed files with 26 additions and 16 deletions

View file

@ -4,6 +4,7 @@
- fix: Survey: textarea answers are trunctated - fix: Survey: textarea answers are trunctated
- fix: Snippet Security Fails - fix: Snippet Security Fails
- add: asset exporter making appropriate symlinks for extras, uploads, and root URL - add: asset exporter making appropriate symlinks for extras, uploads, and root URL
- change: asset exporter now uses one session per asset to avoid breaking state in between
7.1.0 7.1.0
- fix: mysql and mysqldump were transposed in upgrade.pl --help - fix: mysql and mysqldump were transposed in upgrade.pl --help

View file

@ -95,13 +95,19 @@ sub _exportAsHtml {
my $i18n = WebGUI::International->new($self->session, 'Asset'); my $i18n = WebGUI::International->new($self->session, 'Asset');
my $newSession = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename); my $tempSession = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename);
$newSession->user({userId=>$userId}); $tempSession->user({userId=>$userId});
my $newSelf = WebGUI::Asset->new($newSession, $self->getId, $self->get("className"), $self->get("revisionDate")); my $newSelf = WebGUI::Asset->new($tempSession, $self->getId, $self->get("className"), $self->get("revisionDate"));
my $assets = $newSelf->getLineage(["self","descendants"],{returnObjects=>1,endingLineageLength=>$newSelf->getLineageLength+$self->session->form->process("depth")}); my $assetIds = $newSelf->getLineage(["self","descendants"],{endingLineageLength=>$newSelf->getLineageLength+$self->session->form->process("depth")});
$tempSession->var->end;
$tempSession->close;
foreach my $assetId (@{$assetIds}) {
my $assetSession = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename);
$assetSession->user({userId => $userId});
my $asset = WebGUI::Asset->newByDynamicClass($assetSession, $assetId);
foreach my $asset (@{$assets}) {
my $url = $asset->get("url"); my $url = $asset->get("url");
$self->session->output->print(sprintf($i18n->get('exporting page'), $url)) unless $quiet; $self->session->output->print(sprintf($i18n->get('exporting page'), $url)) unless $quiet;
@ -145,19 +151,19 @@ sub _exportAsHtml {
if ($@) { if ($@) {
return (0, sprintf($i18n->get('could not open path'), $path, $@)); return (0, sprintf($i18n->get('could not open path'), $path, $@));
} else { } else {
$newSession->output->setHandle($file); $assetSession->output->setHandle($file);
$newSession->asset($asset); $assetSession->asset($asset);
my $content = $asset->www_view; my $content = $asset->www_view;
unless ($content eq "chunked") { unless ($content eq "chunked") {
$newSession->output->print($content); $assetSession->output->print($content);
} }
$file->close; $file->close;
} }
$assetSession->var->end;
$assetSession->close;
$self->session->output->print($i18n->get('done')) unless $quiet; $self->session->output->print($i18n->get('done')) unless $quiet;
} }
$newSession->var->end;
$newSession->close;
if ($extrasUploadsAction eq 'symlink') { if ($extrasUploadsAction eq 'symlink') {
my ($extrasPath, $uploadsPath) = ($self->session->config->get('extrasPath'), $self->session->config->get('uploadsPath')); my ($extrasPath, $uploadsPath) = ($self->session->config->get('extrasPath'), $self->session->config->get('uploadsPath'));
@ -187,12 +193,15 @@ sub _exportAsHtml {
if ($rootUrlAction eq 'symlinkDefault') { if ($rootUrlAction eq 'symlinkDefault') {
# TODO: internationalize # TODO: internationalize
if (defined $defaultAssetPath) { if (defined $defaultAssetPath) {
my ($src, $dst) = ($defaultAssetPath, $exportPath.'/'.$index); {
$self->session->output->print("Symlinking default asset.\n") unless $quiet; my ($src, $dst) = ($defaultAssetPath, $exportPath.'/'.$index);
if (-l $dst and readlink $dst ne $src) { $self->session->output->print("Symlinking default asset.\n") unless $quiet;
unlink $dst or return (0, sprintf("Could not unlink %s: %s", $dst, $!)); if (-l $dst) {
last if (readlink $dst eq $src);
unlink $dst or return (0, sprintf("Could not unlink %s: %s", $dst, $!));
}
symlink $src, $dst or return (0, sprintf("Could not symlink %s to %s: %s", $src, $dst, $!));
} }
symlink $src, $dst or return (0, sprintf("Could not symlink %s to %s: %s", $src, $dst, $!));
} else { } else {
$self->session->output->print("Not symlinking default asset; not included in exported subtree.\n") unless $quiet; $self->session->output->print("Not symlinking default asset; not included in exported subtree.\n") unless $quiet;
} }
@ -200,7 +209,7 @@ sub _exportAsHtml {
# Nothing. This is the default. # Nothing. This is the default.
} }
return (1, sprintf($i18n->get('export information'), scalar(@{$assets}), ($self->session->datetime->time()-$startTime))); return (1, sprintf($i18n->get('export information'), scalar(@{$assetIds}), ($self->session->datetime->time()-$startTime)));
} }
=head2 exportAsHtml =head2 exportAsHtml