Skip to content

Commit

Permalink
Merge pull request #271 from kartolo/release/v7.0.1
Browse files Browse the repository at this point in the history
[TASK] release v7.0.1
  • Loading branch information
kartolo authored Aug 17, 2021
2 parents adc7f5d + 74cdebb commit 09428b4
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 85 deletions.
21 changes: 13 additions & 8 deletions Classes/Command/InvokeMailerEngineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand Down Expand Up @@ -45,7 +46,6 @@ class InvokeMailerEngineCommand extends Command
public function configure()
{
$this->setDescription('Invoke Mailer Engine of EXT:directmail');
$this->setHelp('Describe ...');
$this->setHelp('
Sends newsletters which are ready to send.
Expand All @@ -63,17 +63,21 @@ public function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->title($this->getDescription());
$lockfile = Environment::getPublicPath() . '/typo3temp/tx_directmail_cron.lock';

// Check if cronjob is already running:
if (@file_exists(Environment::getPublicPath() . '/typo3temp/tx_directmail_cron.lock')) {
// If the lock is not older than 1 day, skip index creation:
if (filemtime(Environment::getPublicPath() . '/typo3temp/tx_directmail_cron.lock') > (time() - (60 * 60 * 24))) {
die('TYPO3 Direct Mail Cron: Aborting, another process is already running!' . LF);
if (@file_exists($lockfile)) {
// If the lock is not older than 1 day, skip:
if (filemtime($lockfile) > (time() - (60 * 60 * 24))) {
$io->warning('TYPO3 Direct Mail Cron: Aborting, another process is already running!');
return 0;
} else {
echo('TYPO3 Direct Mail Cron: A .lock file was found but it is older than 1 day! Processing mails ...' . LF);
$io->writeln('TYPO3 Direct Mail Cron: A .lock file was found but it is older than 1 day! Processing mails ...');
}
}

$lockfile = Environment::getPublicPath() . '/typo3temp/tx_directmail_cron.lock';

touch($lockfile);
// Fixing filepermissions
GeneralUtility::fixPermissions($lockfile);
Expand All @@ -87,5 +91,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$htmlmail->runcron();

unlink($lockfile);
return 0;
}
}
19 changes: 6 additions & 13 deletions Classes/DirectMailUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -1079,20 +1079,13 @@ public static function createDirectMailRecordFromPage($pageUid, array $parameter
}

$pageRecord = BackendUtility::getRecord('pages', $pageUid);
// Fetch page title from pages_language_overlay
// Fetch page title from translated page
if ($newRecord['sys_language_uid'] > 0) {
if (strpos(VersionNumberUtility::getNumericTypo3Version(), '9') === 0) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder
->select('title')
->from('pages')
->where($queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT)));
} else {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages_language_overlay');
$queryBuilder->select('title')
->from('pages_language_overlay')
->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT)));
}
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder
->select('title')
->from('pages')
->where($queryBuilder->expr()->eq('l10n_parent', $queryBuilder->createNamedParameter($pageUid, \PDO::PARAM_INT)));

