Replaced CLI gallery import system with a better one.
This commit is contained in:
parent
d902c7ec79
commit
aa9f0e8396
10 changed files with 464 additions and 1073 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
- fixed: Colorpicker window would not open (Martin Kamerbeek / Oqapi)
|
- fixed: Colorpicker window would not open (Martin Kamerbeek / Oqapi)
|
||||||
- fixed: Reverted change to RichEdit that caused IE6 to stop working
|
- fixed: Reverted change to RichEdit that caused IE6 to stop working
|
||||||
- fixed: Subscription: Price not displaying
|
- fixed: Subscription: Price not displaying
|
||||||
|
- Replaced CLI gallery import system with a better one.
|
||||||
- fixed: Flat Discount Coupon: Add to Cart button seems broken
|
- fixed: Flat Discount Coupon: Add to Cart button seems broken
|
||||||
- fixed: Deleting unProtected user profile fields
|
- fixed: Deleting unProtected user profile fields
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ use Getopt::Long;
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::Storage;
|
use WebGUI::Storage;
|
||||||
use WebGUI::Asset;
|
use WebGUI::Asset;
|
||||||
|
use File::Path;
|
||||||
|
|
||||||
my $toVersion = '7.5.15';
|
my $toVersion = '7.5.15';
|
||||||
my $quiet; # this line required
|
my $quiet; # this line required
|
||||||
|
|
@ -28,19 +28,21 @@ my $quiet; # this line required
|
||||||
|
|
||||||
my $session = start(); # this line required
|
my $session = start(); # this line required
|
||||||
|
|
||||||
# upgrade functions go here
|
removeOldGalleryImport($session);
|
||||||
|
|
||||||
finish($session); # this line required
|
finish($session); # this line required
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Describe what our function does
|
sub removeOldGalleryImport {
|
||||||
#sub exampleFunction {
|
my $session = shift;
|
||||||
# my $session = shift;
|
print "\tRemoving old gallery import mechanism... " unless $quiet;
|
||||||
# print "\tWe're doing some stuff here that you should know about... " unless $quiet;
|
unlink "../../sbin/migrateCollabToGallery.pl";
|
||||||
# # and here's our code
|
unlink "../../sbin/migrateFolderToGallery.pl";
|
||||||
# print "DONE!\n" unless $quiet;
|
rmtree "../../lib/WebGUI/Utility";
|
||||||
#}
|
rmtree "../../t/Utility/Gallery";
|
||||||
|
print "DONE!\n" unless $quiet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
|
# -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package WebGUI::Asset::Wobject::Gallery;
|
package WebGUI::Asset::Wobject::Gallery;
|
||||||
|
|
||||||
$VERSION = "1.0.0";
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package WebGUI::Asset::Wobject::GalleryAlbum;
|
package WebGUI::Asset::Wobject::GalleryAlbum;
|
||||||
|
|
||||||
$VERSION = "1.0.0";
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -1,289 +0,0 @@
|
||||||
package WebGUI::Utility::Gallery;
|
|
||||||
|
|
||||||
=head1 LEGAL
|
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
Please read the legal notices (docs/legal.txt) and the license
|
|
||||||
(docs/license.txt) that came with this distribution before using
|
|
||||||
this software.
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
http://www.plainblack.com info@plainblack.com
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use Carp qw( carp croak );
|
|
||||||
use File::Find;
|
|
||||||
use Scalar::Util qw( blessed );
|
|
||||||
use WebGUI::Asset::Wobject::Collaboration;
|
|
||||||
use WebGUI::Asset::Wobject::Gallery;
|
|
||||||
use WebGUI::Asset::Post::Thread;
|
|
||||||
use WebGUI::Storage::Image;
|
|
||||||
|
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
WebGUI::Utility::Gallery -- Utility functions for working
|
|
||||||
with Gallery assets.
|
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
|
||||||
|
|
||||||
This module provides utility functions to work with Gallery assets from
|
|
||||||
utility scripts.
|
|
||||||
|
|
||||||
This module is B<NOT> to be used by the Gallery asset itself!
|
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
|
||||||
|
|
||||||
use WebGUI::Utility::Gallery;
|
|
||||||
my $utility = "WebGUI::Utility::Gallery" # <- not as cumbersome
|
|
||||||
|
|
||||||
# Add albums from a collaboration system's threads
|
|
||||||
my $gallery = WebGUI::Asset::Wobject::Gallery->new( ... );
|
|
||||||
my $collab = WebGUI::Asset::Wobject::Collaboration->new( ... );
|
|
||||||
$utility->addAlbumFromCollaboration( $gallery, $collab );
|
|
||||||
|
|
||||||
# Add a single album from a collaboration system thread
|
|
||||||
my $thread = WebGUI::Asset::Post::Thread->new( ... );
|
|
||||||
$utility->addAlbumFromThread( $gallery, $thread );
|
|
||||||
|
|
||||||
# Add a single album from a Folder asset
|
|
||||||
my $folder = WebGUI::Asset::Wobject::Folder->new( ... );
|
|
||||||
$utility->addAlbumFromFolder( $gallery, $folder );
|
|
||||||
|
|
||||||
# Add a single album from a filesystem branch
|
|
||||||
$utility->addAlbumFromFilesystem( $gallery, "/Users/Doug/Photos" );
|
|
||||||
|
|
||||||
# Add a single album for every folder in a filesystem branch
|
|
||||||
$utility->addAlbumFromFilesystem(
|
|
||||||
$gallery, "/Users/Doug/Photos",
|
|
||||||
{
|
|
||||||
multiple => 1,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
=head1 METHODS
|
|
||||||
|
|
||||||
These methods are available from this class:
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 addAlbumFromCollaboration ( gallery, collab )
|
|
||||||
|
|
||||||
Add an album or albums to the gallery from the given Collaboration System.
|
|
||||||
C<gallery> is an instanciated Gallery asset. C<collab> is an instanciated
|
|
||||||
Collaboration System asset.
|
|
||||||
|
|
||||||
Will add one album for every thread in the Collaboration System. Will call
|
|
||||||
C<addAlbumFromThread> to do its dirty work.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub addAlbumFromCollaboration {
|
|
||||||
my $class = shift;
|
|
||||||
my $gallery = shift;
|
|
||||||
my $collab = shift;
|
|
||||||
|
|
||||||
croak "First argument must be Gallery asset"
|
|
||||||
unless blessed $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery');
|
|
||||||
croak "Second argument must be Collaboration System asset"
|
|
||||||
unless blessed $collab && $collab->isa('WebGUI::Asset::Wobject::Collaboration');
|
|
||||||
|
|
||||||
my $threads
|
|
||||||
= $collab->getLineage(['descendants'], {
|
|
||||||
returnObjects => 1,
|
|
||||||
includeOnlyClasses => ['WebGUI::Asset::Post::Thread'],
|
|
||||||
statesToInclude => ['published'],
|
|
||||||
statusToInclude => ['approved', 'archived', 'pending'],
|
|
||||||
});
|
|
||||||
|
|
||||||
for my $thread ( @$threads ) {
|
|
||||||
$class->addAlbumFromThread( $gallery, $thread );
|
|
||||||
}
|
|
||||||
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 addAlbumFromFilesystem ( gallery, root [, options] )
|
|
||||||
|
|
||||||
Add an album to the gallery from the file system. C<gallery> is an
|
|
||||||
instanciated Gallery asset. C<root> is a location on the file system.
|
|
||||||
|
|
||||||
C<options> is a hash reference of options with the following keys:
|
|
||||||
|
|
||||||
multiple - Create multiple albums, one for each folder.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub addAlbumFromFilesystem {
|
|
||||||
my $class = shift;
|
|
||||||
my $gallery = shift;
|
|
||||||
my $root = shift;
|
|
||||||
my $options = shift;
|
|
||||||
|
|
||||||
# TODO!!!
|
|
||||||
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 addAlbumFromFolder ( gallery, folder )
|
|
||||||
|
|
||||||
Add an album from a Folder asset filled with File assets. C<gallery> is an
|
|
||||||
instance of a Gallery asset. C<folder> is an instance of a Folder asset.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub addAlbumFromFolder {
|
|
||||||
my $class = shift;
|
|
||||||
my $gallery = shift;
|
|
||||||
my $folder = shift;
|
|
||||||
|
|
||||||
croak "First argument must be Gallery asset"
|
|
||||||
unless blessed $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery');
|
|
||||||
croak "Second argument must be Folder asset"
|
|
||||||
unless blessed $folder && $folder->isa('WebGUI::Asset::Wobject::Folder');
|
|
||||||
|
|
||||||
my $session = $gallery->session;
|
|
||||||
my $addOptions = { skipAutoCommitWorkflows => 1 };
|
|
||||||
|
|
||||||
# Create the new album
|
|
||||||
my $album = $gallery->addChild({
|
|
||||||
className => 'WebGUI::Asset::Wobject::GalleryAlbum',
|
|
||||||
description => $folder->get('description'),
|
|
||||||
menuTitle => $folder->get('menuTitle'),
|
|
||||||
createdBy => $folder->get('createdBy'),
|
|
||||||
creationDate => $folder->get('creationDate'),
|
|
||||||
ownerUserId => $folder->get('ownerUserId'),
|
|
||||||
synopsis => $folder->get('synopsis'),
|
|
||||||
title => $folder->get('title'),
|
|
||||||
url => $session->url->urlize( $gallery->get('url') . "/" . $folder->get('title') ),
|
|
||||||
}, undef, $folder->get('revisionDate'), $addOptions );
|
|
||||||
|
|
||||||
my $fileIds
|
|
||||||
= $folder->getLineage( ['children'], {
|
|
||||||
joinClass => 'WebGUI::Asset::File',
|
|
||||||
} );
|
|
||||||
|
|
||||||
for my $fileId ( @{ $fileIds } ) {
|
|
||||||
my $oldFile = WebGUI::Asset->newByDynamicClass( $session, $fileId );
|
|
||||||
my $oldStorage = $oldFile->getStorageLocation;
|
|
||||||
my $className = $gallery->getAssetClassForFile( $oldStorage->getPath( $oldFile->get('filename') ) );
|
|
||||||
if ( !$className ) {
|
|
||||||
warn "Skipping " . $oldFile->get('filename') . " Gallery doesn't handle this file type";
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $newFile = $album->addChild({
|
|
||||||
className => $className,
|
|
||||||
createdBy => $oldFile->get('createdBy'),
|
|
||||||
creationDate => $oldFile->get('creationDate'),
|
|
||||||
menuTitle => $oldFile->get('menuTitle'),
|
|
||||||
ownerUserId => $oldFile->get('ownerUserId'),
|
|
||||||
synopsis => $oldFile->get('synopsis'),
|
|
||||||
title => $oldFile->get('title'),
|
|
||||||
url => $session->url->urlize( $album->get('url') . "/" . $oldFile->get('menuTitle') ),
|
|
||||||
}, undef, $oldFile->get('revisionDate'), $addOptions );
|
|
||||||
|
|
||||||
$newFile->setFile( $oldStorage->getPath( $oldFile->get('filename') ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 addAlbumFromThread ( gallery, thread )
|
|
||||||
|
|
||||||
Add an album to the gallery from the given Collaboration System thread.
|
|
||||||
C<gallery> is an instanciated Gallery asset. C<thread> is an instanciated
|
|
||||||
Thread asset.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub addAlbumFromThread {
|
|
||||||
my $class = shift;
|
|
||||||
my $gallery = shift;
|
|
||||||
my $thread = shift;
|
|
||||||
|
|
||||||
croak "First argument must be Gallery asset"
|
|
||||||
unless blessed $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery');
|
|
||||||
croak "Second argument must be Thread asset"
|
|
||||||
unless blessed $thread && $thread->isa('WebGUI::Asset::Post::Thread');
|
|
||||||
|
|
||||||
my $session = $gallery->session;
|
|
||||||
my $addOptions = { skipAutoCommitWorkflows => 1 };
|
|
||||||
|
|
||||||
# Create the new album
|
|
||||||
my $album = $gallery->addChild({
|
|
||||||
className => 'WebGUI::Asset::Wobject::GalleryAlbum',
|
|
||||||
description => $thread->get('content'),
|
|
||||||
menuTitle => $thread->get('menuTitle'),
|
|
||||||
createdBy => $thread->get('createdBy'),
|
|
||||||
creationDate => $thread->get('creationDate'),
|
|
||||||
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'),
|
|
||||||
userDefined4 => $thread->get('userDefined4'),
|
|
||||||
userDefined5 => $thread->get('userDefined5'),
|
|
||||||
}, undef, $thread->get('revisionDate'), $addOptions );
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get rid of that file extention
|
|
||||||
my ($title) = $filename =~ m{(.*)\.[^.]*$};
|
|
||||||
|
|
||||||
# Don't repeat the thread
|
|
||||||
my $synopsis
|
|
||||||
= $post->get('content') ne $thread->get('content')
|
|
||||||
? $post->get('content')
|
|
||||||
: undef
|
|
||||||
;
|
|
||||||
|
|
||||||
my $file = $album->addChild({
|
|
||||||
className => $className,
|
|
||||||
createdBy => $post->get('createdBy'),
|
|
||||||
creationDate => $post->get('creationDate'),
|
|
||||||
menuTitle => $title,
|
|
||||||
ownerUserId => $post->get('ownerUserId'),
|
|
||||||
synopsis => $synopsis,
|
|
||||||
title => $title,
|
|
||||||
url => $session->url->urlize( $album->get('url') . "/" . $title ),
|
|
||||||
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 ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
|
||||||
452
sbin/galleryImport.pl
Normal file
452
sbin/galleryImport.pl
Normal file
|
|
@ -0,0 +1,452 @@
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
# Please read the legal notices (docs/legal.txt) and the license
|
||||||
|
# (docs/license.txt) that came with this distribution before using
|
||||||
|
# this software.
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
# http://www.plainblack.com info@plainblack.com
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
|
||||||
|
$|=1;
|
||||||
|
use lib '../lib';
|
||||||
|
use strict;
|
||||||
|
use Carp qw( carp croak );
|
||||||
|
use File::Find;
|
||||||
|
use Getopt::Long;
|
||||||
|
use Pod::Usage;
|
||||||
|
use Scalar::Util qw( blessed );
|
||||||
|
use WebGUI::Asset::Wobject::Collaboration;
|
||||||
|
use WebGUI::Asset::Wobject::GalleryAlbum;
|
||||||
|
use WebGUI::Asset::Wobject::Gallery;
|
||||||
|
use WebGUI::Asset::Wobject::Folder;
|
||||||
|
use WebGUI::Asset::Post::Thread;
|
||||||
|
use WebGUI::Storage::Image;
|
||||||
|
|
||||||
|
|
||||||
|
# custom flags
|
||||||
|
my ($fromAssetId, $fromPath, $fromAssetUrl, $toId, $toUrl) = undef;
|
||||||
|
|
||||||
|
# init
|
||||||
|
my $session = start();
|
||||||
|
|
||||||
|
# load gallery
|
||||||
|
my $gallery = undef;
|
||||||
|
if (defined $toId) {
|
||||||
|
$gallery = WebGUI::Asset::Wobject::Gallery->new($session, $toId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$gallery = WebGUI::Asset::Wobject::Gallery->newByUrl($session, $toUrl);
|
||||||
|
}
|
||||||
|
if ( $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery') ) {
|
||||||
|
# import from
|
||||||
|
if (defined $fromPath) {
|
||||||
|
if (-d $fromPath) {
|
||||||
|
addAlbumFromFilesystem($gallery,$fromPath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pod2usage("$0: You must specify a valid directory to import from.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my $fromAsset = undef;
|
||||||
|
if (defined $fromAssetId) {
|
||||||
|
$fromAsset = WebGUI::Asset->newByDynamicClass($session, $fromAssetId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$fromAsset = WebGUI::Asset->newByUrl($session, $fromAssetUrl);
|
||||||
|
}
|
||||||
|
if ($fromAsset && $fromAsset->isa("WebGUI::Asset::Wobject::Folder")) {
|
||||||
|
addAlbumFromFolder($gallery, $fromAsset);
|
||||||
|
}
|
||||||
|
elsif ($fromAsset && $fromAsset->isa("WebGUI::Asset::Wobject::Collaboration")) {
|
||||||
|
addAlbumFromCollaboration($gallery, $fromAsset);
|
||||||
|
}
|
||||||
|
elsif ($fromAsset && $fromAsset->isa("WebGUI::Asset::Post::Thread")) {
|
||||||
|
addAlbumFromThread($gallery, $fromAsset);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pod2usage("$0: You must specify a valid asset to import from.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pod2usage("$0: You must specify a gallery asset to import into.");
|
||||||
|
}
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
finish($session);
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# addAlbumFromCollaboration ( gallery, collab )
|
||||||
|
#
|
||||||
|
# Add an album or albums to the gallery from the given Collaboration System.
|
||||||
|
# gallery is an instanciated Gallery asset. collab is an instanciated
|
||||||
|
# Collaboration System asset.
|
||||||
|
#
|
||||||
|
# Will add one album for every thread in the Collaboration System. Will call
|
||||||
|
# addAlbumFromThread to do its dirty work.
|
||||||
|
|
||||||
|
sub addAlbumFromCollaboration {
|
||||||
|
my $gallery = shift;
|
||||||
|
my $collab = shift;
|
||||||
|
|
||||||
|
croak "First argument must be Gallery asset"
|
||||||
|
unless blessed $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery');
|
||||||
|
croak "Second argument must be Collaboration System asset"
|
||||||
|
unless blessed $collab && $collab->isa('WebGUI::Asset::Wobject::Collaboration');
|
||||||
|
|
||||||
|
my $threads
|
||||||
|
= $collab->getLineage(['descendants'], {
|
||||||
|
returnObjects => 1,
|
||||||
|
includeOnlyClasses => ['WebGUI::Asset::Post::Thread'],
|
||||||
|
statesToInclude => ['published'],
|
||||||
|
statusToInclude => ['approved', 'archived', 'pending'],
|
||||||
|
});
|
||||||
|
|
||||||
|
for my $thread ( @$threads ) {
|
||||||
|
addAlbumFromThread( $gallery, $thread );
|
||||||
|
}
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# addAlbumFromFilesystem ( gallery, root )
|
||||||
|
#
|
||||||
|
# Add an album to the gallery from the file system. gallery is an
|
||||||
|
# instanciated Gallery asset. root is a location on the file system.
|
||||||
|
|
||||||
|
sub addAlbumFromFilesystem {
|
||||||
|
my $gallery = shift;
|
||||||
|
my $root = shift;
|
||||||
|
|
||||||
|
croak "First argument must be Gallery asset"
|
||||||
|
unless blessed $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery');
|
||||||
|
croak "Second argument must be a path to a folder on the filesystem"
|
||||||
|
unless -d $root;
|
||||||
|
|
||||||
|
# define the import process
|
||||||
|
my $recurseFilesystem = sub {
|
||||||
|
if (-d $File::Find::name) {
|
||||||
|
# find photos
|
||||||
|
print "Searching ".$File::Find::name." for photos.\n";
|
||||||
|
my @photos = ();
|
||||||
|
if (opendir my $folder, $File::Find::name) {
|
||||||
|
my @files = readdir $folder;
|
||||||
|
closedir $folder;
|
||||||
|
foreach my $file (@files) {
|
||||||
|
unless (-d $File::Find::name."/".$file) {
|
||||||
|
if ($file =~ m/\.(jpg|gif|png|jpeg)$/i) {
|
||||||
|
push(@photos, $file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# import if we found anything
|
||||||
|
if (scalar(@photos)) {
|
||||||
|
# get album name
|
||||||
|
my $albumName = $File::Find::name;
|
||||||
|
$albumName =~ s{.*\/([A-Za-z0-9\.-_\s]+)$}{$1};
|
||||||
|
|
||||||
|
# create album
|
||||||
|
print "Creating album $albumName\n";
|
||||||
|
my $addOptions = { skipAutoCommitWorkflows => 1 };
|
||||||
|
my $album = $gallery->addChild({
|
||||||
|
className => 'WebGUI::Asset::Wobject::GalleryAlbum',
|
||||||
|
menuTitle => $albumName,
|
||||||
|
title => $albumName,
|
||||||
|
url => $gallery->get('url') . "/" . $albumName,
|
||||||
|
}, undef, undef, $addOptions );
|
||||||
|
|
||||||
|
# do the import
|
||||||
|
print "\tImporting ".scalar(@photos)." files from ".$File::Find::name." into album called ".$albumName.".\n";
|
||||||
|
foreach my $filename (@photos) {
|
||||||
|
print "\t\t".$filename."\n";
|
||||||
|
my $className = $gallery->getAssetClassForFile( $filename );
|
||||||
|
if ( !$className ) {
|
||||||
|
warn "Skipping $filename because Gallery doesn't handle this file type";
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
my ($title) = $filename =~ m{(.*)\.[^.]*$};
|
||||||
|
my $asset = $album->addChild({
|
||||||
|
className => $className,
|
||||||
|
menuTitle => $title,
|
||||||
|
title => $title,
|
||||||
|
url => $album->get('url') . "/" . $title,
|
||||||
|
}, undef, undef, $addOptions );
|
||||||
|
$asset->setFile( $File::Find::name."/".$filename );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
# run the search and import process
|
||||||
|
File::Find::find({wanted=>$recurseFilesystem,no_chdir=>1} , $root);
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# addAlbumFromFolder ( gallery, folder )
|
||||||
|
#
|
||||||
|
# Add an album from a Folder asset filled with File assets. gallery is an
|
||||||
|
# instance of a Gallery asset. folder is an instance of a Folder asset.
|
||||||
|
|
||||||
|
sub addAlbumFromFolder {
|
||||||
|
my $gallery = shift;
|
||||||
|
my $folder = shift;
|
||||||
|
|
||||||
|
croak "First argument must be Gallery asset"
|
||||||
|
unless blessed $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery');
|
||||||
|
croak "Second argument must be Folder asset"
|
||||||
|
unless blessed $folder && $folder->isa('WebGUI::Asset::Wobject::Folder');
|
||||||
|
|
||||||
|
my $session = $gallery->session;
|
||||||
|
my $addOptions = { skipAutoCommitWorkflows => 1 };
|
||||||
|
|
||||||
|
# Create the new album
|
||||||
|
my $album = $gallery->addChild({
|
||||||
|
className => 'WebGUI::Asset::Wobject::GalleryAlbum',
|
||||||
|
description => $folder->get('description'),
|
||||||
|
menuTitle => $folder->get('menuTitle'),
|
||||||
|
createdBy => $folder->get('createdBy'),
|
||||||
|
creationDate => $folder->get('creationDate'),
|
||||||
|
ownerUserId => $folder->get('ownerUserId'),
|
||||||
|
synopsis => $folder->get('synopsis'),
|
||||||
|
title => $folder->get('title'),
|
||||||
|
url => $gallery->get('url') . "/" . $folder->get('title'),
|
||||||
|
}, undef, $folder->get('revisionDate'), $addOptions );
|
||||||
|
|
||||||
|
my $fileIds
|
||||||
|
= $folder->getLineage( ['children'], {
|
||||||
|
joinClass => 'WebGUI::Asset::File',
|
||||||
|
} );
|
||||||
|
|
||||||
|
for my $fileId ( @{ $fileIds } ) {
|
||||||
|
my $oldFile = WebGUI::Asset->newByDynamicClass( $session, $fileId );
|
||||||
|
my $oldStorage = $oldFile->getStorageLocation;
|
||||||
|
my $className = $gallery->getAssetClassForFile( $oldStorage->getPath( $oldFile->get('filename') ) );
|
||||||
|
if ( !$className ) {
|
||||||
|
warn "Skipping " . $oldFile->get('filename') . " Gallery doesn't handle this file type";
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $newFile = $album->addChild({
|
||||||
|
className => $className,
|
||||||
|
createdBy => $oldFile->get('createdBy'),
|
||||||
|
creationDate => $oldFile->get('creationDate'),
|
||||||
|
menuTitle => $oldFile->get('menuTitle'),
|
||||||
|
ownerUserId => $oldFile->get('ownerUserId'),
|
||||||
|
synopsis => $oldFile->get('synopsis'),
|
||||||
|
title => $oldFile->get('title'),
|
||||||
|
url => $album->get('url') . "/" . $oldFile->get('menuTitle'),
|
||||||
|
}, undef, $oldFile->get('revisionDate'), $addOptions );
|
||||||
|
|
||||||
|
$newFile->setFile( $oldStorage->getPath( $oldFile->get('filename') ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# addAlbumFromThread ( gallery, thread )
|
||||||
|
#
|
||||||
|
# Add an album to the gallery from the given Collaboration System thread.
|
||||||
|
# gallery is an instanciated Gallery asset. thread is an instanciated
|
||||||
|
# Thread asset.
|
||||||
|
|
||||||
|
sub addAlbumFromThread {
|
||||||
|
my $gallery = shift;
|
||||||
|
my $thread = shift;
|
||||||
|
|
||||||
|
croak "First argument must be Gallery asset"
|
||||||
|
unless blessed $gallery && $gallery->isa('WebGUI::Asset::Wobject::Gallery');
|
||||||
|
croak "Second argument must be Thread asset"
|
||||||
|
unless blessed $thread && $thread->isa('WebGUI::Asset::Post::Thread');
|
||||||
|
|
||||||
|
my $session = $gallery->session;
|
||||||
|
my $addOptions = { skipAutoCommitWorkflows => 1 };
|
||||||
|
|
||||||
|
# Create the new album
|
||||||
|
my $album = $gallery->addChild({
|
||||||
|
className => 'WebGUI::Asset::Wobject::GalleryAlbum',
|
||||||
|
description => $thread->get('content'),
|
||||||
|
menuTitle => $thread->get('menuTitle'),
|
||||||
|
createdBy => $thread->get('createdBy'),
|
||||||
|
creationDate => $thread->get('creationDate'),
|
||||||
|
ownerUserId => $thread->get('ownerUserId'),
|
||||||
|
synopsis => $thread->get('synopsis'),
|
||||||
|
title => $thread->get('title'),
|
||||||
|
url => $gallery->get('url') . "/" . $thread->get('title'),
|
||||||
|
userDefined1 => $thread->get('userDefined1'),
|
||||||
|
userDefined2 => $thread->get('userDefined2'),
|
||||||
|
userDefined3 => $thread->get('userDefined3'),
|
||||||
|
userDefined4 => $thread->get('userDefined4'),
|
||||||
|
userDefined5 => $thread->get('userDefined5'),
|
||||||
|
}, undef, $thread->get('revisionDate'), $addOptions );
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get rid of that file extention
|
||||||
|
my ($title) = $filename =~ m{(.*)\.[^.]*$};
|
||||||
|
|
||||||
|
# Don't repeat the thread
|
||||||
|
my $synopsis
|
||||||
|
= $post->get('content') ne $thread->get('content')
|
||||||
|
? $post->get('content')
|
||||||
|
: undef
|
||||||
|
;
|
||||||
|
|
||||||
|
my $file = $album->addChild({
|
||||||
|
className => $className,
|
||||||
|
createdBy => $post->get('createdBy'),
|
||||||
|
creationDate => $post->get('creationDate'),
|
||||||
|
menuTitle => $title,
|
||||||
|
ownerUserId => $post->get('ownerUserId'),
|
||||||
|
synopsis => $synopsis,
|
||||||
|
title => $title,
|
||||||
|
url => $album->get('url') . "/" . $title,
|
||||||
|
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 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub finish {
|
||||||
|
my $session = shift;
|
||||||
|
|
||||||
|
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||||
|
$versionTag->commit;
|
||||||
|
|
||||||
|
$session->var->end;
|
||||||
|
$session->close;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub start {
|
||||||
|
$| = 1; #disable output buffering
|
||||||
|
my ($configFile, $help);
|
||||||
|
GetOptions(
|
||||||
|
'configFile=s' => \$configFile,
|
||||||
|
'help' => \$help,
|
||||||
|
'toUrl=s' => \$toUrl,
|
||||||
|
'fromAssetUrl=s' => \$fromAssetUrl,
|
||||||
|
'toId=s' => \$toId,
|
||||||
|
'fromAssetId=s' => \$fromAssetId,
|
||||||
|
'fromPath=s' => \$fromPath,
|
||||||
|
);
|
||||||
|
|
||||||
|
# Show usage
|
||||||
|
if ($help) {
|
||||||
|
pod2usage( verbose => 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
unless ($configFile) {
|
||||||
|
pod2usage("$0: Must specify a --configFile");
|
||||||
|
}
|
||||||
|
|
||||||
|
my $session = WebGUI::Session->open("..",$configFile);
|
||||||
|
$session->user({userId=>3});
|
||||||
|
|
||||||
|
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
||||||
|
$versionTag->set({name => 'Import Albums into Gallery'});
|
||||||
|
|
||||||
|
return $session;
|
||||||
|
}
|
||||||
|
|
||||||
|
__END__
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
galleryImport.pl - Import media into a Gallery asset from various sources.
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
perl galleryImport.pl --configFile=www.example.com.conf --fromAssetId=XXXXXXXXXXXXXXXXXXXXXX --toId=XXXXXXXXXXXXXXXXXXXXXX
|
||||||
|
|
||||||
|
perl galleryImport.pl --help
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
This WebGUI utility script imports files from the filesystem, and other assets
|
||||||
|
into a Gallery asset. It automatically generates thumbnails and metadata just
|
||||||
|
as if the files were uploaded through the user interface.
|
||||||
|
|
||||||
|
Files with JPG, JPEG, GIF, and PNG extensions are supported.
|
||||||
|
|
||||||
|
The thumbnails are created using L<Image::Magick> for image transformations.
|
||||||
|
|
||||||
|
Exactly one --from* and exactly one --to* parameter are required.
|
||||||
|
|
||||||
|
=over
|
||||||
|
|
||||||
|
=item B<--configFile filename>
|
||||||
|
|
||||||
|
Specify the config file name of the site you wish to perform this import on.
|
||||||
|
|
||||||
|
=item B<--fromAssetId assetId>
|
||||||
|
|
||||||
|
Specify the asset id of an asset to import the files from. The asset type is
|
||||||
|
automatically discerned.
|
||||||
|
|
||||||
|
The supported asset types are Collaboration System, Thread, and Folder.
|
||||||
|
|
||||||
|
=item B<--fromAssetUrl url>
|
||||||
|
|
||||||
|
Specify the URL of an asset to import the files from. The asset type is
|
||||||
|
automatically discerned. The B<url> is the Asset URL parameter, not a fully
|
||||||
|
qualified URL.
|
||||||
|
|
||||||
|
The supported asset types are Collaboration System, Thread, and Folder.
|
||||||
|
|
||||||
|
=item B<--fromPath path>
|
||||||
|
|
||||||
|
Specify the absolute B<path> to a folder containing folders images and other
|
||||||
|
folders with images. The folder name is used to create an album name, and the
|
||||||
|
files contained in the folder are added as photos in the folder.
|
||||||
|
|
||||||
|
=item B<--help>
|
||||||
|
|
||||||
|
Shows this documentation, then exits.
|
||||||
|
|
||||||
|
=item B<--toId assetId>
|
||||||
|
|
||||||
|
Specify the B<assetId> of the Gallery to create albums in.
|
||||||
|
|
||||||
|
=item B<--toUrl url>
|
||||||
|
|
||||||
|
Specify the B<url> of the Gallery to create albums in. The URL is the asset
|
||||||
|
URL parameter of the Gallery, and not the fully qualified URL.
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
=head1 AUTHOR
|
||||||
|
|
||||||
|
Copyright 2001-2008 Plain Black Corporation.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,159 +0,0 @@
|
||||||
#-------------------------------------------------------------------
|
|
||||||
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
# Please read the legal notices (docs/legal.txt) and the license
|
|
||||||
# (docs/license.txt) that came with this distribution before using
|
|
||||||
# this software.
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
# http://www.plainblack.com info@plainblack.com
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
our ($webguiRoot);
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
$webguiRoot = "..";
|
|
||||||
unshift (@INC, $webguiRoot."/lib");
|
|
||||||
}
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use Getopt::Long;
|
|
||||||
use Pod::Usage;
|
|
||||||
use WebGUI::Utility::Gallery;
|
|
||||||
use WebGUI::Session;
|
|
||||||
|
|
||||||
my $session = start();
|
|
||||||
|
|
||||||
my $collab = getCollaborationFromArgs();
|
|
||||||
my $gallery = getGalleryFromArgs();
|
|
||||||
|
|
||||||
WebGUI::Utility::Gallery->addAlbumFromCollaboration( $gallery, $collab );
|
|
||||||
|
|
||||||
finish($session);
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# getCollaborationFromArgs
|
|
||||||
# Gets the collaboration system from the arguments. The argument can be
|
|
||||||
# either an assetId or an absolute URL
|
|
||||||
sub getCollaborationFromArgs {
|
|
||||||
my $asset;
|
|
||||||
my $arg = $ARGV[0];
|
|
||||||
if ( $arg =~ m{^/} ) {
|
|
||||||
$asset = WebGUI::Asset->newByUrl( $session, $arg );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$asset = WebGUI::Asset->newByDynamicClass( $session, $arg );
|
|
||||||
}
|
|
||||||
|
|
||||||
unless ( $asset && $asset->isa('WebGUI::Asset::Wobject::Collaboration') ) {
|
|
||||||
pod2usage("$0: First argument must be a Collaboration asset");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $asset;
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# getGalleryFromArgs
|
|
||||||
# Gets the Gallery from the arguments. The argument can be either an assetId
|
|
||||||
# or an absolute URL
|
|
||||||
sub getGalleryFromArgs {
|
|
||||||
my $asset;
|
|
||||||
my $arg = $ARGV[1];
|
|
||||||
if ( $arg =~ m{^/} ) {
|
|
||||||
$asset = WebGUI::Asset->newByUrl( $session, $arg );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$asset = WebGUI::Asset->newByDynamicClass( $session, $arg );
|
|
||||||
}
|
|
||||||
|
|
||||||
unless ( $asset && $asset->isa('WebGUI::Asset::Wobject::Gallery') ) {
|
|
||||||
pod2usage("$0: Second argument must be a Gallery asset");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $asset;
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
sub start {
|
|
||||||
$| = 1; #disable output buffering
|
|
||||||
my ($configFile, $help);
|
|
||||||
GetOptions(
|
|
||||||
'configFile=s' => \$configFile,
|
|
||||||
'help' => \$help,
|
|
||||||
);
|
|
||||||
|
|
||||||
# Show usage
|
|
||||||
if ($help) {
|
|
||||||
pod2usage( verbose => 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
unless ($configFile) {
|
|
||||||
pod2usage("$0: Must specify a --configFile");
|
|
||||||
}
|
|
||||||
|
|
||||||
my $session = WebGUI::Session->open($webguiRoot,$configFile);
|
|
||||||
$session->user({userId=>3});
|
|
||||||
|
|
||||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
|
||||||
$versionTag->set({name => 'Migrate Collaboration to Gallery'});
|
|
||||||
|
|
||||||
return $session;
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
sub finish {
|
|
||||||
my $session = shift;
|
|
||||||
|
|
||||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
|
||||||
$versionTag->commit;
|
|
||||||
|
|
||||||
$session->var->end;
|
|
||||||
$session->close;
|
|
||||||
}
|
|
||||||
|
|
||||||
__END__
|
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
migrateCollabToGallery -- Migrate a collaboration system into a Gallery
|
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
|
||||||
|
|
||||||
migrateCollabToGallery --configFile config.conf collab gallery
|
|
||||||
|
|
||||||
migrateCollabToGallery --help
|
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
|
||||||
|
|
||||||
This WebGUI utility script migrates a collaboration system's threads
|
|
||||||
into gallery albums. It uses B<WebGUI::Utility::Gallery> for its major
|
|
||||||
features.
|
|
||||||
|
|
||||||
=over
|
|
||||||
|
|
||||||
=item B<--configFile config.conf>
|
|
||||||
|
|
||||||
The WebGUI config file to use. Only the file name needs to be specified,
|
|
||||||
since it will be looked up inside WebGUI's configuration directory.
|
|
||||||
This parameter is required.
|
|
||||||
|
|
||||||
=item B<collab>
|
|
||||||
|
|
||||||
A WebGUI's Collaboration System URL or Asset ID. If an URL is given,
|
|
||||||
it must be an absolute URL beginning with a slash.
|
|
||||||
|
|
||||||
=item B<gallery>
|
|
||||||
|
|
||||||
A WebGUI's Gallery URL or Asset ID. If an URL is given, it must be
|
|
||||||
an absolute URL beginning with a slash.
|
|
||||||
|
|
||||||
=item B<--help>
|
|
||||||
|
|
||||||
Shows this documentation, then exits.
|
|
||||||
|
|
||||||
=back
|
|
||||||
|
|
||||||
=head1 AUTHOR
|
|
||||||
|
|
||||||
Copyright 2001-2008 Plain Black Corporation.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
@ -1,153 +0,0 @@
|
||||||
#-------------------------------------------------------------------
|
|
||||||
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
# Please read the legal notices (docs/legal.txt) and the license
|
|
||||||
# (docs/license.txt) that came with this distribution before using
|
|
||||||
# this software.
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
# http://www.plainblack.com info@plainblack.com
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
our ($webguiRoot);
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
$webguiRoot = "..";
|
|
||||||
unshift (@INC, $webguiRoot."/lib");
|
|
||||||
}
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use Getopt::Long;
|
|
||||||
use Pod::Usage;
|
|
||||||
use WebGUI::Utility::Gallery;
|
|
||||||
use WebGUI::Session;
|
|
||||||
|
|
||||||
my $session = start();
|
|
||||||
|
|
||||||
my $folder = getFolderFromArgs();
|
|
||||||
my $gallery = getGalleryFromArgs();
|
|
||||||
|
|
||||||
WebGUI::Utility::Gallery->addAlbumFromFolder( $gallery, $folder );
|
|
||||||
|
|
||||||
finish($session);
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# getFolderFromArgs
|
|
||||||
# Gets the folder from the arguments. The argument can be
|
|
||||||
# either an assetId or an absolute URL
|
|
||||||
sub getFolderFromArgs {
|
|
||||||
my $asset;
|
|
||||||
my $arg = $ARGV[0];
|
|
||||||
if ( $arg =~ m{^/} ) {
|
|
||||||
$asset = WebGUI::Asset->newByUrl( $session, $arg );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$asset = WebGUI::Asset->newByDynamicClass( $session, $arg );
|
|
||||||
}
|
|
||||||
|
|
||||||
unless ( $asset && $asset->isa('WebGUI::Asset::Wobject::Folder') ) {
|
|
||||||
pod2usage("$0: First argument must be a Folder asset");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $asset;
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# getGalleryFromArgs
|
|
||||||
# Gets the Gallery from the arguments. The argument can be either an assetId
|
|
||||||
# or an absolute URL
|
|
||||||
sub getGalleryFromArgs {
|
|
||||||
my $asset;
|
|
||||||
my $arg = $ARGV[1];
|
|
||||||
if ( $arg =~ m{^/} ) {
|
|
||||||
$asset = WebGUI::Asset->newByUrl( $session, $arg );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$asset = WebGUI::Asset->newByDynamicClass( $session, $arg );
|
|
||||||
}
|
|
||||||
|
|
||||||
unless ( $asset && $asset->isa('WebGUI::Asset::Wobject::Gallery') ) {
|
|
||||||
pod2usage("$0: Second argument must be a Gallery asset");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $asset;
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
sub start {
|
|
||||||
$| = 1; #disable output buffering
|
|
||||||
my ($configFile, $help);
|
|
||||||
GetOptions(
|
|
||||||
'configFile=s' => \$configFile,
|
|
||||||
'help' => \$help,
|
|
||||||
);
|
|
||||||
|
|
||||||
# Show usage
|
|
||||||
if ($help) {
|
|
||||||
pod2usage(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
unless ($configFile) {
|
|
||||||
pod2usage("$0: Must specify a --configFile");
|
|
||||||
}
|
|
||||||
|
|
||||||
my $session = WebGUI::Session->open($webguiRoot,$configFile);
|
|
||||||
$session->user({userId=>3});
|
|
||||||
|
|
||||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
|
||||||
$versionTag->set({name => 'Migrate Folder to Gallery'});
|
|
||||||
|
|
||||||
return $session;
|
|
||||||
}
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
sub finish {
|
|
||||||
my $session = shift;
|
|
||||||
|
|
||||||
my $versionTag = WebGUI::VersionTag->getWorking($session);
|
|
||||||
$versionTag->commit;
|
|
||||||
|
|
||||||
$session->var->end;
|
|
||||||
$session->close;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
migrateFolderToGallery.pl -- Migrate a Folder into a Gallery
|
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
|
||||||
|
|
||||||
migrateFolderToGallery.pl --configFile=<config> <folder> <gallery>
|
|
||||||
|
|
||||||
=head1 ARGUMENTS
|
|
||||||
|
|
||||||
=over
|
|
||||||
|
|
||||||
=item folder
|
|
||||||
|
|
||||||
A Folder URL or asset ID. The URL must be an absolute URL, and
|
|
||||||
so must begin with a "/".
|
|
||||||
|
|
||||||
=item gallery
|
|
||||||
|
|
||||||
A Gallery URL or asset ID. The URL must be an absolute URL, and so much begin
|
|
||||||
with a "/".
|
|
||||||
|
|
||||||
=back
|
|
||||||
|
|
||||||
=head1 OPTIONS
|
|
||||||
|
|
||||||
=over
|
|
||||||
|
|
||||||
=item configFile
|
|
||||||
|
|
||||||
The WebGUI config file to use.
|
|
||||||
|
|
||||||
=back
|
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
|
||||||
|
|
||||||
This script migrates a Folder into a gallery album. It
|
|
||||||
uses B<WebGUI::Utility::Gallery> for its major features.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,275 +0,0 @@
|
||||||
# $vim:syntax=perl
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
# Please read the legal notices (docs/legal.txt) and the license
|
|
||||||
# (docs/license.txt) that came with this distribution before using
|
|
||||||
# this software.
|
|
||||||
#------------------------------------------------------------------
|
|
||||||
# http://www.plainblack.com info@plainblack.com
|
|
||||||
#------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Test the addAlbum* methods from the Gallery::Utility class
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use FindBin;
|
|
||||||
use lib "$FindBin::Bin/../../lib";
|
|
||||||
use Test::More;
|
|
||||||
use Test::Deep;
|
|
||||||
use WebGUI::Test;
|
|
||||||
use WebGUI::Asset;
|
|
||||||
use WebGUI::Session;
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Init
|
|
||||||
my $session = WebGUI::Test->session;
|
|
||||||
my $node = WebGUI::Asset->getImportNode( $session );
|
|
||||||
|
|
||||||
# Add arguments to avoid autocommit workflows
|
|
||||||
my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1 } );
|
|
||||||
|
|
||||||
my @versionTags;
|
|
||||||
push @versionTags, WebGUI::VersionTag->getWorking( $session );
|
|
||||||
|
|
||||||
# Generate a Gallery to import into
|
|
||||||
my $gallery;
|
|
||||||
my $album;
|
|
||||||
|
|
||||||
# Generate a collaboration system to import
|
|
||||||
my $collab
|
|
||||||
= $node->addChild({
|
|
||||||
className => 'WebGUI::Asset::Wobject::Collaboration',
|
|
||||||
});
|
|
||||||
|
|
||||||
my @threads;
|
|
||||||
for (0..2) {
|
|
||||||
push @threads, $collab->addChild({
|
|
||||||
className => 'WebGUI::Asset::Post::Thread',
|
|
||||||
content => "content$_",
|
|
||||||
menuTitle => "menuTitle$_",
|
|
||||||
ownerUserId => "3$_",
|
|
||||||
synopsis => "synopsis$_",
|
|
||||||
title => "title$_",
|
|
||||||
userDefined1 => "$_", # This is important. Used to detect which File is from which Thread
|
|
||||||
userDefined2 => "userDefined2$_",
|
|
||||||
userDefined3 => "userDefined3$_",
|
|
||||||
userDefined4 => "userDefined4$_",
|
|
||||||
userDefined5 => "userDefined5$_",
|
|
||||||
}, @addArgs);
|
|
||||||
$threads[-1]->getStorageLocation->addFileFromFilesystem(
|
|
||||||
WebGUI::Test->getTestCollateralPath('lamp.jpg')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Add a post to one of the threads, with an image
|
|
||||||
my @posts;
|
|
||||||
push @{$posts[0]}, $threads[0]->addChild({
|
|
||||||
className => 'WebGUI::Asset::Post',
|
|
||||||
content => "content00",
|
|
||||||
menuTitle => "menuTitle00",
|
|
||||||
synopsis => "synopsis00",
|
|
||||||
title => "title00",
|
|
||||||
userDefined1 => "00", # This is important. Used to detect which File is from which Post
|
|
||||||
userDefined2 => "userDefined200",
|
|
||||||
userDefined3 => "userDefined300",
|
|
||||||
userDefined4 => "userDefined400",
|
|
||||||
userDefined5 => "userDefined500",
|
|
||||||
}, @addArgs);
|
|
||||||
$posts[0][0]->getStorageLocation->addFileFromFilesystem(
|
|
||||||
WebGUI::Test->getTestCollateralPath('lamp.jpg')
|
|
||||||
);
|
|
||||||
|
|
||||||
$versionTags[-1]->commit;
|
|
||||||
|
|
||||||
# Thread fields mapped to album fields that should be migrated
|
|
||||||
my %threadFields = (
|
|
||||||
content => "description",
|
|
||||||
createdBy => 'createdBy',
|
|
||||||
creationDate => 'creationDate',
|
|
||||||
menuTitle => "menuTitle",
|
|
||||||
ownerUserId => "ownerUserId",
|
|
||||||
synopsis => "synopsis",
|
|
||||||
title => "title",
|
|
||||||
userDefined1 => "userDefined1",
|
|
||||||
userDefined2 => "userDefined2",
|
|
||||||
userDefined3 => "userDefined3",
|
|
||||||
userDefined4 => "userDefined4",
|
|
||||||
userDefined5 => "userDefined5",
|
|
||||||
);
|
|
||||||
|
|
||||||
# Post fields mapped to photo fields that should be migrated
|
|
||||||
my %postFields = (
|
|
||||||
createdBy => 'createdBy',
|
|
||||||
creationDate => 'creationDate',
|
|
||||||
ownerUserId => "ownerUserId",
|
|
||||||
userDefined1 => "userDefined1",
|
|
||||||
userDefined2 => "userDefined2",
|
|
||||||
userDefined3 => "userDefined3",
|
|
||||||
userDefined4 => "userDefined4",
|
|
||||||
userDefined5 => "userDefined5",
|
|
||||||
);
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Tests
|
|
||||||
|
|
||||||
# addAlbumFromThread adds 7 tests for $thread[0] and @{$posts[0]}
|
|
||||||
my $threadPostTests = 7 * ( 1 + scalar @{ $posts[0] } );
|
|
||||||
|
|
||||||
# addAlbumFromThread adds 1 test for each field in %threadFields
|
|
||||||
my $threadFieldTests = 1 * scalar keys %threadFields;
|
|
||||||
|
|
||||||
# addAlbumFromThread adds 1 test for each field in %postFields
|
|
||||||
my $postFieldTests = 1 * ( scalar keys %postFields )
|
|
||||||
* ( 1 + scalar @{ $posts[0] } );
|
|
||||||
|
|
||||||
plan tests => 10
|
|
||||||
+ $threadPostTests
|
|
||||||
+ $threadFieldTests
|
|
||||||
+ $postFieldTests
|
|
||||||
;
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Test use
|
|
||||||
my $utility = 'WebGUI::Utility::Gallery';
|
|
||||||
use_ok($utility);
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Test addAlbumFromThread
|
|
||||||
$gallery = $node->addChild({ className => 'WebGUI::Asset::Wobject::Gallery' });
|
|
||||||
|
|
||||||
ok(
|
|
||||||
!eval{ $utility->addAlbumFromThread( "", $threads[0] ); 1},
|
|
||||||
"addAlbumFromThread croaks if first argument is not a Gallery asset",
|
|
||||||
);
|
|
||||||
|
|
||||||
ok(
|
|
||||||
!eval{ $utility->addAlbumFromThread( $gallery, "" ); 1},
|
|
||||||
"addAlbumFromThread croaks if second argument is not a Thread asset",
|
|
||||||
);
|
|
||||||
|
|
||||||
push @versionTags, WebGUI::VersionTag->getWorking( $session );
|
|
||||||
$utility->addAlbumFromThread( $gallery, $threads[0] );
|
|
||||||
$versionTags[-1]->commit;
|
|
||||||
|
|
||||||
is(
|
|
||||||
scalar @{ $gallery->getAlbumIds }, 1,
|
|
||||||
"addAlbumFromThread creates a new album",
|
|
||||||
);
|
|
||||||
|
|
||||||
$album = WebGUI::Asset->newByDynamicClass( $session, $gallery->getAlbumIds->[0] );
|
|
||||||
use Data::Dumper;
|
|
||||||
diag( Dumper $gallery->getAlbumIds );
|
|
||||||
|
|
||||||
is(
|
|
||||||
$album->get('revisionDate'), $threads[0]->get('revisionDate'),
|
|
||||||
"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 ),
|
|
||||||
"addAlbumFromThread migrates Thread $oldField to GalleryAlbum $threadFields{$oldField}",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
is(
|
|
||||||
scalar @{ $album->getFileIds }, 2,
|
|
||||||
"addAlbumFromThread adds one file for each attachment to the thread or posts of the thread",
|
|
||||||
);
|
|
||||||
|
|
||||||
# 7 tests for each post/file + postFields tests
|
|
||||||
my $albumUrl = $album->get('url');
|
|
||||||
for my $fileId ( @{$album->getFileIds} ) {
|
|
||||||
my $file = WebGUI::Asset->newByDynamicClass( $session, $fileId );
|
|
||||||
|
|
||||||
# Find which Thread or Post this file corresponds to
|
|
||||||
my ( $post, $isThread );
|
|
||||||
if ( length $file->get('userDefined1') == 1 ) {
|
|
||||||
# Is a thread, get it
|
|
||||||
$post = $threads[ $file->get('userDefined1') ];
|
|
||||||
$isThread = 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
my @index = split //, $file->get('userDefined1');
|
|
||||||
$post = $posts[ $index[0] ][ $index[1] ];
|
|
||||||
$isThread = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for my $oldField ( sort keys %postFields ) {
|
|
||||||
is ( $file->get( $postFields{ $oldField } ), $post->get( $oldField ),
|
|
||||||
"addAlbumFromThread migrates Post $oldField to File $postFields{$oldField}",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
# File synopsis should be Post content If and only if Post content is not the same
|
|
||||||
# as the Thread content
|
|
||||||
if ( $isThread ) {
|
|
||||||
is ( $file->get('synopsis'), undef,
|
|
||||||
"Files do not get the Thread's content"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
is ( $file->get('synopsis'), $post->get('content'),
|
|
||||||
"Files get content when they're from posts other than the 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(
|
|
||||||
$file->getStorageLocation->getFiles, superbagof($file->get('filename')),
|
|
||||||
"Storage location contains the filename"
|
|
||||||
);
|
|
||||||
# Test that title and menuTitle do not contain file extention
|
|
||||||
my ($title) = $file->get('filename') =~ m{(.*)\.[^.]*$};
|
|
||||||
is( $file->get('title'), $title,
|
|
||||||
"Title doesn't contain the file extention"
|
|
||||||
);
|
|
||||||
is( $file->get('menuTitle'), $title,
|
|
||||||
"Menu title doesn't contain the file extention"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Test addAlbumFromCollaboration
|
|
||||||
$gallery = $node->addChild({ className => 'WebGUI::Asset::Wobject::Gallery' });
|
|
||||||
|
|
||||||
ok(
|
|
||||||
!eval{ $utility->addAlbumFromCollaboration( "", $collab ); 1},
|
|
||||||
"addAlbumFromCollaboration croaks if first argument is not a Gallery asset",
|
|
||||||
);
|
|
||||||
|
|
||||||
ok(
|
|
||||||
!eval{ $utility->addAlbumFromCollaboration( $gallery, "" ); 1},
|
|
||||||
"addAlbumFromCollaboration croaks if second argument is not a Collaboration asset",
|
|
||||||
);
|
|
||||||
|
|
||||||
push @versionTags, WebGUI::VersionTag->getWorking( $session );
|
|
||||||
$utility->addAlbumFromCollaboration( $gallery, $collab );
|
|
||||||
$versionTags[-1]->commit;
|
|
||||||
|
|
||||||
is(
|
|
||||||
scalar @{ $gallery->getAlbumIds }, scalar @threads,
|
|
||||||
"addAlbumFromCollaboration creates one album per thread",
|
|
||||||
);
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Cleanup
|
|
||||||
END {
|
|
||||||
for my $tag ( @versionTags ) {
|
|
||||||
$tag->rollback;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,184 +0,0 @@
|
||||||
# $vim:syntax=perl
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
# WebGUI is Copyright 2001-2008 Plain Black Corporation.
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
# Please read the legal notices (docs/legal.txt) and the license
|
|
||||||
# (docs/license.txt) that came with this distribution before using
|
|
||||||
# this software.
|
|
||||||
#------------------------------------------------------------------
|
|
||||||
# http://www.plainblack.com info@plainblack.com
|
|
||||||
#------------------------------------------------------------------
|
|
||||||
|
|
||||||
# Test the addAlbum* methods from the Gallery::Utility class
|
|
||||||
#
|
|
||||||
#
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use FindBin;
|
|
||||||
use lib "$FindBin::Bin/../../lib";
|
|
||||||
use Test::More;
|
|
||||||
use Test::Deep;
|
|
||||||
use WebGUI::Test;
|
|
||||||
use WebGUI::Asset;
|
|
||||||
use WebGUI::Session;
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Init
|
|
||||||
my $session = WebGUI::Test->session;
|
|
||||||
my $node = WebGUI::Asset->getImportNode( $session );
|
|
||||||
|
|
||||||
# Add arguments to avoid autocommit workflows
|
|
||||||
my @addArgs = ( undef, undef, { skipAutoCommitWorkflows => 1 } );
|
|
||||||
|
|
||||||
my @versionTags;
|
|
||||||
push @versionTags, WebGUI::VersionTag->getWorking( $session );
|
|
||||||
|
|
||||||
# Generate a Gallery to import into
|
|
||||||
my $gallery;
|
|
||||||
my $album;
|
|
||||||
|
|
||||||
# Generate a folder to import
|
|
||||||
my $folder
|
|
||||||
= $node->addChild({
|
|
||||||
className => 'WebGUI::Asset::Wobject::Folder',
|
|
||||||
});
|
|
||||||
|
|
||||||
my @files;
|
|
||||||
for (0..2) {
|
|
||||||
push @files, $folder->addChild({
|
|
||||||
className => 'WebGUI::Asset::File::Image',
|
|
||||||
menuTitle => "menuTitle$_",
|
|
||||||
ownerUserId => "3$_",
|
|
||||||
synopsis => "synopsis$_",
|
|
||||||
title => "title$_", # This is important. Used to detect which GalleryFile is from which File
|
|
||||||
filename => 'lamp.jpg',
|
|
||||||
}, @addArgs);
|
|
||||||
$files[-1]->getStorageLocation->addFileFromFilesystem(
|
|
||||||
WebGUI::Test->getTestCollateralPath('lamp.jpg')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$versionTags[-1]->commit;
|
|
||||||
|
|
||||||
# File to GalleryFile field mappings. Should be mostly the same
|
|
||||||
my %fileField = (
|
|
||||||
title => "title",
|
|
||||||
menuTitle => "menuTitle",
|
|
||||||
synopsis => "synopsis",
|
|
||||||
ownerUserId => "ownerUserId",
|
|
||||||
filename => "filename",
|
|
||||||
);
|
|
||||||
|
|
||||||
# Folder to GalleryAlbum field mappings.
|
|
||||||
my %folderField = (
|
|
||||||
title => "title",
|
|
||||||
menuTitle => "menuTitle",
|
|
||||||
description => "description",
|
|
||||||
createdBy => 'createdBy',
|
|
||||||
creationDate => 'creationDate',
|
|
||||||
ownerUserId => 'ownerUserId',
|
|
||||||
synopsis => 'synopsis',
|
|
||||||
);
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Tests
|
|
||||||
|
|
||||||
# 1 test for each file + file field tests
|
|
||||||
my $fileTests = scalar @files * ( 3 + scalar keys %fileField );
|
|
||||||
|
|
||||||
# 1 test for each item in folderField
|
|
||||||
my $folderTests = scalar keys %folderField;
|
|
||||||
|
|
||||||
plan tests => 10
|
|
||||||
+ $fileTests
|
|
||||||
+ $folderTests
|
|
||||||
;
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Test use
|
|
||||||
my $utility = 'WebGUI::Utility::Gallery';
|
|
||||||
use_ok($utility);
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Test addAlbumFromFolder
|
|
||||||
$gallery = $node->addChild({ className => 'WebGUI::Asset::Wobject::Gallery' });
|
|
||||||
|
|
||||||
ok(
|
|
||||||
!eval{ $utility->addAlbumFromFolder( "", $folder ); 1},
|
|
||||||
"addAlbumFromFolder croaks if first argument is not a Gallery asset",
|
|
||||||
);
|
|
||||||
|
|
||||||
ok(
|
|
||||||
!eval{ $utility->addAlbumFromFolder( $gallery, "" ); 1},
|
|
||||||
"addAlbumFromFolder croaks if second argument is not a Folder asset",
|
|
||||||
);
|
|
||||||
|
|
||||||
push @versionTags, WebGUI::VersionTag->getWorking( $session );
|
|
||||||
$utility->addAlbumFromFolder( $gallery, $folder );
|
|
||||||
$versionTags[-1]->commit;
|
|
||||||
|
|
||||||
is(
|
|
||||||
scalar @{ $gallery->getAlbumIds }, 1,
|
|
||||||
"addAlbumFromFolder creates a new album",
|
|
||||||
);
|
|
||||||
|
|
||||||
$album = WebGUI::Asset->newByDynamicClass( $session, $gallery->getAlbumIds->[0] );
|
|
||||||
|
|
||||||
is(
|
|
||||||
$album->get('revisionDate'), $folder->get('revisionDate'),
|
|
||||||
"addAlbumFromFolder creates album with same revisionDate as folder",
|
|
||||||
);
|
|
||||||
|
|
||||||
my $galleryUrl = $gallery->get('url');
|
|
||||||
like(
|
|
||||||
$album->get('url'), qr/^$galleryUrl/,
|
|
||||||
"addAlbumFromFolder creates album with url that begins with gallery's url",
|
|
||||||
);
|
|
||||||
|
|
||||||
# 1 test for each field in %folderField
|
|
||||||
for my $oldField ( sort keys %folderField ) {
|
|
||||||
is( $album->get( $folderField{ $oldField } ), $folder->get( $oldField ),
|
|
||||||
"addAlbumFromFolder migrates Folder $oldField to GalleryAlbum $folderField{$oldField}",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
is(
|
|
||||||
scalar @{ $album->getFileIds }, $folder->getChildCount,
|
|
||||||
"addAlbumFromFolder adds one file for each File in the Folder",
|
|
||||||
);
|
|
||||||
|
|
||||||
# 4 tests for each file + fileField tests
|
|
||||||
my $albumUrl = $album->get('url');
|
|
||||||
for my $fileId ( @{$album->getFileIds} ) {
|
|
||||||
my $newFile = WebGUI::Asset->newByDynamicClass( $session, $fileId );
|
|
||||||
|
|
||||||
# Find which File this was in the original Folder
|
|
||||||
( my $index ) = $newFile->get('title') =~ /title(\d+)/;
|
|
||||||
my $oldFile = $files[ $index ];
|
|
||||||
|
|
||||||
for my $oldField ( sort keys %fileField ) {
|
|
||||||
is ( $newFile->get( $fileField{ $oldField } ), $oldFile->get( $oldField ),
|
|
||||||
"addAlbumFromFolder migrates File $oldField to GalleryFile $fileField{$oldField}",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
like(
|
|
||||||
$newFile->get('url'), qr/^$albumUrl/,
|
|
||||||
"addAlbumFromFolder add files with urls that begin with GalleryAlbum url",
|
|
||||||
);
|
|
||||||
isa_ok( $newFile->getStorageLocation, 'WebGUI::Storage', 'Storage location exists' );
|
|
||||||
ok( $newFile->get('filename'), '"filename" property was set' );
|
|
||||||
cmp_deeply(
|
|
||||||
$newFile->getStorageLocation->getFiles, superbagof($newFile->get('filename')),
|
|
||||||
"Storage location contains the filename"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
|
||||||
# Cleanup
|
|
||||||
END {
|
|
||||||
for my $tag ( @versionTags ) {
|
|
||||||
$tag->rollback;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue