fixes for Gallery and Gallery Utility

This commit is contained in:
Doug Bell 2008-01-09 04:23:52 +00:00
parent afc2db4399
commit 6fcfa3f80d
3 changed files with 76 additions and 41 deletions

View file

@ -499,18 +499,26 @@ sub canView {
#----------------------------------------------------------------------------
=head2 getAlbumIds ( )
=head2 getAlbumIds ( options )
Gets an array reference of all the album IDs under this Gallery.
Gets an array reference of all the album IDs under this Gallery. C<options>
is a hash reference with the following keys.
orderBy => An SQL ORDER BY clause to sort the albums
=cut
sub getAlbumIds {
my $self = shift;
my $options = shift;
my $orderBy = $options->{ orderBy } || "lineage ASC";
$self->session->errorHandler->warn("ORDER BY: $orderBy");
my $assets
= $self->getLineage(['descendants'], {
includeOnlyClasses => ['WebGUI::Asset::Wobject::GalleryAlbum'],
orderByClause => $orderBy,
});
return $assets;
@ -525,17 +533,20 @@ hash reference with the following keys.
perpage => The number of results to show per page. Default: 20
For more C<options>, see L</getAlbumIds>.
=cut
sub getAlbumPaginator {
my $self = shift;
my $options = shift;
my $perpage = $options->{ perpage } || 20;
my $perpage = $options->{ perpage } || 20;
delete $options->{ perpage };
my $p
= WebGUI::Paginator->new( $self->session, $self->getUrl, $perpage );
$p->setDataByArrayRef( $self->getAlbumIds );
$p->setDataByArrayRef( $self->getAlbumIds( $options ) );
return $p;
}
@ -795,9 +806,12 @@ sub view_listAlbums {
my $var = $self->getTemplateVars;
my $form = $self->session->form;
my $orderBy = $self->get('viewListOrderBy')
. q{ } . $self->get('viewListOrderDirection');
my $p
= $self->getAlbumPaginator( {
perpage => $form->get('perpage'),
perpage => ( $form->get('perpage') || 20 ),
orderBy => $orderBy,
} );
$p->appendTemplateVars( $var );

View file

@ -60,7 +60,7 @@ This module is B<NOT> to be used by the Gallery asset itself!
multiple => 1,
}
);
=head1 METHODS
These methods are available from this class:
@ -152,21 +152,15 @@ sub addAlbumFromThread {
my $session = $gallery->session;
my $addOptions = { skipAutoCommitWorkflows => 1 };
# Get all the storage locations
my @storageIds = ();
for my $post ( @{ $thread->getPosts } ) {
if ( $post->get('storageId') ) {
push @storageIds, $post->get('storageId');
}
}
# Create the new album
my $album = $gallery->addChild({
className => 'WebGUI::Asset::Wobject::GalleryAlbum',
title => $thread->get('title'),
description => $thread->get('content'),
menuTitle => $thread->get('menuTitle'),
description => $thread->get('bodyText'),
ownerUserId => $thread->get('ownerUserId'),
synopsis => $thread->get('synopsis'),
title => $thread->get('title'),
url => $session->url->urlize( $gallery->get('url') . "/" . $thread->get('title') ),
userDefined1 => $thread->get('userDefined1'),
userDefined2 => $thread->get('userDefined2'),
userDefined3 => $thread->get('userDefined3'),
@ -174,23 +168,33 @@ sub addAlbumFromThread {
userDefined5 => $thread->get('userDefined5'),
}, undef, $thread->get('revisionDate'), $addOptions );
# Add a new Photo asset for each photo in the storage locations
for my $storageId ( @storageIds ) {
# Use WebGUI::Storage::Image to avoid thumbnails if there
my $storage = WebGUI::Storage::Image->get( $session, $storageId );
for my $filename ( @{$storage->getFiles} ) {
my $className = $gallery->getAssetClassForFile( $filename );
if ( !$className ) {
warn "Skipping $filename because Gallery doesn't handle this file type";
next;
for my $post ( @{ $thread->getPosts } ) {
if ( my $storageId = $post->get('storageId') ) {
# Use WebGUI::Storage::Image to avoid thumbnails if there
my $storage = WebGUI::Storage::Image->get( $session, $storageId );
for my $filename ( @{$storage->getFiles} ) {
my $className = $gallery->getAssetClassForFile( $filename );
if ( !$className ) {
warn "Skipping $filename because Gallery doesn't handle this file type";
next;
}
my $file = $album->addChild({
className => $className,
menuTitle => $filename,
ownerUserId => $post->get('ownerUserId'),
title => $filename,
url => $session->url->urlize( $album->get('url') . "/" . $filename ),
userDefined1 => $post->get('userDefined1'),
userDefined2 => $post->get('userDefined2'),
userDefined3 => $post->get('userDefined3'),
userDefined4 => $post->get('userDefined4'),
userDefined5 => $post->get('userDefined5'),
}, undef, $post->get('revisionDate'), $addOptions );
$file->setFile( $storage->getPath( $filename ) );
}
my $file = $album->addChild({
className => $className,
}, undef, $thread->get('revisionDate'), $addOptions );
$file->setFile( $storage->getPath( $filename ) );
}
}

View file

@ -48,10 +48,11 @@ my @threads;
for (0..2) {
push @threads, $collab->addChild({
className => 'WebGUI::Asset::Post::Thread',
title => "title$_",
content => "content$_",
menuTitle => "menuTitle$_",
bodyText => "bodyText$_",
ownerUserId => "3$_",
synopsis => "synopsis$_",
title => "title$_",
userDefined1 => "userDefined1$_",
userDefined2 => "userDefined2$_",
userDefined3 => "userDefined3$_",
@ -67,10 +68,10 @@ for (0..2) {
my @posts;
push @{$posts[0]}, $threads[0]->addChild({
className => 'WebGUI::Asset::Post',
title => "title",
content => "content00",
menuTitle => "menuTitle00",
bodyText => "bodyText00",
synopsis => "synopsis00",
title => "title00",
userDefined1 => "userDefined100",
userDefined2 => "userDefined200",
userDefined3 => "userDefined300",
@ -83,10 +84,11 @@ $posts[0][0]->getStorageLocation->addFileFromFilesystem(
# Thread fields mapped to album fields that should be migrated
my %threadFields = (
title => "title",
content => "description",
menuTitle => "menuTitle",
bodyText => "description",
ownerUserId => "ownerUserId",
synopsis => "synopsis",
title => "title",
userDefined1 => "userDefined1",
userDefined2 => "userDefined2",
userDefined3 => "userDefined3",
@ -97,8 +99,8 @@ my %threadFields = (
#----------------------------------------------------------------------------
# Tests
# addAlbumFromThread tests $thread[0] and @{$posts[0]}
my $threadPostTests = 4 * ( 1 + scalar @{ $posts[0] } );
# addAlbumFromThread adds 6 tests for $thread[0] and @{$posts[0]}
my $threadPostTests = 6 * ( 1 + scalar @{ $posts[0] } );
# addAlbumFromThread adds 1 test for each field in %threadFields
my $threadFieldTests = 1 * scalar keys %threadFields;
@ -138,6 +140,12 @@ is(
"addAlbumFromThread creates album with same revisionDate as thread",
);
my $galleryUrl = $gallery->get('url');
like(
$album->get('url'), qr/^$galleryUrl/,
"addAlbumFromThread creates album with url that begins with gallery's url",
);
# 1 test for each field in %threadFields
for my $oldField ( sort keys %threadFields ) {
is( $album->get( $threadFields{ $oldField } ), $threads[0]->get( $oldField ),
@ -150,14 +158,23 @@ is(
"addAlbumFromThread adds one file for each attachment to the thread or posts of the thread",
);
# 4 tests for each post/file
# 6 tests for each post/file
# TODO: Test that post-to-file fields are migrated properly, but how?
my $albumUrl = $album->get('url');
for my $fileId ( @{$album->getFileIds} ) {
my $file = WebGUI::Asset->newByDynamicClass( $session, $fileId );
is(
$file->get('revisionDate'), $threads[0]->get('revisionDate'),
"addAlbumFromThread adds files with same revisionDate as thread",
);
is(
$file->get('ownerUserId'), $threads[0]->get('ownerUserId'),
"addAlbumFromThread adds files with same ownerUserId as thread",
);
like(
$file->get('url'), qr/^$albumUrl/,
"addAlbumFromThread add files with urls that begin with GalleryAlbum url",
);
isa_ok( $file->getStorageLocation, 'WebGUI::Storage', 'Storage location exists' );
ok( $file->get('filename'), '"filename" property was set' );
cmp_deeply(