Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_mail
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_mail
Commits
5989461c
Commit
5989461c
authored
6 years ago
by
Torsten Oppermann
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Implement registration, started work on exception handling
parent
9da3895b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!12
Feature backend config
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Classes/Controller/ConfigurationController.php
+127
-18
127 additions, 18 deletions
Classes/Controller/ConfigurationController.php
Classes/Controller/MailController.php
+4
-0
4 additions, 0 deletions
Classes/Controller/MailController.php
with
131 additions
and
18 deletions
Classes/Controller/ConfigurationController.php
+
127
−
18
View file @
5989461c
...
...
@@ -27,21 +27,26 @@ namespace SGalinski\SgMail\Controller;
***************************************************************/
use
SGalinski\SgMail\Service\BackendService
;
use
SGalinski\SgMail\Service\MailTemplateService
;
use
SGalinski\SgMail\Service\TypoScriptSettingsService
;
use
SGalinski\SgMail\Session\PhpSession
;
use
TYPO3\CMS\Backend\Template\Components\DocHeaderComponent
;
use
TYPO3\CMS\Backend\Utility\BackendUtility
;
use
TYPO3\CMS\Core\Cache\CacheManager
;
use
TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
;
use
TYPO3\CMS\Core\Exception
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Core\Utility\VersionNumberUtility
;
use
TYPO3\CMS\Extbase\Mvc\Controller\ActionController
;
use
TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
;
use
TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
;
use
TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
;
use
TYPO3\CMS\Extbase\Object\ObjectManager
;
use
TYPO3\CMS\Extbase\Utility\LocalizationUtility
;
/**
* Controller for the configuration mode of the backend module
*/
class
ConfigurationController
extends
ActionController
{
const
DEFAULT_EXTENSION_KEY
=
'sg_mail'
;
/**
* DocHeaderComponent
*
...
...
@@ -64,19 +69,6 @@ class ConfigurationController extends ActionController {
public
function
indexAction
(
$selectedTemplate
=
NULL
,
$selectedExtension
=
NULL
,
array
$filters
=
[])
{
$pageUid
=
(
int
)
GeneralUtility
::
_GP
(
'id'
);
// set session key
if
(
!
(
$this
->
session
instanceof
PhpSession
))
{
$this
->
session
=
$this
->
objectManager
->
get
(
PhpSession
::
class
);
$this
->
session
->
setSessionKey
(
'sg_mail_controller_session'
);
}
else
{
$this
->
session
->
setSessionKey
(
'sg_mail_controller_session'
);
}
// store the user selection in the session
if
(
$this
->
request
->
hasArgument
(
'controller'
))
{
$this
->
session
->
setDataByKey
(
'mode'
,
BackendService
::
BACKEND_MODE_EDITOR_CONTROLLER
);
}
$registerArray
=
BackendService
::
getNonBlacklistedTemplates
(
$pageUid
);
if
(
$selectedTemplate
===
NULL
||
$selectedTemplate
===
''
)
{
if
(
!
empty
(
$registerArray
))
{
...
...
@@ -107,6 +99,8 @@ class ConfigurationController extends ActionController {
/**
* Create the template or display errors that occured
*
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public
function
createAction
()
{
try
{
...
...
@@ -118,9 +112,124 @@ class ConfigurationController extends ActionController {
$subject
=
$configuration
[
'subject'
];
$description
=
$configuration
[
'description'
];
$this
->
redirect
(
'index'
);
}
catch
(
NoSuchArgumentException
$e
)
{
// parse csv (,,,;,,,;)
$markersCsv
=
str_getcsv
(
$csv
,
';'
);
$markers
=
[];
foreach
(
$markersCsv
as
$markerCsv
)
{
$rowArray
=
GeneralUtility
::
trimExplode
(
','
,
$markerCsv
);
$markers
[]
=
[
'identifier'
=>
$rowArray
[
0
],
'value'
=>
$rowArray
[
1
],
'description'
=>
$rowArray
[
2
]
];
}
// write the new Register.php file
$this
->
writeRegisterFile
(
$templateName
,
self
::
DEFAULT_EXTENSION_KEY
,
$markers
,
$subject
,
$description
);
// call register function in mail template service class
MailTemplateService
::
registerExtensions
();
// clear caches
$this
->
clearCaches
();
// store selected template & extension key in the session
if
(
!
(
$this
->
session
instanceof
PhpSession
))
{
$this
->
session
=
$this
->
objectManager
->
get
(
PhpSession
::
class
);
$this
->
session
->
setSessionKey
(
'sg_mail_controller_session'
);
}
else
{
$this
->
session
->
setSessionKey
(
'sg_mail_controller_session'
);
}
$this
->
session
->
setDataByKey
(
'selectedTemplate'
,
$templateName
);
$this
->
session
->
setDataByKey
(
'selectedExtension'
,
self
::
DEFAULT_EXTENSION_KEY
);
$this
->
redirect
(
'index'
,
'Mail'
,
NULL
,
[
'message'
=>
LocalizationUtility
::
translate
(
'backend.create.message.success'
,
'sg_mail'
)]);
}
catch
(
Exception
$e
)
{
}
}
/**
* Write the mail registration file
*
* @TODO move this to the register service class when security update is merged. refactor in FormEditorController xclass as well
*
* @param string $templateKey
* @param string $extensionKey
* @param array $markers
* @param string $subject
* @param string $description
*/
private
function
writeRegisterFile
(
$templateKey
,
$extensionKey
,
$markers
,
$subject
,
$description
)
{
// get the location where registrations should be stored
$configurationLocation
=
$this
->
getRegistrationPath
();
$registerFolder
=
GeneralUtility
::
getFileAbsFileName
(
$configurationLocation
);
// create folder
GeneralUtility
::
mkdir
(
$registerFolder
);
$registerFile
=
GeneralUtility
::
getFileAbsFileName
(
$registerFolder
.
'/'
.
$templateKey
.
'.php'
);
// build the register array
$newRegisterArray
=
[
'extension_key'
=>
$extensionKey
,
'template_key'
=>
$templateKey
,
'description'
=>
$description
,
'subject'
=>
$subject
,
'markers'
=>
[]
];
// add the markers for this template
foreach
(
$markers
as
$marker
)
{
$markerName
=
$marker
[
'identifier'
];
$newRegisterArray
[
'markers'
][]
=
[
'marker'
=>
$markerName
,
'type'
=>
MailTemplateService
::
MARKER_TYPE_STRING
,
'value'
=>
$marker
[
'value'
],
'description'
=>
$marker
[
'description'
]
];
}
file_put_contents
(
$registerFile
,
'<?php return '
.
var_export
(
$newRegisterArray
,
TRUE
)
.
';'
);
}
/**
* Returns the path to the configured location where automatic mail template registrations should be
*
* @TODO move this to the register service class when security update is merged. refactor in FormEditorController xclass as well
*
* @return string
*/
private
function
getRegistrationPath
():
string
{
// get typoscript settings from sg mail
/** @var TypoScriptSettingsService $typoScriptSettingsService */
$typoScriptSettingsService
=
$this
->
objectManager
->
get
(
TypoScriptSettingsService
::
class
);
$tsSettings
=
$typoScriptSettingsService
->
getSettings
(
0
,
'tx_sgmail'
);
// get the location where automatic registrations should be stored
return
'EXT:'
.
$tsSettings
[
'mail'
][
'configurationLocation'
]
.
'/'
.
MailTemplateService
::
CONFIG_PATH
;
}
/**
* Clear the sgmail register cache
*
* @TODO move this to the register service class when security update is merged. refactor in FormEditorController xclass as well
*
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
private
function
clearCaches
()
{
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
$cacheManager
=
$objectManager
->
get
(
CacheManager
::
class
);
/** @var FrontendInterface $cache */
$cache
=
$cacheManager
->
getCache
(
MailTemplateService
::
CACHE_NAME
);
/** @var FrontendInterface $cache */
$cache
->
flush
();
}
}
This diff is collapsed.
Click to expand it.
Classes/Controller/MailController.php
+
4
−
0
View file @
5989461c
...
...
@@ -81,6 +81,10 @@ class MailController extends ActionController {
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
*/
public
function
indexAction
(
array
$parameters
=
[])
{
if
(
$this
->
request
->
hasArgument
(
'message'
))
{
}
$pid
=
(
int
)
GeneralUtility
::
_GP
(
'id'
);
if
(
!
(
$this
->
session
instanceof
PhpSession
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment