Add a progress bar to uploading zip archives in Gallery Albums. Fixes bug #10994.
This commit is contained in:
parent
9b74ab24cf
commit
c5e9abe10e
4 changed files with 62 additions and 16 deletions
|
|
@ -21,6 +21,7 @@ use Tie::IxHash;
|
|||
use WebGUI::International;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::HTML;
|
||||
use WebGUI::ProgressBar;
|
||||
|
||||
use Archive::Any;
|
||||
|
||||
|
|
@ -84,7 +85,7 @@ sub definition {
|
|||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 addArchive ( filename, properties )
|
||||
=head2 addArchive ( filename, properties, [$outputSub] )
|
||||
|
||||
Add an archive of Files to this Album. C<filename> is the full path of the
|
||||
archive. C<properties> is a hash reference of properties to assign to the
|
||||
|
|
@ -95,12 +96,27 @@ a directory outside of the storage location.
|
|||
|
||||
Will only handle file types handled by the parent Gallery.
|
||||
|
||||
=head3 filename
|
||||
|
||||
The name of the file archive to import.
|
||||
|
||||
=head3 properties
|
||||
|
||||
A base set of properties to add to each file in the archive.
|
||||
|
||||
=head3 $outputSub
|
||||
|
||||
A callback to use for outputting data, most likely to a progress bar. It expects the
|
||||
callback to accept an i18n key for use in sprintf, and then any extra fields to stuff
|
||||
into the translated key.
|
||||
|
||||
=cut
|
||||
|
||||
sub addArchive {
|
||||
my $self = shift;
|
||||
my $filename = shift;
|
||||
my $properties = shift;
|
||||
my $outputSub = shift || sub {};
|
||||
my $gallery = $self->getParent;
|
||||
|
||||
my $archive = Archive::Any->new( $filename );
|
||||
|
|
@ -109,11 +125,12 @@ sub addArchive {
|
|||
if $archive->is_naughty;
|
||||
|
||||
my $tempdirName = tempdir( "WebGUI-Gallery-XXXXXXXX", TMPDIR => 1, CLEANUP => 1);
|
||||
$outputSub->('Extracting archive');
|
||||
$archive->extract( $tempdirName );
|
||||
|
||||
# Get all the files in the archive
|
||||
my @files;
|
||||
my $wanted = sub { push @files, $File::Find::name };
|
||||
my $wanted = sub { push @files, $File::Find::name; $outputSub->('Found file: %s', $File::Find::name); };
|
||||
find( {
|
||||
wanted => $wanted,
|
||||
}, $tempdirName );
|
||||
|
|
@ -127,7 +144,8 @@ sub addArchive {
|
|||
next unless $class; # class is undef for those files the Gallery can't handle
|
||||
|
||||
$self->session->errorHandler->info( "Adding $filename to album!" );
|
||||
# Remove the file extention
|
||||
$outputSub->('Adding %s to album', $filename);
|
||||
# Remove the file extension
|
||||
$filename =~ s{\.[^.]+}{};
|
||||
|
||||
$properties->{ className } = $class;
|
||||
|
|
@ -143,6 +161,7 @@ sub addArchive {
|
|||
$versionTag->set({
|
||||
"workflowId" => $self->getParent->get("workflowIdCommit"),
|
||||
});
|
||||
$outputSub->('Requesting commit for version tag');
|
||||
$versionTag->requestCommit;
|
||||
|
||||
return undef;
|
||||
|
|
@ -918,7 +937,7 @@ sub www_addArchive {
|
|||
|
||||
my $i18n = WebGUI::International->new($session);
|
||||
|
||||
$var->{ error } = $params->{ error };
|
||||
$var->{ error } = $params->{ error } || $form->get('error');
|
||||
|
||||
$var->{ form_start }
|
||||
= WebGUI::Form::formHeader( $session, {
|
||||
|
|
@ -973,32 +992,27 @@ sub www_addArchiveSave {
|
|||
my $session = $self->session;
|
||||
my $form = $self->session->form;
|
||||
my $i18n = WebGUI::International->new( $session, 'Asset_GalleryAlbum' );
|
||||
my $pb = WebGUI::ProgressBar->new($session);
|
||||
my $properties = {
|
||||
keywords => $form->get("keywords"),
|
||||
friendsOnly => $form->get("friendsOnly"),
|
||||
};
|
||||
|
||||
$pb->start($i18n->get('Uploading archive'), $session->url->extras('adminConsole/assets.gif'));
|
||||
my $storageId = $form->get("archive", "File");
|
||||
my $storage = WebGUI::Storage->get( $session, $storageId );
|
||||
if (!$storage) {
|
||||
return $self->www_addArchive({
|
||||
error => sprintf $i18n->get('addArchive error too big'),
|
||||
});
|
||||
return $pb->finish($self->getUrl('func=addArchive;error='.$i18n->get('addArchive error too big')));
|
||||
}
|
||||
my $filename = $storage->getPath( $storage->getFiles->[0] );
|
||||
|
||||
eval { $self->addArchive( $filename, $properties ) };
|
||||
eval { $self->addArchive( $filename, $properties, sub{ $pb->update(sprintf $i18n->get(shift), @_); }); };
|
||||
$storage->delete;
|
||||
if ( my $error = $@ ) {
|
||||
return $self->www_addArchive({
|
||||
error => sprintf( $i18n->get('addArchive error generic'), $error ),
|
||||
});
|
||||
return $pb->finish($self->getUrl('func=addArchive;error='.sprintf $i18n->get('addArchive error generic'), $error ));
|
||||
}
|
||||
|
||||
$storage->delete;
|
||||
|
||||
return $self->processStyle(
|
||||
sprintf $i18n->get('addArchive message'), $self->getUrl,
|
||||
);
|
||||
return $pb->finish($self->getUrl);
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -82,6 +82,7 @@ sub finish {
|
|||
parent.location.href='%s';
|
||||
</script>
|
||||
EOJS
|
||||
local $| = 1;
|
||||
$self->session->output->print($text . $self->{_foot}, 1); # skipMacros
|
||||
return 'chunked';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -597,6 +597,36 @@ our $I18N = {
|
|||
context => 'Label for URL to add an album Description.',
|
||||
},
|
||||
|
||||
'Uploading archive' => {
|
||||
message => 'Uploading archive',
|
||||
lastUpdated => 1237403498,
|
||||
context => 'label for progress bar in addArchive',
|
||||
},
|
||||
|
||||
'Extracting archive' => {
|
||||
message => 'Extracting archive',
|
||||
lastUpdated => 1237403498,
|
||||
context => 'label for progress bar in addArchive',
|
||||
},
|
||||
|
||||
'Found file: %s' => {
|
||||
message => 'Found file %s',
|
||||
lastUpdated => 1237403498,
|
||||
context => 'label for progress bar in addArchive',
|
||||
},
|
||||
|
||||
'Adding %s to album' => {
|
||||
message => 'Adding %s to album',
|
||||
lastUpdated => 1237403498,
|
||||
context => 'label for progress bar in addArchive',
|
||||
},
|
||||
|
||||
'Requesting commit for version tag' => {
|
||||
message => 'Requesting commit for version tag',
|
||||
lastUpdated => 1237403498,
|
||||
context => 'label for progress bar in addArchive',
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue