Adding basic per instance mailing configuration.
This commit is contained in:
parent
f8cb8cd05a
commit
04f39ebc19
5 changed files with 104 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ use warnings;
|
||||||
use Class::C3;
|
use Class::C3;
|
||||||
|
|
||||||
use WebGUI::Macro;
|
use WebGUI::Macro;
|
||||||
|
use Tie::IxHash;
|
||||||
|
|
||||||
##----------------------------------------------------------------------------
|
##----------------------------------------------------------------------------
|
||||||
#sub configureMailingForm {
|
#sub configureMailingForm {
|
||||||
|
|
@ -62,6 +63,33 @@ sub getIssueList {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub getSubject {
|
||||||
|
my $self = shift;
|
||||||
|
my $configuration = shift || {};
|
||||||
|
|
||||||
|
return $configuration->{ subject } || '(No subject)';
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub getMailingProperties {
|
||||||
|
my $self = shift;
|
||||||
|
tie my %properties, 'Tie::IxHash', (
|
||||||
|
subject => {
|
||||||
|
fieldType => 'text',
|
||||||
|
label => 'subject',
|
||||||
|
},
|
||||||
|
styleTemplateId => {
|
||||||
|
fieldType => 'template',
|
||||||
|
label => 'Style template',
|
||||||
|
defaultValue=> $self->get('mailStyleTemplateId'),
|
||||||
|
namespace => 'style',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return \%properties;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub getRecipients {
|
sub getRecipients {
|
||||||
WebGUI::Error::OverrideMe->throw;
|
WebGUI::Error::OverrideMe->throw;
|
||||||
|
|
@ -70,9 +98,11 @@ sub getRecipients {
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub processContentAsUser {
|
sub processContentAsUser {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $issueId = shift;
|
my $issueId = shift;
|
||||||
my $userId = shift;
|
my $userId = shift;
|
||||||
|
my $configuration = shift || {};
|
||||||
|
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $currentUser = $session->user;
|
my $currentUser = $session->user;
|
||||||
|
|
||||||
|
|
@ -81,7 +111,8 @@ sub processContentAsUser {
|
||||||
$session->log->preventDebugOutput;
|
$session->log->preventDebugOutput;
|
||||||
|
|
||||||
my $styleTemplateId =
|
my $styleTemplateId =
|
||||||
$self->get('mailStyleTemplateId')
|
$configuration->{ styleTemplateId }
|
||||||
|
|| $self->get('mailStyleTemplateId')
|
||||||
|| $self->get('styleTemplateId');
|
|| $self->get('styleTemplateId');
|
||||||
|
|
||||||
# Generate email body for this user
|
# Generate email body for this user
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ sub crud_definition {
|
||||||
},
|
},
|
||||||
configuration => {
|
configuration => {
|
||||||
fieldType => 'textarea',
|
fieldType => 'textarea',
|
||||||
|
serialize => 1,
|
||||||
},
|
},
|
||||||
sendDate => {
|
sendDate => {
|
||||||
fieldType => 'dateTime',
|
fieldType => 'dateTime',
|
||||||
|
|
@ -122,6 +123,68 @@ sub queueEmails {
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub www_delete {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
|
||||||
|
$self->delete;
|
||||||
|
|
||||||
|
return WebGUI::Mailing::Admin->new($session)->www_view;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub www_edit {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
|
||||||
|
my $f = WebGUI::HTMLForm->new( $session );
|
||||||
|
$f->hidden(
|
||||||
|
name => 'newsletter',
|
||||||
|
value => 'mailing',
|
||||||
|
);
|
||||||
|
$f->hidden(
|
||||||
|
name => 'func',
|
||||||
|
value => 'editSave',
|
||||||
|
);
|
||||||
|
$f->hidden(
|
||||||
|
name => 'id',
|
||||||
|
value => $self->getId,
|
||||||
|
);
|
||||||
|
|
||||||
|
my %fields = %{ $self->getAsset->getMailingProperties };
|
||||||
|
my $configuration = $self->get('configuration') || {};
|
||||||
|
while ( my( $name, $properties ) = each %fields ) {
|
||||||
|
$f->dynamicField(
|
||||||
|
name => $name,
|
||||||
|
%{ $properties },
|
||||||
|
value => $configuration->{ $name },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$f->submit;
|
||||||
|
|
||||||
|
return WebGUI::Mailing::Admin->new($session)->getAdminConsole->render( $f->print, 'Configure mailing' );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub www_editSave {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $form = $session->form;
|
||||||
|
|
||||||
|
my %fields = %{ $self->getAsset->getMailingProperties };
|
||||||
|
my $configuration = {};
|
||||||
|
while ( my( $name, $properties ) = each %fields ) {
|
||||||
|
my $value = $form->process( $name, $properties->{ fieldType }, $properties->{ defaultValue } );
|
||||||
|
|
||||||
|
$configuration->{ $name } = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
#### TODO: Add error checking and required fields?
|
||||||
|
$self->update( { configuration => $configuration } );
|
||||||
|
|
||||||
|
return WebGUI::Mailing::Admin->new( $session )->www_view;
|
||||||
|
}
|
||||||
|
|
||||||
sub www_sendBatch {
|
sub www_sendBatch {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ sub www_createMailing {
|
||||||
active => 0,
|
active => 0,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return $self->www_view;
|
return $mailing->www_edit;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub www_settings {
|
sub www_settings {
|
||||||
|
|
@ -124,6 +124,8 @@ sub www_view {
|
||||||
status => $mailing->getStatusLine,
|
status => $mailing->getStatusLine,
|
||||||
sendTestUrl => $url->page('newsletter=mailing;func=sendTestEmails;id='.$mailing->getId),
|
sendTestUrl => $url->page('newsletter=mailing;func=sendTestEmails;id='.$mailing->getId),
|
||||||
sendUrl => $url->page('newsletter=mailing;func=sendBatch;id='.$mailing->getId),
|
sendUrl => $url->page('newsletter=mailing;func=sendBatch;id='.$mailing->getId),
|
||||||
|
editUrl => $url->page('newsletter=mailing;func=edit;id='.$mailing->getId),
|
||||||
|
deleteUrl => $url->page('newsletter=mailing;func=delete;id='.$mailing->getId),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,8 +150,9 @@ sub send {
|
||||||
|
|
||||||
#### TODO: Error checking
|
#### TODO: Error checking
|
||||||
my $mailing = $self->getMailing;
|
my $mailing = $self->getMailing;
|
||||||
|
my $configuration = $mailing->get('configuration') || {};
|
||||||
my $asset = $mailing->getAsset;
|
my $asset = $mailing->getAsset;
|
||||||
my $content = $asset->processContentAsUser( $mailing->get('issueId'), $self->get('userId') );
|
my $content = $asset->processContentAsUser( $mailing->get('issueId'), $self->get('userId'), $configuration );
|
||||||
my $body = $self->absolutifyURIs( $content, $asset->getUrl );
|
my $body = $self->absolutifyURIs( $content, $asset->getUrl );
|
||||||
|
|
||||||
# Mail is a test mail but there is noone to send the result to
|
# Mail is a test mail but there is noone to send the result to
|
||||||
|
|
@ -169,7 +170,7 @@ sub send {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fetch subject
|
# Fetch subject
|
||||||
my $subject = '[TEST] Subject selection still needs to be implemented.';
|
my $subject = $asset->getSubject( $configuration );
|
||||||
|
|
||||||
my $messageId = $id->toHex( $self->getId );
|
my $messageId = $id->toHex( $self->getId );
|
||||||
my $domain = $session->setting->get( 'newsletterReturnDomain' );
|
my $domain = $session->setting->get( 'newsletterReturnDomain' );
|
||||||
|
|
@ -187,7 +188,6 @@ sub send {
|
||||||
# And send it.
|
# And send it.
|
||||||
my $success = $mail->send;
|
my $success = $mail->send;
|
||||||
|
|
||||||
$session->log->warn( "Sending email to [$to]" );
|
|
||||||
if ( $success ne '1' ) {
|
if ( $success ne '1' ) {
|
||||||
$self->error( "Mail couldn't be sent by WebGUI::Mail::Send" );
|
$self->error( "Mail couldn't be sent by WebGUI::Mail::Send" );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue