Skip to content

Commit

Permalink
Merge pull request #66 from slub/feature-send-confirmation-only-once
Browse files Browse the repository at this point in the history
Feature send confirmation only once
  • Loading branch information
Alexander Bigga authored Jun 14, 2021
2 parents 25b8f1a + aff6fc5 commit 6da83dd
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 13 deletions.
66 changes: 66 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

# CSS-Files
[*.css]
indent_style = space
indent_size = 4

# HTML-Files
[*.html]
indent_style = space
indent_size = 4

# TMPL-Files
[*.tmpl]
indent_style = space
indent_size = 4

# LESS-Files
[*.less]
indent_style = space
indent_size = 4

# JS-Files
[*.js]
indent_style = space
indent_size = 4

# PHP-Files
[*.php]
indent_style = space
indent_size = 4

# MD-Files
[*.md]
indent_style = space
indent_size = 4

# ReST-Files
[*.rst]
indent_style = space
indent_size = 3

# TypoScript
[*.typoscript]
indent_style = space
indent_size = 4

# YML-Files
[{*.yml,*.yaml}]
indent_style = space
indent_size = 4

# package.json, composer.json or .travis.yml
[{package.json,composer.json,.travis.yml}]
indent_style = space
indent_size = 2
40 changes: 38 additions & 2 deletions Classes/Helper/EmailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public static function sendTemplateEmail(
$useSimfonyMailer = true;
}

// array of files to unlink after email has been sent
$unlinkFiles = [];

/** @var \TYPO3Fluid\Fluid\View\StandaloneView $emailViewHTML */
$emailViewHTML = $objectManager->get('TYPO3\\CMS\\Fluid\\View\\StandaloneView');
$emailViewHTML->getRequest()->setControllerExtensionName('SlubEvents');
Expand All @@ -93,8 +96,7 @@ public static function sendTemplateEmail(
} else {
$message->setBody(EmailHelper::html2rest($emailTextHTML));
$message->addPart($emailTextHTML, 'text/html');
}

}

// attach ics-File
if ($variables['attachIcs'] == true) {
Expand All @@ -117,11 +119,14 @@ public static function sendTemplateEmail(
20
)
. '-' . strtolower($templateName) . '-' . $variables['event']->getUid() . '.ics';

GeneralUtility::writeFileToTypo3tempDir(
$eventIcsFile,
implode("\r\n", array_filter(explode("\r\n", $ics->render())))
);

$unlinkFiles[] = $eventIcsFile;

// attach additionally ics as file
if ($useSimfonyMailer) {
$message->attachFromPath($eventIcsFile);
Expand All @@ -132,6 +137,17 @@ public static function sendTemplateEmail(
$message->addPart(implode("\r\n", array_filter(explode("\r\n", $ics->render()))), 'text/calendar', 'utf-8');
}

if ($variables['settings']['email']['keepLocalFilesForDebugging']) {
$debugFile = Environment::getPublicPath() . 'typo3temp/tx_slubevents/' .
substr(
preg_replace('/[^\w]/', '', strtolower($variables['nameTo'])),
0,
20
)
. '-' . strtolower($templateName) . (isset($variables['event']) ? '-' . $variables['event']->getUid() : '' ) . '.html';
GeneralUtility::writeFileToTypo3tempDir($debugFile, $emailViewHTML->render());
}

}
// attach CSV-File
if ($variables['attachCsv'] == true) {
Expand All @@ -156,6 +172,8 @@ public static function sendTemplateEmail(
. '-' . strtolower($templateName) . '.csv';
GeneralUtility::writeFileToTypo3tempDir($eventCsvFile, $csv->render());

$unlinkFiles[] = $eventCsvFile;

// attach CSV-File
if ($useSimfonyMailer) {
$message->attachFromPath($eventCsvFile);
Expand All @@ -165,8 +183,26 @@ public static function sendTemplateEmail(
}
}

if ($variables['settings']['email']['keepLocalFilesForDebugging']) {
$debugFile = Environment::getPublicPath() . '/typo3temp/tx_slubevents/' .
substr(
preg_replace('/[^\w]/', '', strtolower($variables['nameTo'])),
0,
20
)
. '-' . strtolower($templateName) . (isset($variables['event']) ? '-' . $variables['event']->getUid() : '' ) . '.html';
GeneralUtility::writeFileToTypo3tempDir($debugFile, $emailTextHTML);
}

$message->send();

// remove files from typo3temp if not kept for debuggin purpose
if (empty($variables['settings']['email']['keepLocalFilesForDebugging'])) {
foreach ($unlinkFiles as $file) {
GeneralUtility::unlink_tempfile($file);
}
}

return $message->isSent();
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ plugin.tx_slubevents {
sendEmailOnEveryBooking = 0
}

email {
# Keep ICS and html files sent to contacts for debugging purpose. DON'T USE IN PRODUCTION!
keepLocalFilesForDebugging = 0
}

# --------------
# List
# --------------
Expand Down Expand Up @@ -131,7 +136,7 @@ printCal {

config {
disableAllHeaderCode = 1
additionalHeaders {
additionalHeaders {
10 {
header = Content-type:text/calendar; charset=utf-8;
}
Expand Down
19 changes: 18 additions & 1 deletion Documentation/AdministratorManual/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ Configure Email Handling
Default
``[email protected]``

.. container:: table-row

Property
email.keepLocalFilesForDebugging

Data type
string

Description
Keep files (.ics, .csv, .html) sent by email for debugging purpose.
The files are stored in :code:`typo3temp/tx_slubevents/`.

**Do not use this setting on production environment!**

Default
0 - Do not keep files.

.. container:: table-row

Property
Expand Down Expand Up @@ -273,4 +290,4 @@ simply add these line to your registration form template
</label>
While the property ``acceptpp`` is submitted, it's needed to be checked
to submit a valid registration.
to submit a valid registration.
4 changes: 2 additions & 2 deletions Resources/Private/Partials/Subscriber/FormFields.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
<span class="required">*</span>
</label>

<f:form.checkbox value="1" property="acceptpp" id="acceptpp"/> <label for="acceptpp"> <f:translate key="tx_slubevents_domain_model_subscriber.acceptpp"/> <span class="required">*</span> </label>

<f:if condition="{event.maxNumber} >= {se:format.freePlacesLeft(event:'{event}')} || {event.maxNumber} == 0">
<f:then>
<f:form.textfield id="number" property="number" type="number"
Expand All @@ -47,5 +45,7 @@
required="required"/>
</f:else>
</f:if>
<f:form.checkbox value="1" property="acceptpp" id="acceptpp"/> <label for="acceptpp"> <f:translate key="tx_slubevents_domain_model_subscriber.acceptpp"/> <span class="required">*</span> </label>

<f:form.hidden property="editcode" value="<se:format.editCode event='{event}' />"/>
<f:form.hidden property="message" value=""/>
4 changes: 1 addition & 3 deletions ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
defined('TYPO3_MODE') || die();

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Slub.SlubEvents',
Expand Down
5 changes: 1 addition & 4 deletions ext_tables.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}

defined('TYPO3_MODE') || die();

/***************************************************************
* Backend module
Expand Down

0 comments on commit 6da83dd

Please sign in to comment.