Skip to content
Snippets Groups Projects
Commit 92e9b02b authored by Torsten Oppermann's avatar Torsten Oppermann
Browse files

Merge branch 'new_version_4_0' into new_version_4_1

parents ad2ae457 344597a4
No related branches found
No related tags found
1 merge request!3New version 4 1
......@@ -171,30 +171,10 @@ class QueueController extends ActionController {
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \InvalidArgumentException
*/
public function exportAction(array $filters = []) {
$pageUid = (int) GeneralUtility::_GP('id');
$queue = $this->mailRepository->findAllEntries($pageUid, 0, $filters);
$exportString = 'Subject;Body;To;From;From Name;CC;BCC;Reply To;Extension;Template;Language' . LF;
foreach ($queue as $item) {
$exportString .= $item['mail_subject'] . ',';
if (strpos($item['mail_body'], ',') !== FALSE || strpos($item['mail_body'], '"') !== FALSE || strpos(
$item['mail_body'], "\n"
) !== FALSE) {
$item['mail_body'] = '"' . str_replace('"', '""', $item['mail_body']) . '"';
}
$exportString .= trim(preg_replace('/\s\s+/', ' ', strip_tags($item['mail_body']) . ';'));
$exportString .= $item['to_address'] . ';';
$exportString .= $item['from_address'] . ';';
$exportString .= $item['from_name'] . ';';
$exportString .= $item['cc_addresses'] . ';';
$exportString .= $item['bcc_addresses'] . ';';
$exportString .= $item['reply_to'] . ';';
$exportString .= $item['extension_key'] . ';';
$exportString .= $item['template_name'] . ';';
$exportString .= $item['language'] . LF;
}
$exportString = BackendService::getCsvFromQueue($filters);
header('Content-Type: application/force-download');
header('Content-Transfer-Encoding: Binary');
......@@ -202,6 +182,5 @@ class QueueController extends ActionController {
header('Content-Length: ' . strlen($exportString));
echo $exportString;
exit(0);
}
}
......@@ -27,6 +27,7 @@ namespace SGalinski\SgMail\Service;
***************************************************************/
use SGalinski\SgMail\Domain\Model\Template;
use SGalinski\SgMail\Domain\Repository\MailRepository;
use SGalinski\SgMail\Domain\Repository\TemplateRepository;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
......@@ -35,7 +36,6 @@ use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository;
use TYPO3\CMS\Extbase\Mvc\Request;
use TYPO3\CMS\Extbase\Object\ObjectManager;
......@@ -315,4 +315,76 @@ class BackendService {
return $frontendUserRepository->findAll()->toArray();
}
/**
* Generate a csv string from the queues, respecting the given filters
*
* @param array $filters
* @return string
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \InvalidArgumentException
*/
public static function getCsvFromQueue(array $filters = []) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** @var MailRepository $mailRepository */
$mailRepository = $objectManager->get(MailRepository::class);
$pageUid = (int) GeneralUtility::_GP('id');
/** @var array $queue */
$queue = $mailRepository->findAllEntries($pageUid, 0, $filters);
$totalQueueSize = count($queue);
$exportString = '';
if ($totalQueueSize && $queue) {
$ignoreFields = ['uid', 'pid', 'tstamp',
'password', 'starttime', 'endtime', 'deleted', 'sent', 'priority', 'crdate', 'cruser_id', 'hidden'];
$dateFields = ['tstamp', 'starttime', 'endtime', 'crdate'];
$export = [[]];
$first = TRUE;
/** @var array $mail */
foreach ($queue as $mail) {
if ($first) {
$first = FALSE;
foreach ($mail as $field => $value) {
if (!in_array($field, $ignoreFields, TRUE)) {
$label = isset($GLOBALS['TCA']['tx_sgmail_domain_model_mail']['columns'][$field]) ?
$GLOBALS['TCA']['fe_users']['columns'][$field]['label'] : '';
if (strpos($label, 'LLL:') === 0) {
$label = $GLOBALS['LANG']->sL($label);
}
$export[0][] = $label ?: $field;
}
}
}
}
$line = 1;
/** @var array $mail */
foreach ($queue as $mail) {
foreach ($mail as $field => $value) {
if (!in_array($field, $ignoreFields, TRUE)) {
if (in_array($field, $dateFields, TRUE)) {
$export[$line][] = $value ? date('d.m.Y', $value) : '';
} else {
$export[$line][] = (string) $value;
}
}
}
$line++;
}
foreach ($export as $line) {
/** @var array $line */
$fields = [];
foreach ($line as $field) {
$fields[] = '"' . $field . '"';
}
$exportString .= implode(',', $fields) . ';' . LF;
}
}
return trim(preg_replace('/\s\s+/', ' ', strip_tags($exportString)));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment