Improve robustness.

This commit is contained in:
Martin Kamerbeek 2010-06-18 11:48:48 +02:00
parent 192cd6afe4
commit 87163f5d0f
3 changed files with 27 additions and 3 deletions

View file

@ -116,7 +116,10 @@ sub getAsset {
my $session = $self->session;
my $asset = WebGUI::Asset->newByDynamicClass( $session, $self->get('assetId') );
#### TODO: error checking
unless ( $asset ) {
$session->log->error( sprintf 'Mailing %s has corrupt assetId %s', $self->getId, $self->get('assetId') );
}
return $asset;
}
@ -126,7 +129,10 @@ sub getIssue {
my $session = $self->session;
my $issue = WebGUI::Asset->newByDynamicClass( $session, $self->get('issueId') );
#### TODO: error checking
unless ( $issue ) {
$session->log->error( sprintf 'Mailing %s has corrupt issueId %s', $self->getId, $self->get('issueId') );
}
return $issue;
}

View file

@ -96,10 +96,23 @@ sub www_createMailing {
return $session->privilege->insufficient unless $self->canManage;
# TODO: test if assetId and issueId are valid.
my $assetId = $form->guid( 'assetId' );
my $issueId = $form->guid( 'issueId' );
# Sanity check: does assetId exist?
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId )
|| return "Error: Asset [$assetId] could not be instanciated";
# Sanity check: is asset mailable?
unless ( $asset->isa( 'WebGUI::AssetAspect::Mailable' ) ) {
return "Error: Asset [$assetId] is not Mailable";
}
# Sanity check: does issue exist?
my $issue = WebGUI::Asset->newByDynamicClass( $session, $issueId )
|| return "Error: issue [$issueId] for asset [$assetId] could not be instanciated.";
# All ok, create mailing.
my $mailing = WebGUI::Mailing->create( $session, {
assetId => $assetId,
issueId => $issueId,

View file

@ -151,6 +151,11 @@ sub send {
#### TODO: Error checking
my $mailing = $self->getMailing;
unless ( $mailing ) {
$session->log->error( 'Cannot send because getMailing doesn\'t return one.' );
return;
}
my $configuration = $mailing->get('configuration') || {};
my $asset = $mailing->getAsset;
my $content = $asset->processContentAsUser( $mailing->get('issueId'), $self->get('userId'), $configuration );