$pageRecordOverlay = $queryBuilder->andWhere(
$queryBuilder->expr()->eq(
Expand Down
10 changes: 5 additions & 5 deletions Classes/Dmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public function getListOfRecipentCategories(string $table, int $uid): string
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$statement = $queryBuilder
->select('uid_foreign')
->select($relationTable . '.uid_foreign')
->from($relationTable, $relationTable)
->leftJoin($relationTable, $table, $table, $relationTable . '.uid_local = ' . $table . '.uid')
->where($queryBuilder->expr()->eq($relationTable . '.uid_local', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
Expand Down Expand Up @@ -904,7 +904,7 @@ public function setContent(&$mailer)
{
// todo: css??
// iterate through the media array and embed them
if ($this->includeMedia) {
if ($this->includeMedia && !empty($this->theParts['html']['content'])) {
// extract all media path from the mail message
$this->extractMediaLinks();
foreach ($this->theParts['html']['media'] as $media) {
Expand All @@ -923,11 +923,11 @@ public function setContent(&$mailer)
}

// set the html content
if ($this->theParts['html']) {
if ($this->theParts['html']['content']) {
$mailer->html($this->theParts['html']['content']);
}
// set the plain content as alt part
if ($this->theParts['plain']) {
if ($this->theParts['plain']['content']) {
$mailer->text($this->theParts['plain']['content']);
}

Expand Down Expand Up @@ -967,7 +967,7 @@ public function sendTheMail($recipient, $recipRow = null)
}

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

// TODO: setContent should set the images (includeMedia) or add attachment
Expand Down
14 changes: 10 additions & 4 deletions Classes/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function cmd_displayImport()
// TYPO3 6.0 returns an object...
if (is_object($this->indata['newFile'][0])) {
$storageConfig = $this->indata['newFile'][0]->getStorage()->getConfiguration();
$this->indata['newFile'] = $storageConfig['basePath'] . ltrim($this->indata['newFile'][0]->getIdentifier(), '/');
$this->indata['newFile'] = rtrim($storageConfig['basePath'], '/') . '/' . ltrim($this->indata['newFile'][0]->getIdentifier(), '/');
}
} elseif (!empty($this->indata['csv']) && empty($_FILES['upload_1']['name'])) {
if (((strpos($currentFileInfo['file'], 'import')=== false)?0:1) && ($currentFileInfo['realFileext'] === 'txt')) {
Expand All @@ -137,7 +137,7 @@ public function cmd_displayImport()
$stepCurrent = 'mapping';
}

if ($this->indata['csv'] !== '') {
if (strlen($this->indata['csv']) > 0) {
$this->indata['mode'] = 'csv';
$this->indata['newFile'] = $this->writeTempFile();
} elseif (!empty($this->indata['newFile'])) {
Expand Down Expand Up @@ -890,6 +890,9 @@ public function readCSV()
ini_set('auto_detect_line_endings', true);
$mydata = array();
$handle = fopen($this->indata['newFile'], 'r');
if($handle === false) {
return $mydata;
}
$delimiter = $this->indata['delimiter'];
$encaps = $this->indata['encapsulation'];
$delimiter = ($delimiter === 'comma') ? ',' : $delimiter;
Expand Down Expand Up @@ -929,6 +932,9 @@ public function readExampleCSV($records=3)
$this->indata['newFile'] = Environment::getPublicPath() . '/' . $this->indata['newFile'];
}
$handle = fopen($this->indata['newFile'], 'r');
if($handle === false) {
return $mydata;
}
$i = 0;
$delimiter = $this->indata['delimiter'];
$encaps = $this->indata['encapsulation'];
Expand Down Expand Up @@ -969,7 +975,7 @@ public function convCharset(array $data)
if ($dbCharset != $this->indata['charset']) {
$converter = GeneralUtility::makeInstance(CharsetConverter::class);
foreach ($data as $k => $v) {
$data[$k] = $converter->conv($v, $this->indata['charset'], $dbCharset);
$data[$k] = $converter->conv($v, strtolower($this->indata['charset']), $dbCharset);
}
}
return $data;
Expand Down Expand Up @@ -1095,7 +1101,7 @@ public function writeTempFile()
}

if ($newfile) {
$csvFile['data'] = $this->indata['csv'];
$csvFile['data'] = $this->indata['csv'] ?? '';
$csvFile['target'] = $newfile;
$write = $this->fileProcessor->func_edit($csvFile);
}
Expand Down
4 changes: 3 additions & 1 deletion Classes/Module/MailerEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,9 @@ public function deleteLink($uid)
$icon = $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL);
$dmail = BackendUtility::getRecord('sys_dmail', $uid);

if (!empty($dmail['scheduled_begin'])) {
// show delete icon if newsletter hasn't been sent, or not yet finished sending
if (!($dmail['scheduled_begin']) ||
($dmail['scheduled_begin'] && $dmail['scheduled_end'] === 0)) {
/** @var UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$moduleUrl = $uriBuilder->buildUriFromRoute(
Expand Down
8 changes: 4 additions & 4 deletions Classes/Scheduler/AnalyzeBounceMailAdditionalFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\AbstractTask;

Expand All @@ -29,7 +29,7 @@
* @package DirectMailTeam\DirectMail\Scheduler
* @author Ivan Kartolo <[email protected]>
*/
class AnalyzeBounceMailAdditionalFields implements AdditionalFieldProviderInterface
class AnalyzeBounceMailAdditionalFields extends AbstractAdditionalFieldProvider
{
public function __construct()
{
Expand Down Expand Up @@ -128,15 +128,15 @@ public function validateAdditionalFields(array &$submittedData, SchedulerModuleC
$imapStream = $mailServer->getImapStream();
$return = true;
} catch (\Exception $e) {
$schedulerModule->addMessage(
$this->addMessage(
$this->getLanguangeService()->getLL('scheduler.bounceMail.dataVerification') .
$e->getMessage(),
FlashMessage::ERROR
);
$return = false;
}
} else {
$schedulerModule->addMessage(
$this->addMessage(
$this->getLanguangeService()->getLL('scheduler.bounceMail.phpImapError'),
FlashMessage::ERROR
);
Expand Down
40 changes: 19 additions & 21 deletions Classes/Scheduler/MailFromDraftAdditionalFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\AbstractTask;

/**
* Aditional fields provider class for usage with the Scheduler's MailFromDraft task
Expand All @@ -26,7 +29,7 @@
* @package TYPO3
* @subpackage direct_mail
*/
class MailFromDraftAdditionalFields implements AdditionalFieldProviderInterface
class MailFromDraftAdditionalFields extends AbstractAdditionalFieldProvider
{

/**
Expand All @@ -35,7 +38,7 @@ class MailFromDraftAdditionalFields implements AdditionalFieldProviderInterface
*
* @param array $taskInfo reference to the array containing the info used in the add/edit form
* @param object $task when editing, reference to the current task object. Null when adding.
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject reference to the calling object (Scheduler's BE module)
* @param SchedulerModuleController $schedulerModuleController reference to the calling object (Scheduler's BE module)
*
* @return array Array containg all the information pertaining to the additional fields
* The array is multidimensional, keyed to the task class name and each field's id
Expand All @@ -45,12 +48,11 @@ class MailFromDraftAdditionalFields implements AdditionalFieldProviderInterface
* ['cshKey'] => The CSH key for the field
* ['cshLabel'] => The code of the CSH label
*/
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $parentObject)
public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModuleController)
{

// Initialize extra field value
// Initialize extra field value
if (empty($taskInfo['selecteddraft'])) {
if ($parentObject->CMD == 'edit') {
if ($schedulerModuleController->CMD === 'edit') {
// In case of edit, and editing a test task, set to internal value if not data was submitted already
$taskInfo['selecteddraft'] = $task->draftUid;
} else {
Expand All @@ -62,7 +64,7 @@ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleCont
// fetch all available drafts
$drafts = array();

$queryBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('sys_dmail');
$draftsInternal = $queryBuilder
->select('*')
Expand Down Expand Up @@ -99,13 +101,12 @@ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleCont
} else {
foreach ($drafts as $draft) {
// see #44577
$selected = ($task->draftUid == $draft['uid'] ? ' selected="selected"' : '');
$selected = ($task->draftUid === $draft['uid'] ? ' selected="selected"' : '');
$fieldHtml .= '<option value="' . $draft['uid'] . '"' . $selected . '>' . $draft['subject'] . ' [' . $draft['uid'] . ']</option>';
}
}
$fieldHtml = '<select name="tx_scheduler[selecteddraft]" id="' . $fieldID . '">' . $fieldHtml . '</select>';


$additionalFields = array();
$additionalFields[$fieldID] = array(
'code' => $fieldHtml,
Expand All @@ -124,17 +125,17 @@ public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleCont
* If the task class is not relevant, the method is expected to return true
*
* @param array $submittedData Reference to the array containing the data submitted by the user
* @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject Reference to the calling object (Scheduler's BE module)
* @param SchedulerModuleController $schedulerModuleController Reference to the calling object (Scheduler's BE module)
*
* @return bool True if validation was ok (or selected class is not relevant), false otherwise
*/
public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $parentObject)
public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModuleController)
{
$draftUid = $submittedData['selecteddraft'] = intval($submittedData['selecteddraft']);
$draftUid = $submittedData['selecteddraft'] = (int) $submittedData['selecteddraft'];
if ($draftUid > 0) {
$draftRecord = BackendUtility::getRecord('sys_dmail', $draftUid);

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




if ($draftRecord['type'] == 2 || $draftRecord['type'] == 3) {
$result = true;
} else {
// TODO: localization
$parentObject->addMessage('No draft record selected', FlashMessage::ERROR);
$this->addMessage('No draft record selected', FlashMessage::ERROR);
$result = false;
}
} else {
// TODO: localization
$parentObject->addMessage('No drafts found. Please add one first through the direct mail process', FlashMessage::ERROR);
$this->addMessage('No drafts found. Please add one first through the direct mail process', FlashMessage::ERROR);
$result = false;
}

Expand All @@ -169,11 +167,11 @@ public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Sched
* if the task class matches
*
* @param array $submittedData Array containing the data submitted by the user
* @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
* @param AbstractTask $task Reference to the current task object
*
* @return void
*/
public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
public function saveAdditionalFields(array $submittedData, AbstractTask $task)
{
$task->setDraft($submittedData['selecteddraft']);
}
Expand Down
15 changes: 0 additions & 15 deletions Configuration/Commands.php

This file was deleted.

17 changes: 17 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

DirectMailTeam\DirectMail\:
resource: '../Classes/*'

DirectMailTeam\DirectMail\Command\InvokeMailerEngineCommand:
tags:
- name: 'console.command'
command: 'directmail:invokemailerengine'
description: 'Invoke Mailer Engine of EXT:directmail'
# not required, defaults to false
#hidden: false
#schedulable: false
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
"class-alias-maps": [
"Migrations/Code/ClassAliasMap.php"
]
},
"typo3/cms": {
"extension-key": "direct_mail"
}
}
}
Loading

0 comments on commit 09428b4

Please sign in to comment.