EXPORT- Exporting Files (PDFs, docs, and some pages)
This commit is contained in:
parent
0ceb0f68e3
commit
fc3f206171
4 changed files with 60 additions and 80 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
- Made Weather Data asset more fault tollerant.
|
- Made Weather Data asset more fault tollerant.
|
||||||
- Made CS related upgrades more fault tollerant.
|
- Made CS related upgrades more fault tollerant.
|
||||||
- Made slave handling more fault tollerant, and slightly higher performing.
|
- Made slave handling more fault tollerant, and slightly higher performing.
|
||||||
|
- fix: EXPORT- Exporting Files (PDFs, docs, and some pages)
|
||||||
- Enhanced HTTP caching directives.
|
- Enhanced HTTP caching directives.
|
||||||
- fix: Fixing bad link on the Event page to the search engine. Added a new
|
- fix: Fixing bad link on the Event page to the search engine. Added a new
|
||||||
Event template variable called urlSearch to handle it. (perlDreamer Consulting, LLC)
|
Event template variable called urlSearch to handle it. (perlDreamer Consulting, LLC)
|
||||||
|
|
|
||||||
|
|
@ -388,8 +388,6 @@ sub www_edit {
|
||||||
# exporter. We have a separate method for this now.
|
# exporter. We have a separate method for this now.
|
||||||
sub exportHtml_view {
|
sub exportHtml_view {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
return $self->session->privilege->noAccess() unless $self->canView;
|
|
||||||
|
|
||||||
my $path = $self->getStorageLocation->getPath($self->get('filename'));
|
my $path = $self->getStorageLocation->getPath($self->get('filename'));
|
||||||
my $fh = eval { FileHandle->new($path) };
|
my $fh = eval { FileHandle->new($path) };
|
||||||
defined($fh) or return "";
|
defined($fh) or return "";
|
||||||
|
|
|
||||||
|
|
@ -97,99 +97,88 @@ sub _exportAsHtml {
|
||||||
|
|
||||||
my $i18n = WebGUI::International->new($self->session, 'Asset');
|
my $i18n = WebGUI::International->new($self->session, 'Asset');
|
||||||
|
|
||||||
|
# Get a list of the asset IDs we need, reverse sorted by URL
|
||||||
my $tempSession = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename);
|
my $tempSession = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename);
|
||||||
$tempSession->user({userId=>$userId});
|
$tempSession->user({userId=>$userId});
|
||||||
|
|
||||||
my $newSelf = WebGUI::Asset->new($tempSession, $self->getId, $self->get("className"), $self->get("revisionDate"));
|
my $newSelf = WebGUI::Asset->new($tempSession, $self->getId, $self->get("className"), $self->get("revisionDate"));
|
||||||
# Get a list of the asset IDs we need, reverse sorted by URL
|
my $assetIds = $newSelf->getLineage(["self","descendants"],{
|
||||||
my $assetIds
|
endingLineageLength => $newSelf->getLineageLength+$self->session->form->process("depth"),
|
||||||
= $newSelf->getLineage(["self","descendants"],{
|
|
||||||
endingLineageLength => $newSelf->getLineageLength+$self->session->form->process("depth"),
|
|
||||||
orderByClause => 'assetData.url DESC',
|
orderByClause => 'assetData.url DESC',
|
||||||
});
|
});
|
||||||
|
$tempSession->var->end;
|
||||||
|
$tempSession->close;
|
||||||
|
|
||||||
$tempSession->var->end;
|
# We're going to walk up the URL branch, making the deepest paths first
|
||||||
$tempSession->close;
|
|
||||||
|
|
||||||
# We're going to walk up the URL branch, making the deepest paths first
|
|
||||||
foreach my $assetId (@{$assetIds}) {
|
foreach my $assetId (@{$assetIds}) {
|
||||||
my $assetSession
|
my $assetSession = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename);
|
||||||
= WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename);
|
$assetSession->user({userId=>$userId});
|
||||||
$assetSession->user({userId=>$userId});
|
|
||||||
my $asset = WebGUI::Asset->newByDynamicClass($assetSession, $assetId);
|
my $asset = WebGUI::Asset->newByDynamicClass($assetSession, $assetId);
|
||||||
|
|
||||||
my $url = $asset->get("url");
|
my $url = $asset->get("url");
|
||||||
$self->session->output->print(sprintf($i18n->get('exporting page'), $url)) unless $quiet;
|
|
||||||
|
|
||||||
|
# notify we can't output because user selected can't view the page
|
||||||
unless ($asset->canView($userId)) {
|
unless ($asset->canView($userId)) {
|
||||||
$self->session->output->print(sprintf($i18n->get('bad user privileges')."\n")) unless $quiet;
|
$self->session->output->print(sprintf($i18n->get('bad user privileges')."\n") . $asset->getUrl) unless $quiet;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# find out where we're exporting
|
||||||
my $pathData = $self->_translateUrlToPath($url, $index);
|
my $pathData = $self->_translateUrlToPath($url, $index);
|
||||||
if (my $error = $pathData->{'error'}) {
|
if (my $error = $pathData->{'error'}) {
|
||||||
return (0, $error);
|
return (0, $error);
|
||||||
}
|
}
|
||||||
|
my $path = $exportPath . '/'. $pathData->{'path'};
|
||||||
my $path = $pathData->{'path'};
|
|
||||||
my $filename = $pathData->{'filename'};
|
my $filename = $pathData->{'filename'};
|
||||||
|
|
||||||
my $fullPath = (length($path)? "$path/" : "").$filename;
|
# this is needed for symlinking
|
||||||
if ($asset->getId eq $defaultAssetId) {
|
if ($asset->getId eq $defaultAssetId) {
|
||||||
$defaultAssetPath = $fullPath;
|
$defaultAssetPath = (length($pathData->{'path'}) ? $pathData->{'path'}."/" : "") . $pathData->{'filename'};
|
||||||
}
|
}
|
||||||
|
|
||||||
# Make sure that the filename is not a directory in this path
|
# see if path already exists, if not, create it
|
||||||
if (-d $exportPath . "/" . $fullPath) {
|
unless (-d $path) {
|
||||||
# A previous asset created this directory
|
eval { mkpath($path) };
|
||||||
# so make this asset the index of this directory
|
if($@) {
|
||||||
if (!-e "$exportPath/$fullPath/$index") {
|
return (0, sprintf($i18n->get('could not create path'), $path, $@));
|
||||||
$path .= "/$filename";
|
}
|
||||||
$filename = $index;
|
}
|
||||||
$fullPath .= "/$index";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return (0, sprintf($i18n->get('file exists when making directory index'), $fullPath, $@));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->session->db->write("UPDATE asset SET lastExportedAs = ? WHERE assetId = ?", [$fullPath, $asset->getId]);
|
# output which page we're exporting
|
||||||
|
my $pathWithFilename = $path.'/'.$filename;
|
||||||
$path = $exportPath . (length($path)? "/$path" : "");
|
unless ($quiet) {
|
||||||
eval { mkpath($path) };
|
$self->session->output->print(sprintf($i18n->get('exporting page'), $pathWithFilename));
|
||||||
if($@) {
|
}
|
||||||
return (0, sprintf($i18n->get('could not create path'), $path, $@));
|
|
||||||
}
|
|
||||||
$path .= "/".$filename;
|
|
||||||
|
|
||||||
my $file = eval { FileHandle->new(">".$path) or die "$!" };
|
|
||||||
if ($@) {
|
|
||||||
return (0, sprintf($i18n->get('could not open path'), $path, $@));
|
|
||||||
} else {
|
|
||||||
$assetSession->output->setHandle($file);
|
|
||||||
$assetSession->asset($asset);
|
|
||||||
my $content = $asset->exportHtml_view;
|
|
||||||
unless ($content eq "chunked") {
|
|
||||||
$assetSession->output->print($content);
|
|
||||||
}
|
|
||||||
$file->close;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
# write the file
|
||||||
|
#open my $fileHandle, ">", $pathWithFilename;
|
||||||
|
my $fileHandle = FileHandle->new(">".$pathWithFilename);
|
||||||
|
if (defined $fileHandle) {
|
||||||
|
$assetSession->output->setHandle($fileHandle);
|
||||||
|
$assetSession->asset($asset);
|
||||||
|
my $content = $asset->exportHtml_view;
|
||||||
|
# chunked content will have already been printed, so no need to print again
|
||||||
|
unless ($content eq "chunked") {
|
||||||
|
$assetSession->output->print($content);
|
||||||
|
}
|
||||||
|
$fileHandle->close;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return (0, sprintf($i18n->get('could not open path'), $pathWithFilename, $!));
|
||||||
|
}
|
||||||
$assetSession->var->end;
|
$assetSession->var->end;
|
||||||
$assetSession->close;
|
$assetSession->close;
|
||||||
|
$self->session->db->write("UPDATE asset SET lastExportedAs = ? WHERE assetId = ?", [$pathWithFilename, $asset->getId]);
|
||||||
$self->session->output->print($i18n->get('done')) unless $quiet;
|
$self->session->output->print($i18n->get('done')) unless $quiet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# symlink?
|
||||||
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'));
|
||||||
my ($extrasUrl, $uploadsUrl) = ($self->session->config->get('extrasURL'), $self->session->config->get('uploadsURL'));
|
my ($extrasUrl, $uploadsUrl) = ($self->session->config->get('extrasURL'), $self->session->config->get('uploadsURL'));
|
||||||
s#^/*## for ($extrasUrl, $uploadsUrl);
|
s#^/*## for ($extrasUrl, $uploadsUrl);
|
||||||
my ($extrasDst, $uploadsDst) = ($exportPath.'/'.$extrasUrl, $exportPath.'/'.$uploadsUrl);
|
my ($extrasDst, $uploadsDst) = ($exportPath.'/'.$extrasUrl, $exportPath.'/'.$uploadsUrl);
|
||||||
|
|
||||||
$self->session->output->print($i18n->get('extrasUploads symlinking')."\n") unless $quiet;
|
$self->session->output->print($i18n->get('extrasUploads symlinking')."\n") unless $quiet;
|
||||||
foreach my $rec ([$extrasPath, $extrasDst],
|
foreach my $rec ([$extrasPath, $extrasDst], [$uploadsPath, $uploadsDst]) {
|
||||||
[$uploadsPath, $uploadsDst]) {
|
|
||||||
my ($path, $dst) = @$rec;
|
my ($path, $dst) = @$rec;
|
||||||
if (-l $dst) {
|
if (-l $dst) {
|
||||||
next if (readlink $dst eq $path);
|
next if (readlink $dst eq $path);
|
||||||
|
|
@ -201,21 +190,20 @@ sub _exportAsHtml {
|
||||||
rmdir $dst or return (0, sprintf($i18n->get('could not rmdir'), $dst, $!));
|
rmdir $dst or return (0, sprintf($i18n->get('could not rmdir'), $dst, $!));
|
||||||
symlink $path, $dst or return (0, sprintf($i18n->get('could not symlink'), $path, $dst, $!));
|
symlink $path, $dst or return (0, sprintf($i18n->get('could not symlink'), $path, $dst, $!));
|
||||||
}
|
}
|
||||||
} elsif ($extrasUploadsAction eq 'none') {
|
}
|
||||||
|
elsif ($extrasUploadsAction eq 'none') {
|
||||||
# Nothing. This is the default.
|
# Nothing. This is the default.
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($rootUrlAction eq 'symlinkDefault') {
|
if ($rootUrlAction eq 'symlinkDefault') {
|
||||||
if (defined $defaultAssetPath) {
|
if (defined $defaultAssetPath) {
|
||||||
{
|
my ($src, $dst) = ($defaultAssetPath, $exportPath.'/'.$index);
|
||||||
my ($src, $dst) = ($defaultAssetPath, $exportPath.'/'.$index);
|
$self->session->output->print($i18n->get('rootUrl symlinking default')."\n") unless $quiet;
|
||||||
$self->session->output->print($i18n->get('rootUrl symlinking default')."\n") unless $quiet;
|
if (-l $dst) {
|
||||||
if (-l $dst) {
|
last if (readlink $dst eq $src);
|
||||||
last if (readlink $dst eq $src);
|
unlink $dst or return (0, sprintf($i18n->get('could not unlink'), $dst, $!));
|
||||||
unlink $dst or return (0, sprintf($i18n->get('could not unlink'), $dst, $!));
|
|
||||||
}
|
|
||||||
symlink $src, $dst or return (0, sprintf($i18n->get('could not symlink'), $src, $dst, $!));
|
|
||||||
}
|
}
|
||||||
|
symlink $src, $dst or return (0, sprintf($i18n->get('could not symlink'), $src, $dst, $!));
|
||||||
} else {
|
} else {
|
||||||
$self->session->output->print($i18n->get('rootUrl default not present')."\n") unless $quiet;
|
$self->session->output->print($i18n->get('rootUrl default not present')."\n") unless $quiet;
|
||||||
}
|
}
|
||||||
|
|
@ -262,7 +250,7 @@ sub _translateUrlToPath {
|
||||||
my ($path,$name) = $url =~ m{(?:(.*) /)? ([^/]+) $}x; # NOTE: Might be more efficient to use index() and substr()
|
my ($path,$name) = $url =~ m{(?:(.*) /)? ([^/]+) $}x; # NOTE: Might be more efficient to use index() and substr()
|
||||||
|
|
||||||
# If it ends in a known file type handled by apache, use that
|
# If it ends in a known file type handled by apache, use that
|
||||||
if ($name =~ m{[.](?:html|htm|txt)$}) {
|
if ($name =~ m{[.](?:html|htm|txt|pdf|jpg|css|gif|png|doc|xls|xml|rss)$}) {
|
||||||
$dataRef->{'path' } = $path;
|
$dataRef->{'path' } = $path;
|
||||||
$dataRef->{'filename' } = $name;
|
$dataRef->{'filename' } = $name;
|
||||||
}
|
}
|
||||||
|
|
@ -384,7 +372,7 @@ sub www_exportStatus {
|
||||||
$iframeUrl = $self->session->url->append($iframeUrl, $formVar.'='.$self->session->form->process($formVar));
|
$iframeUrl = $self->session->url->append($iframeUrl, $formVar.'='.$self->session->form->process($formVar));
|
||||||
}
|
}
|
||||||
|
|
||||||
my $output = '<iframe src="'.$iframeUrl.'" title="'.$i18n->get('Page Export Status').'" width="410" height="200"></iframe>';
|
my $output = '<iframe src="'.$iframeUrl.'" title="'.$i18n->get('Page Export Status').'" width="700" height="500"></iframe>';
|
||||||
$self->getAdminConsole->render($output,$i18n->get('Page Export Status'),"Asset");
|
$self->getAdminConsole->render($output,$i18n->get('Page Export Status'),"Asset");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,12 +400,12 @@ sub www_exportGenerate {
|
||||||
$self->session->form->process('rootUrlAction'));
|
$self->session->form->process('rootUrlAction'));
|
||||||
if (!$success) {
|
if (!$success) {
|
||||||
$self->session->output->print($description,1);
|
$self->session->output->print($description,1);
|
||||||
return;
|
return "chunked";
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->session->output->print($description,1);
|
$self->session->output->print($description,1);
|
||||||
$self->session->output->print('<a target="_parent" href="'.$self->getUrl.'">'.$i18n->get(493,'WebGUI').'</a>');
|
$self->session->output->print('<a target="_parent" href="'.$self->getUrl.'">'.$i18n->get(493,'WebGUI').'</a>');
|
||||||
return;
|
return "chunked";
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -854,13 +854,6 @@ config file must be enabled for this function to be available.</p>
|
||||||
lastUpdated => 1129420080,
|
lastUpdated => 1129420080,
|
||||||
},
|
},
|
||||||
|
|
||||||
'file exists when making directory index' => {
|
|
||||||
message => q{Couldn't create %-s because %-s <br />}
|
|
||||||
. q{This most likely means you have a page with this URL already. }
|
|
||||||
. q{Altering that page's URL to not end with your directory index will fix this.},
|
|
||||||
lastUpdated => 0,
|
|
||||||
},
|
|
||||||
|
|
||||||
'could not create path' => {
|
'could not create path' => {
|
||||||
message => q|
|
message => q|
|
||||||
Couldn't create %-s because %-s <br />
|
Couldn't create %-s because %-s <br />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue