Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
TYPO3
sg_mail
Commits
e599a554
Commit
e599a554
authored
Feb 20, 2017
by
Torsten Oppermann
Browse files
[TASK] Adding sending time to queue entries. Fixing a bug with template values & cc addresses
parent
999a9753
Changes
6
Hide whitespace changes
Inline
Side-by-side
Classes/Domain/Model/Mail.php
View file @
e599a554
...
...
@@ -94,6 +94,16 @@ class Mail extends AbstractEntity {
*/
protected
$templateName
=
''
;
/**
* @var string
*/
protected
$replyTo
=
''
;
/**
* @var int
*/
protected
$sendingTime
=
0
;
/**
* @return string
*/
...
...
@@ -253,4 +263,32 @@ class Mail extends AbstractEntity {
public
function
setTemplateName
(
$templateName
)
{
$this
->
templateName
=
$templateName
;
}
/**
* @return string
*/
public
function
getReplyTo
()
{
return
$this
->
replyTo
;
}
/**
* @param string $replyTo
*/
public
function
setReplyTo
(
$replyTo
)
{
$this
->
replyTo
=
$replyTo
;
}
/**
* @return int
*/
public
function
getSendingTime
()
{
return
$this
->
sendingTime
;
}
/**
* @param int $sendingTime
*/
public
function
setSendingTime
(
$sendingTime
)
{
$this
->
sendingTime
=
$sendingTime
;
}
}
Classes/Service/MailTemplateService.php
View file @
e599a554
...
...
@@ -26,6 +26,7 @@ namespace SGalinski\SgMail\Service;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use
DateTime
;
use
SGalinski\SgMail\Domain\Model\Mail
;
use
SGalinski\SgMail\Domain\Model\Template
;
use
SGalinski\SgMail\Domain\Repository\MailRepository
;
...
...
@@ -185,6 +186,7 @@ class MailTemplateService {
}
}
$this
->
mailMessage
->
setFrom
(
$this
->
fromAddress
);
if
(
count
(
$this
->
bccAddresses
)
>
0
)
{
$this
->
mailMessage
->
setBcc
(
$this
->
bccAddresses
);
}
...
...
@@ -297,6 +299,11 @@ class MailTemplateService {
$this
->
extensionKey
,
$this
->
templateName
,
$this
->
language
);
// if there is a template, prefer those values
if
(
$template
)
{
$this
->
loadTemplateValues
(
$template
);
}
// If there is no template for this language, use the default template
if
(
$template
===
NULL
)
{
$templatePath
=
self
::
$registerArray
[
$this
->
extensionKey
][
$this
->
templateName
][
'templatePath'
];
...
...
@@ -359,13 +366,16 @@ class MailTemplateService {
// insert <br /> tags, but replace every instance of three or more successive breaks with just two.
$emailBody
=
nl2br
(
$emailBody
);
$emailBody
=
preg_replace
(
'/(<br[\s]?[\/]?>[\s]*){3,}/'
,
'<br /><br />'
,
$emailBody
);
if
(
$this
->
ignoreMailQueue
)
{
$this
->
addMailToMailQueue
(
$this
->
extensionKey
,
$this
->
templateName
,
$subject
,
$emailBody
,
$this
->
priority
,
TRUE
);
$this
->
mailMessage
->
setBody
(
$emailBody
,
'text/html'
);
$this
->
mailMessage
->
send
();
$dateTime
=
new
DateTime
();
$this
->
addMailToMailQueue
(
$this
->
extensionKey
,
$this
->
templateName
,
$subject
,
$emailBody
,
$this
->
priority
,
$dateTime
->
getTimestamp
(),
TRUE
);
}
else
{
$this
->
addMailToMailQueue
(
$this
->
extensionKey
,
$this
->
templateName
,
$subject
,
$emailBody
,
$this
->
priority
);
}
...
...
@@ -380,10 +390,11 @@ class MailTemplateService {
* @param string $templateName
* @param string $subject
* @param string $emailBody
* @param int $sendingTime
* @param int $priority
* @param bool $sent
*/
private
function
addMailToMailQueue
(
$extensionKey
,
$templateName
,
$subject
,
$emailBody
,
$priority
,
$sent
=
FALSE
)
{
private
function
addMailToMailQueue
(
$extensionKey
,
$templateName
,
$subject
,
$emailBody
,
$priority
,
$sendingTime
=
0
,
$sent
=
FALSE
)
{
$mail
=
$this
->
objectManager
->
get
(
Mail
::
class
);
$mail
->
setExtensionKey
(
$extensionKey
);
$mail
->
setTemplateName
(
$templateName
);
...
...
@@ -395,6 +406,7 @@ class MailTemplateService {
$mail
->
setBccAddresses
(
implode
(
','
,
$this
->
bccAddresses
));
$mail
->
setCcAddresses
(
implode
(
','
,
$this
->
ccAddresses
));
$mail
->
setSent
(
$sent
);
$mail
->
setSendingTime
(
$sendingTime
);
$mailRepository
=
$this
->
objectManager
->
get
(
MailRepository
::
class
);
$mailRepository
->
add
(
$mail
);
...
...
@@ -416,7 +428,9 @@ class MailTemplateService {
$this
->
mailMessage
->
setTo
(
$mailToSend
->
getToAddress
());
$this
->
mailMessage
->
setFrom
(
$mailToSend
->
getFromAddress
(),
$mailToSend
->
getFromName
());
$this
->
mailMessage
->
setSubject
(
$mailToSend
->
getMailSubject
());
$this
->
mailMessage
->
setBcc
(
explode
(
','
,
$mailToSend
->
getBccAddresses
()));
$this
->
mailMessage
->
setCc
(
explode
(
','
,
$mailToSend
->
getCcAddresses
()));
$this
->
mailMessage
->
setReplyTo
(
$mailToSend
->
getReplyTo
());
$this
->
mailMessage
->
send
();
}
}
...
...
@@ -451,12 +465,12 @@ class MailTemplateService {
}
/**
* @param
array|
string $ccAddresses
* @param string $ccAddresses
* @return MailTemplateService
*/
public
function
setCcAddresses
(
$ccAddresses
)
{
$this
->
ccAddresses
[]
=
$ccAddresses
;
$this
->
mailMessage
->
setCc
(
$this
->
ccAddresses
);
$this
->
ccAddresses
=
$ccAddresses
;
$this
->
mailMessage
->
setCc
(
explode
(
','
,
$this
->
ccAddresses
)
)
;
return
$this
;
}
...
...
@@ -516,12 +530,12 @@ class MailTemplateService {
}
/**
* @param
array
$bccAddresses
* @param
string
$bccAddresses
* @return MailTemplateService
*/
public
function
setBccAddresses
(
array
$bccAddresses
)
{
$this
->
bccAddresses
[]
=
$bccAddresses
;
$this
->
mailMessage
->
setBcc
(
$this
->
bccAddresses
);
public
function
setBccAddresses
(
$bccAddresses
)
{
$this
->
bccAddresses
=
$bccAddresses
;
$this
->
mailMessage
->
setBcc
(
explode
(
','
,
$this
->
bccAddresses
)
)
;
return
$this
;
}
...
...
@@ -556,4 +570,15 @@ class MailTemplateService {
return
$this
->
mailMessage
;
}
/**
* use all values from the given template
*
* @param Template $template
*/
private
function
loadTemplateValues
(
$template
)
{
$this
->
setFromAddress
(
$template
->
getFromMail
(),
$template
->
getFromName
());
$this
->
setCcAddresses
(
$template
->
getCc
());
$this
->
setBccAddresses
(
$template
->
getBcc
());
$this
->
setReplyToAddress
(
$template
->
getReplyTo
());
}
}
Configuration/TCA/tx_sgmail_domain_model_mail.php
View file @
e599a554
...
...
@@ -144,6 +144,20 @@ return [
'config'
=>
[
'type'
=>
'input'
],
],
'sending_time'
=>
[
'exclude'
=>
TRUE
,
'label'
=>
'LLL:EXT:sg_mail/Resources/Private/Language/locallang_db.xlf:tx_sgmail_domain_model_mail.sending_time'
,
'config'
=>
[
'type'
=>
'input'
],
],
'reply_to'
=>
[
'exclude'
=>
TRUE
,
'label'
=>
'LLL:EXT:sg_mail/Resources/Private/Language/locallang_db.xlf:tx_sgmail_domain_model_mail.reply_to'
,
'config'
=>
[
'type'
=>
''
],
]
]
];
Resources/Private/Language/de.locallang_db.xlf
View file @
e599a554
...
...
@@ -45,6 +45,14 @@
<source>
Priority (Lowest = 0 | Low = 50 | Medium = 100 | High = 150 | Highest = 200)
</source>
<target>
Priorität (Niedrigstes = 0 | Niedrig = 50 | Mittel = 100 | Hoch = 150 | Höchste = 200)
</target>
</trans-unit>
<trans-unit
id=
"tx_sgmail_domain_model_mail.reply_to"
approved=
"yes"
>
<source>
Reply To
</source>
<target>
Antwort an
</target>
</trans-unit>
<trans-unit
id=
"tx_sgmail_domain_model_mail.sending_time"
approved=
"yes"
>
<source>
Sending Time
</source>
<target>
Abgesendet
</target>
</trans-unit>
<trans-unit
id=
"tx_sgmail_domain_model_mail.sent"
approved=
"yes"
>
<source>
Sent
</source>
<target>
Gesendet
</target>
...
...
Resources/Private/Language/locallang_db.xlf
View file @
e599a554
...
...
@@ -36,6 +36,12 @@
<trans-unit
id=
"tx_sgmail_domain_model_mail.priority"
>
<source>
Priority (Lowest = 0 | Low = 50 | Medium = 100 | High = 150 | Highest = 200)
</source>
</trans-unit>
<trans-unit
id=
"tx_sgmail_domain_model_mail.reply_to"
>
<source>
Reply To
</source>
</trans-unit>
<trans-unit
id=
"tx_sgmail_domain_model_mail.sending_time"
>
<source>
Sending Time
</source>
</trans-unit>
<trans-unit
id=
"tx_sgmail_domain_model_mail.sent"
>
<source>
Sent
</source>
</trans-unit>
...
...
ext_tables.sql
View file @
e599a554
...
...
@@ -13,6 +13,8 @@ CREATE TABLE tx_sgmail_domain_model_mail (
priority
int
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
extension_key
varchar
(
30
)
DEFAULT
''
NOT
NULL
,
template_name
varchar
(
30
)
DEFAULT
''
NOT
NULL
,
reply_to
varchar
(
30
)
DEFAULT
''
NOT
NULL
,
sending_time
int
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
tstamp
int
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
crdate
int
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment