moved metadata system into asset superclass, and added a fileImport script
This commit is contained in:
parent
1914386984
commit
2110af418a
16 changed files with 623 additions and 1056 deletions
|
|
@ -1,194 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2004 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, $webUser, @nailable);
|
||||
|
||||
BEGIN {
|
||||
$webguiRoot = "..";
|
||||
@nailable = qw(jpg jpeg png gif);
|
||||
unshift (@INC, $webguiRoot."/lib");
|
||||
}
|
||||
|
||||
|
||||
$| = 1;
|
||||
|
||||
use Getopt::Long;
|
||||
use strict;
|
||||
use WebGUI::Collateral;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Utility;
|
||||
|
||||
|
||||
my $configFile;
|
||||
my $folderId = '0';
|
||||
my $help;
|
||||
my $override;
|
||||
my $pathToFiles;
|
||||
my $quiet;
|
||||
my $thumbnailSize;
|
||||
my $webUser = 'apache';
|
||||
|
||||
GetOptions(
|
||||
'configFile=s'=>\$configFile,
|
||||
'folderId=s'=>\$folderId,
|
||||
'help'=>\$help,
|
||||
'override'=>\$override,
|
||||
'pathToFiles=s'=>\$pathToFiles,
|
||||
'quiet'=>\$quiet,
|
||||
'thumbnailSize=i'=>\$thumbnailSize,
|
||||
'webUser=s'=>\$webUser
|
||||
);
|
||||
|
||||
|
||||
if ($help || $configFile eq "" || $pathToFiles eq ""){
|
||||
print <<STOP;
|
||||
|
||||
|
||||
Usage: perl $0 --pathToFiles=<pathToImportFiles> --configfile=<webguiConfig>
|
||||
|
||||
--configFile WebGUI config file.
|
||||
|
||||
--pathToFiles Folder containing files to import.
|
||||
|
||||
|
||||
Options:
|
||||
|
||||
--folderId The unique identifier for the collateral
|
||||
folder that the imported files should
|
||||
be organized under. Defaults to '0' (Root).
|
||||
|
||||
--help Display this help message and exit.
|
||||
|
||||
--override This utility is designed to be run as
|
||||
a privileged user on Linux style systems.
|
||||
If you wish to run this utility without
|
||||
being the super user, then use this flag,
|
||||
but note that it may not work as
|
||||
intended.
|
||||
|
||||
--quiet Disable output unless there's an error.
|
||||
|
||||
--thumbnailSize The size (in pixels) of the thumbnails
|
||||
that will be generated if you import
|
||||
images. Defaults to the Thumbnail Size
|
||||
setting in the site's content settings.
|
||||
|
||||
--webUser The user that your web server runs as.
|
||||
Defaults to 'apache'.
|
||||
|
||||
STOP
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
if (!($^O =~ /^Win/i) && $> != 0 && !$override) {
|
||||
print "You must be the super user to use this utility.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
print "Starting..." unless ($quiet);
|
||||
WebGUI::Session::open($webguiRoot,$configFile);
|
||||
WebGUI::Session::refreshUserInfo(3);
|
||||
print "OK\n" unless ($quiet);
|
||||
|
||||
addFiles(buildFileList($pathToFiles), ($thumbnailSize||$session{setting}{thumbnailSize}));
|
||||
setPrivileges();
|
||||
|
||||
print "Cleaning up..." unless ($quiet);
|
||||
WebGUI::Session::end($session{var}{sessionId});
|
||||
WebGUI::Session::close();
|
||||
print "OK\n" unless ($quiet);
|
||||
|
||||
|
||||
#-----------------------------------------
|
||||
# addFiles(dbHandler, filelistHashRef, webguiSettingsHashRef, pathToCopyFrom)
|
||||
#-----------------------------------------
|
||||
sub addFiles {
|
||||
my ($type, $parameters);
|
||||
my ($filelist, $thumbnailSize) = @_;
|
||||
print "Adding files...\n" unless ($quiet);
|
||||
foreach my $filename (keys %{$filelist}) {
|
||||
print "Processing $filename.\n" unless ($quiet);
|
||||
foreach my $ext (keys %{${$filelist}{$filename}}) {
|
||||
my $collateral = WebGUI::Collateral->new("new");
|
||||
print "\tCopying ".${$filelist}{$filename}{$ext}.".\n" unless ($quiet);
|
||||
$collateral->saveFromFilesystem($pathToFiles.$session{os}{slash}.${$filelist}{$filename}{$ext},$thumbnailSize);
|
||||
print "\tAdding $filename to the database.\n" unless ($quiet);
|
||||
if (isIn(lc($ext), @nailable)) {
|
||||
$type = "image";
|
||||
$parameters = 'border="0"';
|
||||
} else {
|
||||
$type = "file";
|
||||
$parameters = '';
|
||||
}
|
||||
$collateral->set({
|
||||
collateralType=>$type,
|
||||
name=>$filelist->{$filename}{$ext},
|
||||
username=>"Imported",
|
||||
thumbnailSize=>$thumbnailSize,
|
||||
collateralFolderId=>$folderId,
|
||||
parameters=>$parameters
|
||||
});
|
||||
}
|
||||
}
|
||||
print "Finished adding.\n";
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------
|
||||
# setPrivileges()
|
||||
#-----------------------------------------
|
||||
sub setPrivileges {
|
||||
print "Setting filesystem privileges.\n" unless ($quiet);
|
||||
if ($session{os}{type} eq "Linuxish") {
|
||||
unless (system("chown -R ".$webUser." ".$session{config}{uploadsPath})) {
|
||||
print "Privileges set.\n" unless ($quiet);
|
||||
} else {
|
||||
print "Could not set privileges.\n";
|
||||
}
|
||||
} else {
|
||||
print "Cannot set privileges on this platform.\n" unless ($quiet)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------
|
||||
# buildFileList(pathToImportFiles)
|
||||
#-----------------------------------------
|
||||
sub buildFileList {
|
||||
print "Building file list.\n" unless ($quiet);
|
||||
my (%filelist, @files, $file, $filename, $ext);
|
||||
if (opendir(FILES,$_[0])) {
|
||||
@files = readdir(FILES);
|
||||
foreach $file (@files) {
|
||||
unless ($file eq "." || $file eq "..") {
|
||||
$file =~ /(.*?)\.(.*?)$/;
|
||||
$filename = $1;
|
||||
$ext = $2;
|
||||
$filelist{$filename}{$ext} = $file;
|
||||
print "Found file $file.\n" unless ($quiet);
|
||||
}
|
||||
}
|
||||
closedir(FILES);
|
||||
print "File list complete.\n" unless ($quiet);
|
||||
return \%filelist;
|
||||
} else {
|
||||
print "Error: Could not open folder.\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ our ($webguiRoot, @nailable);
|
|||
|
||||
BEGIN {
|
||||
$webguiRoot = "..";
|
||||
@nailable = qw(jpg jpeg png gif tif tiff bmp);
|
||||
@nailable = qw(jpg jpeg png gif);
|
||||
unshift (@INC, $webguiRoot."/lib");
|
||||
}
|
||||
|
||||
|
|
@ -25,60 +25,72 @@ use File::Path;
|
|||
use File::stat;
|
||||
use FileHandle;
|
||||
use Getopt::Long;
|
||||
use Image::Magick;
|
||||
use POSIX;
|
||||
use strict;
|
||||
use WebGUI::Attachment;
|
||||
use WebGUI::Asset::File;
|
||||
use WebGUI::Asset::File::Image;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::Storage;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::Wobject::FileManager;
|
||||
|
||||
|
||||
|
||||
my $configFile;
|
||||
my $groupToView = 2;
|
||||
my $owner = 3;
|
||||
my $groupToView = 7;
|
||||
my $groupToEdit = 4;
|
||||
my $help;
|
||||
my $pathToFiles;
|
||||
my $override;
|
||||
my $quiet;
|
||||
my $webUser = 'apache';
|
||||
my $wobjectId;
|
||||
my $assetId;
|
||||
|
||||
GetOptions(
|
||||
'configFile=s'=>\$configFile,
|
||||
'owner=s'=>\$owner,
|
||||
'groupToView=s'=>\$groupToView,
|
||||
'groupToEdit=s'=>\$groupToEdit,
|
||||
'help'=>\$help,
|
||||
'override'=>$override,
|
||||
'pathToFiles=s'=>\$pathToFiles,
|
||||
'quiet'=>\$quiet,
|
||||
'webUser=s'=>\$webUser,
|
||||
'wobjectId=s'=>\$wobjectId
|
||||
'parentAssetId=s'=>\$parrentAssetId
|
||||
);
|
||||
|
||||
|
||||
if ($help || $configFile eq "" || $pathToFiles eq "" || $wobjectId eq ""){
|
||||
if ($help || $configFile eq "" || $pathToFiles eq "" || $parentAssetId eq ""){
|
||||
print <<STOP;
|
||||
|
||||
|
||||
Usage: perl $0 --pathToFiles=<pathToImportFiles> --configfile=<webguiConfig> --wobjectId=<fileManagerWobjectId>
|
||||
Usage: perl $0 --pathToFiles=<pathToImportFiles> --configfile=<webguiConfig> --parentAssetId=<assetId>
|
||||
|
||||
--configFile WebGUI config file.
|
||||
|
||||
--pathToFiles Folder containing files to import.
|
||||
|
||||
--wobjectId The wobject ID of the file manager you
|
||||
wish to import these files to.
|
||||
--parentAssetId The asset ID of the asset you wish
|
||||
to attach these files to.
|
||||
|
||||
|
||||
Options:
|
||||
|
||||
--groupToEdit The group ID of the group that should
|
||||
have the privileges to edit these
|
||||
files. Defaults to '4' (Content Managers).
|
||||
|
||||
--groupToView The group ID of the group that should
|
||||
have the privileges to view these
|
||||
files. Defaults to '2'.
|
||||
files. Defaults to '7' (Everybody).
|
||||
|
||||
--help Display this help message and exit.
|
||||
|
||||
--owner The user ID of the user that should
|
||||
have the privileges to modify these
|
||||
files. Defaults to '3' (Admin).
|
||||
|
||||
--override This utility is designed to be run as
|
||||
a privileged user on Linux style systems.
|
||||
If you wish to run this utility without
|
||||
|
|
@ -119,39 +131,33 @@ print "OK\n" unless ($quiet);
|
|||
# addFiles(dbHandler, filelistHashRef, webguiSettingsHashRef, pathToCopyFrom)
|
||||
#-----------------------------------------
|
||||
sub addFiles {
|
||||
my ($exists, @files, $filename, $ext, $id, $i, $file1, $file2, $file3, $seq);
|
||||
my $filelist = shift;
|
||||
print "Adding files...\n" unless ($quiet);
|
||||
($exists) = WebGUI::SQL->quickArray("select count(*) from FileManager where wobjectId='$wobjectId'");
|
||||
if ($exists) {
|
||||
my $w = WebGUI::Wobject::FileManager->new({wobjectId=>$wobjectId,namespace=>"FileManager"});
|
||||
foreach $filename (keys %{$_[0]}) {
|
||||
print "Processing $filename.\n" unless ($quiet);
|
||||
$i = 0;
|
||||
@files = [];
|
||||
print "\tAdding $filename to the database.\n" unless ($quiet);
|
||||
my $fileId = $w->setCollateral("FileManager_file","FileManager_fileId",{
|
||||
FileManager_fileId=>"new",
|
||||
groupToView=>$groupToView,
|
||||
dateUploaded=>time(),
|
||||
fileTitle=>$filename
|
||||
});
|
||||
my $attachment = WebGUI::Attachment->new("new",$w->get("wobjectId"),$fileId);
|
||||
foreach $ext (keys %{${$_[0]}{$filename}}) {
|
||||
print "\tCopying ".${$_[0]}{$filename}{$ext}.".\n" unless ($quiet);
|
||||
$attachment->saveFromFilesystem($pathToFiles.$session{os}{slash}.${$_[0]}{$filename}{$ext});
|
||||
$files[$i] = ${$_[0]}{$filename}{$ext};
|
||||
$i++;
|
||||
}
|
||||
my @files = sort {isIn(getType($b),@nailable) cmp isIn(getType($a),@nailable)} @files;
|
||||
$w->setCollateral("FileManager_file","FileManager_fileId",{
|
||||
FileManager_fileId=>$fileId,
|
||||
downloadFile=>$files[0],
|
||||
alternateVersion1=>$files[1],
|
||||
alternateVersion2=>$files[2]
|
||||
my $parent = WebGUI::Asset::File->newByDynamicClass($parentAssetId);
|
||||
if (defined $parent) {
|
||||
foreach my $file (@{$filelist}) {
|
||||
print "\tAdding ".$file->{filename}." to the database.\n" unless ($quiet);
|
||||
my $class = 'WebGUI::Asset::File';
|
||||
$class = 'WebGUI::Asset::File::Image' if (isIn($file->{ext},@nailable));
|
||||
my $url = $parent->getUrl.'/'.$file->{filename};
|
||||
my $storage = WebGUI::Storage->create;
|
||||
my $filename = $storage->addFileFromFilesystem($pathToFiles.$session{os}{slash}.$file->{filename});
|
||||
my $newAsset = $parent->addChild({
|
||||
className=>$class,
|
||||
title=>$filename,
|
||||
menuTitle=>$filename,
|
||||
filename=>$filename,
|
||||
storageId=>$storage->getId,
|
||||
url=>$url,
|
||||
groupIdView=>$groupToView,
|
||||
groupIdEdit=>$groupToEdit,
|
||||
ownerUserId=>$owner
|
||||
});
|
||||
$newAsset->generateThumbnail if ($class eq 'WebGUI::Asset::File::Image');
|
||||
$newAsset->setSize($storage->getFileSize($filename));
|
||||
}
|
||||
} else {
|
||||
print "Warning: File Manager '".$wobjectId."' does not exist. Cannot import files.\n";
|
||||
print "Warning: Parent asset '".$parentAssetId."' does not exist. Cannot import files.\n";
|
||||
}
|
||||
print "Finished adding.\n" unless ($quiet);
|
||||
}
|
||||
|
|
@ -177,7 +183,7 @@ sub setPrivileges {
|
|||
#-----------------------------------------
|
||||
sub buildFileList {
|
||||
print "Building file list.\n" unless ($quiet);
|
||||
my (%filelist, @files, $file, $filename, $ext);
|
||||
my (@filelist, @files, $file, $filename, $ext);
|
||||
if (opendir(FILES,$_[0])) {
|
||||
@files = readdir(FILES);
|
||||
foreach $file (@files) {
|
||||
|
|
@ -185,13 +191,14 @@ sub buildFileList {
|
|||
$file =~ /(.*?)\.(.*?)$/;
|
||||
$filename = $1;
|
||||
$ext = $2;
|
||||
push(@filelist,{ext=>$ext, filename=>$file});
|
||||
$filelist{$filename}{$ext} = $file;
|
||||
print "Found file $file.\n" unless ($quiet);
|
||||
}
|
||||
}
|
||||
closedir(FILES);
|
||||
print "File list complete.\n" unless ($quiet);
|
||||
return \%filelist;
|
||||
return \@filelist;
|
||||
} else {
|
||||
print "Error: Could not open folder.\n";
|
||||
exit;
|
||||
|
|
@ -69,7 +69,6 @@ use XML::Simple ();
|
|||
use WebGUI ();
|
||||
use WebGUI::Affiliate ();
|
||||
use WebGUI::Asset ();
|
||||
use WebGUI::Asset::Wobject ();
|
||||
use WebGUI::Auth ();
|
||||
use WebGUI::Cache ();
|
||||
use WebGUI::Config ();
|
||||
|
|
@ -78,10 +77,6 @@ use WebGUI::DateTime ();
|
|||
use WebGUI::ErrorHandler ();
|
||||
use WebGUI::Form ();
|
||||
use WebGUI::FormProcessor ();
|
||||
use WebGUI::Forum ();
|
||||
use WebGUI::Forum::Post ();
|
||||
use WebGUI::Forum::Thread ();
|
||||
use WebGUI::Forum::UI ();
|
||||
use WebGUI::Group ();
|
||||
use WebGUI::Grouping ();
|
||||
use WebGUI::HTMLForm ();
|
||||
|
|
@ -106,25 +101,25 @@ use WebGUI::User ();
|
|||
use WebGUI::Utility ();
|
||||
|
||||
# help
|
||||
use WebGUI::Help::Article ();
|
||||
use WebGUI::Help::Asset ();
|
||||
use WebGUI::Help::AuthLDAP ();
|
||||
use WebGUI::Help::AuthSMB ();
|
||||
use WebGUI::Help::AuthWebGUI ();
|
||||
use WebGUI::Help::DataForm ();
|
||||
use WebGUI::Help::EventsCalendar ();
|
||||
use WebGUI::Help::HttpProxy ();
|
||||
use WebGUI::Help::IndexedSearch ();
|
||||
use WebGUI::Help::MessageBoard ();
|
||||
use WebGUI::Help::Poll ();
|
||||
use WebGUI::Help::Product ();
|
||||
use WebGUI::Help::SQLReport ();
|
||||
use WebGUI::Help::Survey ();
|
||||
use WebGUI::Help::SyndicatedContent ();
|
||||
use WebGUI::Help::USS ();
|
||||
use WebGUI::Help::WebGUI ();
|
||||
use WebGUI::Help::WobjectProxy ();
|
||||
use WebGUI::Help::WSClient ();
|
||||
#use WebGUI::Help::Article ();
|
||||
#use WebGUI::Help::Asset ();
|
||||
#use WebGUI::Help::AuthLDAP ();
|
||||
#use WebGUI::Help::AuthSMB ();
|
||||
#use WebGUI::Help::AuthWebGUI ();
|
||||
#use WebGUI::Help::DataForm ();
|
||||
#use WebGUI::Help::EventsCalendar ();
|
||||
#use WebGUI::Help::HttpProxy ();
|
||||
#use WebGUI::Help::IndexedSearch ();
|
||||
#use WebGUI::Help::MessageBoard ();
|
||||
#use WebGUI::Help::Poll ();
|
||||
#use WebGUI::Help::Product ();
|
||||
#use WebGUI::Help::SQLReport ();
|
||||
#use WebGUI::Help::Survey ();
|
||||
#use WebGUI::Help::SyndicatedContent ();
|
||||
#use WebGUI::Help::USS ();
|
||||
#use WebGUI::Help::WebGUI ();
|
||||
#use WebGUI::Help::WobjectProxy ();
|
||||
#use WebGUI::Help::WSClient ();
|
||||
|
||||
# i18n
|
||||
use WebGUI::i18n::English ();
|
||||
|
|
@ -156,6 +151,8 @@ use WebGUI::i18n::English::WSClient ();
|
|||
use WebGUI::Asset::File ();
|
||||
use WebGUI::Asset::File::Image ();
|
||||
use WebGUI::Asset::Snippet ();
|
||||
use WebGUI::Asset::Template ();
|
||||
use WebGUI::Asset::Wobject ();
|
||||
use WebGUI::Asset::Wobject::Article ();
|
||||
use WebGUI::Asset::Wobject::Layout ();
|
||||
use WebGUI::Asset::Wobject::Navigation ();
|
||||
|
|
@ -173,6 +170,13 @@ use WebGUI::Auth::LDAP ();
|
|||
# macros
|
||||
use WebGUI::Macro::AdminBar ();
|
||||
use WebGUI::Macro::AssetProxy ();
|
||||
use WebGUI::Macro::Extras ();
|
||||
use WebGUI::Macro::FileUrl ();
|
||||
use WebGUI::Macro::JavaScript ();
|
||||
use WebGUI::Macro::PageUrl ();
|
||||
use WebGUI::Macro::Slash_gatewayUrl ();
|
||||
use WebGUI::Macro::Spacer ();
|
||||
use WebGUI::Macro::StyleSheet ();
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue