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: Snippet Security Fails
- 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
- 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 $newSession = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename);
$newSession->user({userId=>$userId});
my $tempSession = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename);
$tempSession->user({userId=>$userId});
my $newSelf = WebGUI::Asset->new($newSession, $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 $newSelf = WebGUI::Asset->new($tempSession, $self->getId, $self->get("className"), $self->get("revisionDate"));
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");
$self->session->output->print(sprintf($i18n->get('exporting page'), $url)) unless $quiet;
@ -145,19 +151,19 @@ sub _exportAsHtml {
if ($@) {
return (0, sprintf($i18n->get('could not open path'), $path, $@));
} else {
$newSession->output->setHandle($file);
$newSession->asset($asset);
$assetSession->output->setHandle($file);
$assetSession->asset($asset);
my $content = $asset->www_view;
unless ($content eq "chunked") {
$newSession->output->print($content);
$assetSession->output->print($content);
}
$file->close;
}
$assetSession->var->end;
$assetSession->close;
$self->session->output->print($i18n->get('done')) unless $quiet;
}
$newSession->var->end;
$newSession->close;
if ($extrasUploadsAction eq 'symlink') {
my ($extrasPath, $uploadsPath) = ($self->session->config->get('extrasPath'), $self->session->config->get('uploadsPath'));
@ -187,12 +193,15 @@ sub _exportAsHtml {
if ($rootUrlAction eq 'symlinkDefault') {
# TODO: internationalize
if (defined $defaultAssetPath) {
my ($src, $dst) = ($defaultAssetPath, $exportPath.'/'.$index);
$self->session->output->print("Symlinking default asset.\n") unless $quiet;
if (-l $dst and readlink $dst ne $src) {
unlink $dst or return (0, sprintf("Could not unlink %s: %s", $dst, $!));
{
my ($src, $dst) = ($defaultAssetPath, $exportPath.'/'.$index);
$self->session->output->print("Symlinking default asset.\n") unless $quiet;
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 {
$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.
}
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