Finished? Ready for merge at least.

This commit is contained in:
Doug Bell 2007-12-17 22:22:06 +00:00
parent 5d1faff793
commit 82e9bf8448
45 changed files with 5112 additions and 513 deletions

View file

@ -125,18 +125,22 @@ A hash reference containing the exported data.
=cut
sub importAssetData {
my $self = shift;
my $data = shift;
my $error = $self->session->errorHandler;
my $id = $data->{properties}{assetId};
my $class = $data->{properties}{className};
my $version = $data->{properties}{revisionDate};
my $self = shift;
my $data = shift;
my $error = $self->session->errorHandler;
my $id = $data->{properties}{assetId};
my $class = $data->{properties}{className};
my $version = $data->{properties}{revisionDate};
# Load the class
WebGUI::Asset->loadModule( $self->session, $class );
my $asset;
my $assetExists = WebGUI::Asset->assetExists($self->session, $id, $class, $version);
if ($assetExists) { # update an existing revision
my $assetExists = WebGUI::Asset->assetExists($self->session, $id, $class, $version);
if ($assetExists) { # update an existing revision
$asset = WebGUI::Asset->new($self->session, $id, $class, $version);
$error->info("Updating an existing revision of asset $id");
$asset->update($data->{properties});
$error->info("Updating an existing revision of asset $id");
$asset->update($data->{properties});
##Pending assets are assigned a new version tag
if ($data->{properties}->{status} eq 'pending') {
$self->session->db->write(
@ -144,19 +148,19 @@ sub importAssetData {
[WebGUI::VersionTag->getWorking($self->session)->getId, $data->{properties}->{assetId}]
);
}
}
}
else {
$asset = WebGUI::Asset->new($self->session, $id, $class);
if (defined $asset) { # create a new revision of an existing asset
$error->info("Creating a new revision of asset $id");
$asset = $asset->addRevision($data->{properties}, $version, {skipAutoCommitWorkflows => 1});
}
$asset = WebGUI::Asset->new($self->session, $id, $class);
if (defined $asset) { # create a new revision of an existing asset
$error->info("Creating a new revision of asset $id");
$asset = $asset->addRevision($data->{properties}, $version, {skipAutoCommitWorkflows => 1});
}
else { # add an entirely new asset
$error->info("Adding $id that didn't previously exist.");
$asset = $self->addChild($data->{properties}, $id, $version, {skipAutoCommitWorkflows => 1});
}
}
return $asset;
$error->info("Adding $id that didn't previously exist.");
$asset = $self->addChild($data->{properties}, $id, $version, {skipAutoCommitWorkflows => 1});
}
}
return $asset;
}
#-------------------------------------------------------------------
@ -188,40 +192,40 @@ A reference to a WebGUI::Storage object that contains a webgui package file.
=cut
sub importPackage {
my $self = shift;
my $storage = shift;
my $decompressed = $storage->untar($storage->getFiles->[0]);
my %assets = ();
my $error = $self->session->errorHandler;
$error->info("Importing package.");
foreach my $file (sort(@{$decompressed->getFiles})) {
next unless ($decompressed->getFileExtension($file) eq "json");
$error->info("Found data file $file");
my $data = eval{
my $self = shift;
my $storage = shift;
my $decompressed = $storage->untar($storage->getFiles->[0]);
my %assets = ();
my $error = $self->session->errorHandler;
$error->info("Importing package.");
foreach my $file (sort(@{$decompressed->getFiles})) {
next unless ($decompressed->getFileExtension($file) eq "json");
$error->info("Found data file $file");
my $data = eval{
local $JSON::UnMapping = 1;
JSON::jsonToObj($decompressed->getFileContentsAsScalar($file))
};
if ($@ || $data->{properties}{assetId} eq "" || $data->{properties}{className} eq "" || $data->{properties}{revisionDate} eq "") {
$error->error("package corruption: ".$@) if ($@);
return "corrupt";
}
$error->info("Data file $file is valid and represents asset ".$data->{properties}{assetId});
foreach my $storageId (@{$data->{storage}}) {
my $assetStorage = WebGUI::Storage->get($self->session, $storageId);
$decompressed->untar($storageId.".storage", $assetStorage);
}
my $asset = $assets{$data->{properties}{parentId}} || $self;
my $newAsset = $asset->importAssetData($data);
if ($@ || $data->{properties}{assetId} eq "" || $data->{properties}{className} eq "" || $data->{properties}{revisionDate} eq "") {
$error->error("package corruption: ".$@) if ($@);
return "corrupt";
}
$error->info("Data file $file is valid and represents asset ".$data->{properties}{assetId});
foreach my $storageId (@{$data->{storage}}) {
my $assetStorage = WebGUI::Storage->get($self->session, $storageId);
$decompressed->untar($storageId.".storage", $assetStorage);
}
my $asset = $assets{$data->{properties}{parentId}} || $self;
my $newAsset = $asset->importAssetData($data);
$newAsset->importAssetCollateralData($data);
$assets{$newAsset->getId} = $newAsset;
}
if ($self->session->setting->get("autoRequestCommit")) {
$assets{$newAsset->getId} = $newAsset;
}
if ($self->session->setting->get("autoRequestCommit")) {
if ($self->session->setting->get("skipCommitComments")) {
WebGUI::VersionTag->getWorking($self->session)->requestCommit;
} else {
$self->session->http->setRedirect($self->getUrl("op=commitVersionTag;tagId=".WebGUI::VersionTag->getWorking($self->session)->getId));
$self->session->http->setRedirect($self->getUrl("op=commitVersionTag;tagId=".WebGUI::VersionTag->getWorking($self->session)->getId));
}
}
}
return undef;
}