Merge branch 'create-poll-fix' into 'develop'

fix(create_poll): don't send emails in case of DB transaction errors

See merge request framasoft/framadate/framadate!384
This commit is contained in:
Thomas Citharel 2019-04-19 20:44:14 +02:00
commit 1d0b565594
6 changed files with 41 additions and 12 deletions

View File

@ -41,6 +41,7 @@ class Form
public $choix_sondage;
public $ValueMax;
public $errors = [];
/**
* Tells if users can modify their choices.

View File

@ -216,16 +216,24 @@ class PollService {
list($poll_id, $admin_poll_id) = $this->createPoll($form);
// Send confirmation by mail if enabled
// Everything went well
$this->notificationService->sendPollCreationMails($form->admin_mail, $form->admin_name, $form->title, $poll_id, $admin_poll_id);
if (!is_null($ids)) {
// Everything went well
$this->notificationService->sendPollCreationMails($form->admin_mail, $form->admin_name, $form->title, $poll_id, $admin_poll_id);
// Clean Form data in session
$this->sessionService->removeAll('form');
// Creation message
$this->sessionService->set("Framadate", "messagePollCreated", TRUE);
// Delete old polls
$this->purgeService->repeatedCleanings();
// Clean Form data in session
$this->sessionService->removeAll('form');
// Creation message
$this->sessionService->set("Framadate", "messagePollCreated", TRUE);
// Delete old polls
$this->purgeService->repeatedCleanings();
} else {
// Add an error in the form
$form->errors = [
__('Error', 'GenericErrorPollCreation')
];
// TODO: change this to use sessionService function
$_SESSION['form'] = serialize($form);
}
return $admin_poll_id;
}

View File

@ -56,7 +56,7 @@ if (!isset($form->title) || !isset($form->admin_name) || ($config['use_smtp'] &&
$step = 1;
} elseif (isset($_POST['confirmation'])) {
$step = 4;
} elseif (empty($_POST['fin_sondage_autre']) ) {
} elseif (empty($form->errors) && empty($_POST['fin_sondage_autre']) ) {
$step = 2;
} else {
$step = 3;
@ -137,6 +137,7 @@ switch ($step) {
$smarty->assign('end_date_str', $end_date_str);
$smarty->assign('default_poll_duration', $config['default_poll_duration']);
$smarty->assign('use_smtp', $config['use_smtp']);
$smarty->assign('errors', $form->errors);
$smarty->display('create_poll_step_3.tpl');
exit;
@ -152,6 +153,10 @@ switch ($step) {
if (!is_null($admin_poll_id)) {
// Redirect to poll administration
header('Location:' . Utils::getUrlSondage($admin_poll_id, true));
} else {
// Redirect to current page
$referer = $_SERVER['HTTP_REFERER'];
header("Location: $referer");
}
exit;

View File

@ -54,7 +54,7 @@ if (!isset($form->title) || !isset($form->admin_name) || ($config['use_smtp'] &&
$step = 1;
} else if (!empty($_POST['confirmation'])) {
$step = 4;
} else if (empty($_POST['choixheures']) || isset($form->totalchoixjour)) {
} else if (empty($form->errors) && (empty($_POST['choixheures']) || isset($form->totalchoixjour))) {
$step = 2;
} else {
$step = 3;
@ -173,6 +173,7 @@ switch ($step) {
$smarty->assign('end_date_str', $end_date_str);
$smarty->assign('default_poll_duration', $config['default_poll_duration']);
$smarty->assign('use_smtp', $config['use_smtp']);
$smarty->assign('errors', $form->errors);
$smarty->display('create_poll_step_3.tpl');
exit;
@ -188,6 +189,10 @@ switch ($step) {
if (!is_null($admin_poll_id)) {
// Redirect to poll administration
header('Location:' . Utils::getUrlSondage($admin_poll_id, true));
} else {
// Redirect to current page
$referer = $_SERVER['HTTP_REFERER'];
header("Location: $referer");
}
exit;

View File

@ -548,6 +548,10 @@ msgstr "Failed to save poll"
msgid "Forbidden!"
msgstr "Forbidden!"
#: .Error.GenericErrorPollCreation
msgid "GenericErrorPollCreation"
msgstr "Oh no! Your poll could not be created at the moment. Sorry about that. Please try again later."
#: .Error.Identifier+is+already+used
msgid "Identifier is already used"
msgstr "Identifier is already used"
@ -1920,4 +1924,3 @@ msgid ""
msgstr ""
"Your vote has been saved, but please note: you need to keep this "
"personalised link to be able to edit your vote."

View File

@ -38,6 +38,13 @@
<p>{__('Step 3', 'Then you will receive two emails: one containing the link of your poll for sending to the participants, the other containing the link to the poll administration page.')}</p>
{/if}
</div>
{if !empty($errors)}
<div class="alert alert-danger">
{foreach $errors as $error}
<p>{$error}</p>
{/foreach}
</div>
{/if}
<p class="text-right">
<button class="btn btn-default" onclick="javascript:window.history.back();" title="{__('Step 3', 'Back to step 2')}">{__('Generic', 'Back')}</button>
<button name="confirmation" value="confirmation" type="submit" class="btn btn-success">{__('Step 3', 'Create the poll')}</button>