Skip to content

Commit 09428b4

Browse files
authored
Merge pull request #271 from kartolo/release/v7.0.1
[TASK] release v7.0.1
2 parents adc7f5d + 74cdebb commit 09428b4

11 files changed

+82
-85
lines changed

Classes/Command/InvokeMailerEngineCommand.php

+13-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Command\Command;
1919
use Symfony\Component\Console\Input\InputInterface;
2020
use Symfony\Component\Console\Output\OutputInterface;
21+
use Symfony\Component\Console\Style\SymfonyStyle;
2122
use TYPO3\CMS\Core\Core\Environment;
2223
use TYPO3\CMS\Core\Utility\GeneralUtility;
2324

@@ -45,7 +46,6 @@ class InvokeMailerEngineCommand extends Command
4546
public function configure()
4647
{
4748
$this->setDescription('Invoke Mailer Engine of EXT:directmail');
48-
$this->setHelp('Describe ...');
4949
$this->setHelp('
5050
Sends newsletters which are ready to send.
5151
@@ -63,17 +63,21 @@ public function configure()
6363
*/
6464
protected function execute(InputInterface $input, OutputInterface $output)
6565
{
66+
$io = new SymfonyStyle($input, $output);
67+
$io->title($this->getDescription());
68+
$lockfile = Environment::getPublicPath() . '/typo3temp/tx_directmail_cron.lock';
69+
6670
// Check if cronjob is already running:
67-
if (@file_exists(Environment::getPublicPath() . '/typo3temp/tx_directmail_cron.lock')) {
68-
// If the lock is not older than 1 day, skip index creation:
69-
if (filemtime(Environment::getPublicPath() . '/typo3temp/tx_directmail_cron.lock') > (time() - (60 * 60 * 24))) {
70-
die('TYPO3 Direct Mail Cron: Aborting, another process is already running!' . LF);
71+
if (@file_exists($lockfile)) {
72+
// If the lock is not older than 1 day, skip:
73+
if (filemtime($lockfile) > (time() - (60 * 60 * 24))) {
74+
$io->warning('TYPO3 Direct Mail Cron: Aborting, another process is already running!');
75+
return 0;
7176
} else {
72-
echo('TYPO3 Direct Mail Cron: A .lock file was found but it is older than 1 day! Processing mails ...' . LF);
77+
$io->writeln('TYPO3 Direct Mail Cron: A .lock file was found but it is older than 1 day! Processing mails ...');
7378
}
7479
}
75-
76-
$lockfile = Environment::getPublicPath() . '/typo3temp/tx_directmail_cron.lock';
80+
7781
touch($lockfile);
7882
// Fixing filepermissions
7983
GeneralUtility::fixPermissions($lockfile);
@@ -87,5 +91,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
8791
$htmlmail->runcron();
8892

8993
unlink($lockfile);
94+
return 0;
9095
}
9196
}

Classes/DirectMailUtility.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -1079,20 +1079,13 @@ public static function createDirectMailRecordFromPage($pageUid, array $parameter
10791079
}
10801080

10811081
$pageRecord = BackendUtility::getRecord('pages', $pageUid);
1082-
// Fetch page title from pages_language_overlay
1082+
// Fetch page title from translated page
10831083
if ($newRecord['sys_language_uid'] > 0) {
1084-
if (strpos(VersionNumberUtility::getNumericTypo3Version(), '9') === 0) {
1085-
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1086-
$queryBuilder
1087-
->select('title')
1088-
->from('pages')
1089-
->where($queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT)));
1090-
} else {
1091-
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages_language_overlay');
1092-
$queryBuilder->select('title')
1093-
->from('pages_language_overlay')
1094-
->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT)));
1095-
}
1084+
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1085+
$queryBuilder
1086+
->select('title')
1087+
->from('pages')
1088+
->where($queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT)));
10961089

10971090
$pageRecordOverlay = $queryBuilder->andWhere(
10981091
$queryBuilder->expr()->eq(

Classes/Dmailer.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public function getListOfRecipentCategories(string $table, int $uid): string
465465
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
466466
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
467467
$statement = $queryBuilder
468-
->select('uid_foreign')
468+
->select($relationTable . '.uid_foreign')
469469
->from($relationTable, $relationTable)
470470
->leftJoin($relationTable, $table, $table, $relationTable . '.uid_local = ' . $table . '.uid')
471471
->where($queryBuilder->expr()->eq($relationTable . '.uid_local', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
@@ -904,7 +904,7 @@ public function setContent(&$mailer)
904904
{
905905
// todo: css??
906906
// iterate through the media array and embed them
907-
if ($this->includeMedia) {
907+
if ($this->includeMedia && !empty($this->theParts['html']['content'])) {
908908
// extract all media path from the mail message
909909
$this->extractMediaLinks();
910910
foreach ($this->theParts['html']['media'] as $media) {
@@ -923,11 +923,11 @@ public function setContent(&$mailer)
923923
}
924924

925925
// set the html content
926-
if ($this->theParts['html']) {
926+
if ($this->theParts['html']['content']) {
927927
$mailer->html($this->theParts['html']['content']);
928928
}
929929
// set the plain content as alt part
930-
if ($this->theParts['plain']) {
930+
if ($this->theParts['plain']['content']) {
931931
$mailer->text($this->theParts['plain']['content']);
932932
}
933933

@@ -967,7 +967,7 @@ public function sendTheMail($recipient, $recipRow = null)
967967
}
968968

969969
if (GeneralUtility::validEmail($this->dmailer['sys_dmail_rec']['return_path'])) {
970-
$mailer->returnPath($this->dmailer['sys_dmail_rec']['return_path']);
970+
$mailer->sender($this->dmailer['sys_dmail_rec']['return_path']);
971971
}
972972

973973
// TODO: setContent should set the images (includeMedia) or add attachment

Classes/Importer.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function cmd_displayImport()
119119
// TYPO3 6.0 returns an object...
120120
if (is_object($this->indata['newFile'][0])) {
121121
$storageConfig = $this->indata['newFile'][0]->getStorage()->getConfiguration();
122-
$this->indata['newFile'] = $storageConfig['basePath'] . ltrim($this->indata['newFile'][0]->getIdentifier(), '/');
122+
$this->indata['newFile'] = rtrim($storageConfig['basePath'], '/') . '/' . ltrim($this->indata['newFile'][0]->getIdentifier(), '/');
123123
}
124124
} elseif (!empty($this->indata['csv']) && empty($_FILES['upload_1']['name'])) {
125125
if (((strpos($currentFileInfo['file'], 'import')=== false)?0:1) && ($currentFileInfo['realFileext'] === 'txt')) {
@@ -137,7 +137,7 @@ public function cmd_displayImport()
137137
$stepCurrent = 'mapping';
138138
}
139139

140-
if ($this->indata['csv'] !== '') {
140+
if (strlen($this->indata['csv']) > 0) {
141141
$this->indata['mode'] = 'csv';
142142
$this->indata['newFile'] = $this->writeTempFile();
143143
} elseif (!empty($this->indata['newFile'])) {
@@ -890,6 +890,9 @@ public function readCSV()
890890
ini_set('auto_detect_line_endings', true);
891891
$mydata = array();
892892
$handle = fopen($this->indata['newFile'], 'r');
893+
if($handle === false) {
894+
return $mydata;
895+
}
893896
$delimiter = $this->indata['delimiter'];
894897
$encaps = $this->indata['encapsulation'];
895898
$delimiter = ($delimiter === 'comma') ? ',' : $delimiter;
@@ -929,6 +932,9 @@ public function readExampleCSV($records=3)
929932
$this->indata['newFile'] = Environment::getPublicPath() . '/' . $this->indata['newFile'];
930933
}
931934
$handle = fopen($this->indata['newFile'], 'r');
935+
if($handle === false) {
936+
return $mydata;
937+
}
932938
$i = 0;
933939
$delimiter = $this->indata['delimiter'];
934940
$encaps = $this->indata['encapsulation'];
@@ -969,7 +975,7 @@ public function convCharset(array $data)
969975
if ($dbCharset != $this->indata['charset']) {
970976
$converter = GeneralUtility::makeInstance(CharsetConverter::class);
971977
foreach ($data as $k => $v) {
972-
$data[$k] = $converter->conv($v, $this->indata['charset'], $dbCharset);
978+
$data[$k] = $converter->conv($v, strtolower($this->indata['charset']), $dbCharset);
973979
}
974980
}
975981
return $data;
@@ -1095,7 +1101,7 @@ public function writeTempFile()
10951101
}
10961102

10971103
if ($newfile) {
1098-
$csvFile['data'] = $this->indata['csv'];
1104+
$csvFile['data'] = $this->indata['csv'] ?? '';
10991105
$csvFile['target'] = $newfile;
11001106
$write = $this->fileProcessor->func_edit($csvFile);
11011107
}

Classes/Module/MailerEngine.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ public function deleteLink($uid)
465465
$icon = $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL);
466466
$dmail = BackendUtility::getRecord('sys_dmail', $uid);
467467

468-
if (!empty($dmail['scheduled_begin'])) {
468+
// show delete icon if newsletter hasn't been sent, or not yet finished sending
469+
if (!($dmail['scheduled_begin']) ||
470+
($dmail['scheduled_begin'] && $dmail['scheduled_end'] === 0)) {
469471
/** @var UriBuilder $uriBuilder */
470472
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
471473
$moduleUrl = $uriBuilder->buildUriFromRoute(

Classes/Scheduler/AnalyzeBounceMailAdditionalFields.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use TYPO3\CMS\Core\Localization\LanguageService;
1919
use TYPO3\CMS\Core\Messaging\FlashMessage;
2020
use TYPO3\CMS\Core\Utility\GeneralUtility;
21-
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
21+
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
2222
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
2323
use TYPO3\CMS\Scheduler\Task\AbstractTask;
2424

@@ -29,7 +29,7 @@
2929
* @package DirectMailTeam\DirectMail\Scheduler
3030
* @author Ivan Kartolo <[email protected]>
3131
*/
32-
class AnalyzeBounceMailAdditionalFields implements AdditionalFieldProviderInterface
32+
class AnalyzeBounceMailAdditionalFields extends AbstractAdditionalFieldProvider
3333
{
3434
public function __construct()
3535
{
@@ -128,15 +128,15 @@ public function validateAdditionalFields(array &$submittedData, SchedulerModuleC
128128
$imapStream = $mailServer->getImapStream();
129129
$return = true;
130130
} catch (\Exception $e) {
131-
$schedulerModule->addMessage(
131+
$this->addMessage(
132132
$this->getLanguangeService()->getLL('scheduler.bounceMail.dataVerification') .
133133
$e->getMessage(),
134134
FlashMessage::ERROR
135135
);
136136
$return = false;
137137
}
138138
} else {
139-
$schedulerModule->addMessage(
139+
$this->addMessage(
140140
$this->getLanguangeService()->getLL('scheduler.bounceMail.phpImapError'),
141141
FlashMessage::ERROR
142142
);

Classes/Scheduler/MailFromDraftAdditionalFields.php

+19-21
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
*/
1616

1717
use TYPO3\CMS\Backend\Utility\BackendUtility;
18+
use TYPO3\CMS\Core\Database\ConnectionPool;
1819
use TYPO3\CMS\Core\Messaging\FlashMessage;
19-
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
20+
use TYPO3\CMS\Core\Utility\GeneralUtility;
21+
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
2022
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
23+
use TYPO3\CMS\Scheduler\Task\AbstractTask;
2124

2225
/**
2326
* Aditional fields provider class for usage with the Scheduler's MailFromDraft task
@@ -26,7 +29,7 @@
2629
* @package TYPO3
2730
* @subpackage direct_mail
2831
*/
29-
class MailFromDraftAdditionalFields implements AdditionalFieldProviderInterface
32+
class MailFromDraftAdditionalFields extends AbstractAdditionalFieldProvider
3033
{
3134

3235
/**
@@ -35,7 +38,7 @@ class MailFromDraftAdditionalFields implements AdditionalFieldProviderInterface
3538
*
3639
* @param array $taskInfo reference to the array containing the info used in the add/edit form
3740
* @param object $task when editing, reference to the current task object. Null when adding.
38-
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject reference to the calling object (Scheduler's BE module)
41+
* @param SchedulerModuleController $schedulerModuleController reference to the calling object (Scheduler's BE module)
3942
*
4043
* @return array Array containg all the information pertaining to the additional fields
4144
* The array is multidimensional, keyed to the task class name and each field's id
@@ -45,12 +48,11 @@ class MailFromDraftAdditionalFields implements AdditionalFieldProviderInterface
4548
* ['cshKey'] => The CSH key for the field
4649
* ['cshLabel'] => The code of the CSH label
4750
*/
48-
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $parentObject)
51+
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModuleController)
4952
{
50-
51-
// Initialize extra field value
53+
// Initialize extra field value
5254
if (empty($taskInfo['selecteddraft'])) {
53-
if ($parentObject->CMD == 'edit') {
55+
if ($schedulerModuleController->CMD === 'edit') {
5456
// In case of edit, and editing a test task, set to internal value if not data was submitted already
5557
$taskInfo['selecteddraft'] = $task->draftUid;
5658
} else {
@@ -62,7 +64,7 @@ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleCont
6264
// fetch all available drafts
6365
$drafts = array();
6466

65-
$queryBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
67+
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
6668
->getQueryBuilderForTable('sys_dmail');
6769
$draftsInternal = $queryBuilder
6870
->select('*')
@@ -99,13 +101,12 @@ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleCont
99101
} else {
100102
foreach ($drafts as $draft) {
101103
// see #44577
102-
$selected = ($task->draftUid == $draft['uid'] ? ' selected="selected"' : '');
104+
$selected = ($task->draftUid === $draft['uid'] ? ' selected="selected"' : '');
103105
$fieldHtml .= '<option value="' . $draft['uid'] . '"' . $selected . '>' . $draft['subject'] . ' [' . $draft['uid'] . ']</option>';
104106
}
105107
}
106108
$fieldHtml = '<select name="tx_scheduler[selecteddraft]" id="' . $fieldID . '">' . $fieldHtml . '</select>';
107109

108-
109110
$additionalFields = array();
110111
$additionalFields[$fieldID] = array(
111112
'code' => $fieldHtml,
@@ -124,17 +125,17 @@ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleCont
124125
* If the task class is not relevant, the method is expected to return true
125126
*
126127
* @param array $submittedData Reference to the array containing the data submitted by the user
127-
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
128+
* @param SchedulerModuleController $schedulerModuleController Reference to the calling object (Scheduler's BE module)
128129
*
129130
* @return bool True if validation was ok (or selected class is not relevant), false otherwise
130131
*/
131-
public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
132+
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModuleController)
132133
{
133-
$draftUid = $submittedData['selecteddraft'] = intval($submittedData['selecteddraft']);
134+
$draftUid = $submittedData['selecteddraft'] = (int) $submittedData['selecteddraft'];
134135
if ($draftUid > 0) {
135136
$draftRecord = BackendUtility::getRecord('sys_dmail', $draftUid);
136137

137-
$queryBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
138+
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
138139
->getQueryBuilderForTable('sys_dmail');
139140
$draftsInternal = $queryBuilder
140141
->select('*')
@@ -145,19 +146,16 @@ public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Sched
145146
->execute()
146147
->fetchAll();
147148

148-
149-
150-
151149
if ($draftRecord['type'] == 2 || $draftRecord['type'] == 3) {
152150
$result = true;
153151
} else {
154152
// TODO: localization
155-
$parentObject->addMessage('No draft record selected', FlashMessage::ERROR);
153+
$this->addMessage('No draft record selected', FlashMessage::ERROR);
156154
$result = false;
157155
}
158156
} else {
159157
// TODO: localization
160-
$parentObject->addMessage('No drafts found. Please add one first through the direct mail process', FlashMessage::ERROR);
158+
$this->addMessage('No drafts found. Please add one first through the direct mail process', FlashMessage::ERROR);
161159
$result = false;
162160
}
163161

@@ -169,11 +167,11 @@ public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Sched
169167
* if the task class matches
170168
*
171169
* @param array $submittedData Array containing the data submitted by the user
172-
* @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
170+
* @param AbstractTask $task Reference to the current task object
173171
*
174172
* @return void
175173
*/
176-
public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
174+
public function saveAdditionalFields(array $submittedData, AbstractTask $task)
177175
{
178176
$task->setDraft($submittedData['selecteddraft']);
179177
}

Configuration/Commands.php

-15
This file was deleted.

Configuration/Services.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
services:
2+
_defaults:
3+
autowire: true
4+
autoconfigure: true
5+
public: false
6+
7+
DirectMailTeam\DirectMail\:
8+
resource: '../Classes/*'
9+
10+
DirectMailTeam\DirectMail\Command\InvokeMailerEngineCommand:
11+
tags:
12+
- name: 'console.command'
13+
command: 'directmail:invokemailerengine'
14+
description: 'Invoke Mailer Engine of EXT:directmail'
15+
# not required, defaults to false
16+
#hidden: false
17+
#schedulable: false

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
"class-alias-maps": [
4747
"Migrations/Code/ClassAliasMap.php"
4848
]
49+
},
50+
"typo3/cms": {
51+
"extension-key": "direct_mail"
4952
}
5053
}
5154
}

0 commit comments

Comments
 (0)