[TASK] Improve error and config handling
This commit is contained in:
parent
3797bf0800
commit
c2203a0d06
212
Classes/Controller/AbstractEIDController.php
Normal file
212
Classes/Controller/AbstractEIDController.php
Normal file
@ -0,0 +1,212 @@
|
|||||||
|
<?php
|
||||||
|
namespace Cjel\TemplatesAide\Controller;
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* This file is part of the "Templates Aide" Extension for TYPO3 CMS.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the
|
||||||
|
* LICENSE.txt file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* (c) 2021 Philipp Dieter <philippdieter@attic-media.net>
|
||||||
|
*
|
||||||
|
***/
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use TYPO3\CMS\Core\Cache\CacheManager;
|
||||||
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||||
|
use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
|
||||||
|
use TYPO3\CMS\Core\Log\LogManager;
|
||||||
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||||
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||||
|
use TYPO3\CMS\Frontend\Plugin\AbstractPlugin;
|
||||||
|
use TYPO3\CMS\Frontend\Utility\EidUtility;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AbstractEIDController
|
||||||
|
*/
|
||||||
|
class AbstractEIDController
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var BackendConfigurationManager
|
||||||
|
*/
|
||||||
|
protected $configurationManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ApiUtility
|
||||||
|
*/
|
||||||
|
protected $apiUtility = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* extension Key
|
||||||
|
*/
|
||||||
|
protected $extensionKey = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* objectManager
|
||||||
|
*/
|
||||||
|
protected $objectManager = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* storagePids
|
||||||
|
*/
|
||||||
|
protected $settings = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* storagePids
|
||||||
|
*/
|
||||||
|
protected $storagePids = [];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* logManager
|
||||||
|
*/
|
||||||
|
protected $logManager = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* logger
|
||||||
|
*/
|
||||||
|
protected $importLogger = null;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* returns the extensionkey set in the exended calss
|
||||||
|
*/
|
||||||
|
public function getExtensionKey() {
|
||||||
|
return $this->extensionKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct
|
||||||
|
*
|
||||||
|
* @param ObjectManager $objectManager
|
||||||
|
* @param array $configuration
|
||||||
|
*/
|
||||||
|
public function __construct(ObjectManager $objectManager = null,
|
||||||
|
array $configuration = [])
|
||||||
|
{
|
||||||
|
$this->objectManager = GeneralUtility::makeInstance(
|
||||||
|
ObjectManager::class
|
||||||
|
);
|
||||||
|
$this->initFrontendController();
|
||||||
|
$this->configurationManager = $this->objectManager->get(
|
||||||
|
ConfigurationManagerInterface::class
|
||||||
|
);
|
||||||
|
$this->configurationManager->setConfiguration(array());
|
||||||
|
$frameworkConfiguration = $this->configurationManager->getConfiguration(
|
||||||
|
ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK,
|
||||||
|
$this->getExtensionKey()
|
||||||
|
);
|
||||||
|
$this->settings = $frameworkConfiguration;
|
||||||
|
$this->storagePids = explode(
|
||||||
|
',',
|
||||||
|
str_replace(
|
||||||
|
' ',
|
||||||
|
'',
|
||||||
|
$frameworkConfiguration['persistence']['storagePid']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$this->logManager = $this->objectManager->get(
|
||||||
|
LogManager::Class
|
||||||
|
);
|
||||||
|
$this->importLogger = $this->logManager->getLogger(
|
||||||
|
'importLogger'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize frontentController
|
||||||
|
*/
|
||||||
|
private function initFrontendController()
|
||||||
|
{
|
||||||
|
$currentDomain = strtok(GeneralUtility::getIndpEnv('HTTP_HOST'), ':');
|
||||||
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||||
|
->getQueryBuilderForTable('sys_domain');
|
||||||
|
$queryBuilder->setRestrictions(
|
||||||
|
GeneralUtility::makeInstance(DefaultRestrictionContainer::class)
|
||||||
|
);
|
||||||
|
$result = $queryBuilder
|
||||||
|
->select('uid', 'pid', 'domainName')
|
||||||
|
->from('sys_domain')
|
||||||
|
->where(
|
||||||
|
$queryBuilder->expr()->eq(
|
||||||
|
'domainName',
|
||||||
|
$queryBuilder->createNamedParameter(
|
||||||
|
$currentDomain,
|
||||||
|
\PDO::PARAM_STR
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
->orderBy('sorting', 'ASC')
|
||||||
|
->execute()
|
||||||
|
->fetchAll();
|
||||||
|
//if (count($result) < 1) {
|
||||||
|
// throw new \Exception('Domain not configured');
|
||||||
|
//}
|
||||||
|
$frontendController = GeneralUtility::makeInstance(
|
||||||
|
\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class,
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS'],
|
||||||
|
null,
|
||||||
|
0,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
$GLOBALS['TSFE'] = $frontendController;
|
||||||
|
$frontendController->connectToDB();
|
||||||
|
$frontendController->fe_user = EidUtility::initFeUser();
|
||||||
|
$frontendController->id = $result[0]['pid'];
|
||||||
|
$frontendController->determineId();
|
||||||
|
$frontendController->initTemplate();
|
||||||
|
$frontendController->getConfigArray();
|
||||||
|
EidUtility::initTCA();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* process incoming requst
|
||||||
|
*
|
||||||
|
* checks if there is a method avaiable for the request and executes it, if
|
||||||
|
* found
|
||||||
|
*
|
||||||
|
* @param ServerRequestInterface $request
|
||||||
|
* @param ResponseInterface $response
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function processRequest(ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response = null)
|
||||||
|
{
|
||||||
|
$apiObject = explode('/', $request->getUri()->getPath())[3];
|
||||||
|
$apiObjectId = explode('/', $request->getUri()->getPath())[4];
|
||||||
|
if (!$apiObject) {
|
||||||
|
return $response->withStatus(404);
|
||||||
|
}
|
||||||
|
$httpMethod = strtolower($request->getMethod());
|
||||||
|
if ($apiObjectId) {
|
||||||
|
$requestMethod = $httpMethod
|
||||||
|
. ucfirst($apiObject)
|
||||||
|
. 'SingleRequest';
|
||||||
|
$request->apiObjectId = $apiObjectId;
|
||||||
|
} else {
|
||||||
|
$requestMethod = $httpMethod
|
||||||
|
. ucfirst($apiObject)
|
||||||
|
. 'Request';
|
||||||
|
}
|
||||||
|
if (method_exists($this, $requestMethod)) {
|
||||||
|
$responseData = $this->$requestMethod($request, $response);
|
||||||
|
$response = $response->withHeader(
|
||||||
|
'Content-Type',
|
||||||
|
'application/json; charset=utf-8'
|
||||||
|
);
|
||||||
|
if (is_array($responseData)
|
||||||
|
&& array_key_exists('errors', $responseData)
|
||||||
|
) {
|
||||||
|
$response = $response->withStatus(400);
|
||||||
|
}
|
||||||
|
$response->getBody()->write(\json_encode($responseData));
|
||||||
|
return $response;
|
||||||
|
} else {
|
||||||
|
return $response->withStatus(404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -123,6 +123,11 @@ class ActionController extends BaseController
|
|||||||
*/
|
*/
|
||||||
protected $uriBuilder = null;
|
protected $uriBuilder = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* general config
|
||||||
|
*/
|
||||||
|
protected $config = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* propertyMappginConfigrtationBuolder
|
* propertyMappginConfigrtationBuolder
|
||||||
*/
|
*/
|
||||||
@ -176,6 +181,9 @@ class ActionController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function initializeAction()
|
public function initializeAction()
|
||||||
{
|
{
|
||||||
|
$this->config = GeneralUtility::removeDotsFromTS(
|
||||||
|
$GLOBALS['TSFE']->config['config']
|
||||||
|
);
|
||||||
$this->pageType = GeneralUtility::_GP('type');
|
$this->pageType = GeneralUtility::_GP('type');
|
||||||
if (!is_numeric($this->pageType)) {
|
if (!is_numeric($this->pageType)) {
|
||||||
$this->pageType = 0;
|
$this->pageType = 0;
|
||||||
@ -209,6 +217,16 @@ class ActionController extends BaseController
|
|||||||
$this->arguments->addNewArgument('submit', 'string', false, false);
|
$this->arguments->addNewArgument('submit', 'string', false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns an instance of uribuilder
|
||||||
|
*/
|
||||||
|
public function getUriBuilder()
|
||||||
|
{
|
||||||
|
return $this->objectManager->get(
|
||||||
|
UriBuilder::class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shortcut
|
* shortcut
|
||||||
*
|
*
|
||||||
@ -376,15 +394,21 @@ class ActionController extends BaseController
|
|||||||
/**
|
/**
|
||||||
* function to add validation error manually in the controller
|
* function to add validation error manually in the controller
|
||||||
*/
|
*/
|
||||||
protected function addValidationError($field, $keyword) {
|
protected function addValidationError(
|
||||||
|
$field, $keyword, $overwrite = false
|
||||||
|
) {
|
||||||
$this->responseStatus = [400 => 'validationError'];
|
$this->responseStatus = [400 => 'validationError'];
|
||||||
$this->errors[$field] = [
|
if (!array_key_exists($field, $this->errors)
|
||||||
'keyword' => $keyword,
|
|| $overwrite == true
|
||||||
];
|
) {
|
||||||
$this->errorLabels[$field] = $this->getErrorLabel(
|
$this->errors[$field] = [
|
||||||
$field,
|
'keyword' => $keyword,
|
||||||
$keyword
|
];
|
||||||
);
|
$this->errorLabels[$field] = $this->getErrorLabel(
|
||||||
|
$field,
|
||||||
|
$keyword
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
56
Classes/Controller/EIDController.php
Normal file
56
Classes/Controller/EIDController.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
namespace Cjel\TemplatesAide\Controller;
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* This file is part of the "Templates Aide" Extension for TYPO3 CMS.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the
|
||||||
|
* LICENSE.txt file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* (c) 2021 Philipp Dieter <philippdieter@attic-media.net>
|
||||||
|
*
|
||||||
|
***/
|
||||||
|
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use TYPO3\CMS\Core\Cache\CacheManager;
|
||||||
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||||
|
use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
|
||||||
|
use TYPO3\CMS\Core\Log\LogManager;
|
||||||
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||||
|
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||||
|
use TYPO3\CMS\Frontend\Plugin\AbstractPlugin;
|
||||||
|
use TYPO3\CMS\Frontend\Utility\EidUtility;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EIDController
|
||||||
|
*/
|
||||||
|
class EIDController extends AbstractEIDController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function scriptEnabled(
|
||||||
|
ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response = null
|
||||||
|
) {
|
||||||
|
$GLOBALS['TSFE']->fe_user->setKey('ses', 'scriptstate', 1);
|
||||||
|
$GLOBALS["TSFE"]->storeSessionData();
|
||||||
|
$response->getBody()->write(\json_encode([]));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scriptDisabled(
|
||||||
|
ServerRequestInterface $request,
|
||||||
|
ResponseInterface $response = null
|
||||||
|
) {
|
||||||
|
$GLOBALS['TSFE']->fe_user->setKey('ses', 'scriptstate', 0);
|
||||||
|
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(
|
||||||
|
// $GLOBALS['TSFE']->fe_user->getKey('ses', 'scriptstate')
|
||||||
|
//);
|
||||||
|
$GLOBALS["TSFE"]->storeSessionData();
|
||||||
|
$response->getBody()->write(\json_encode([]));
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
Classes/ViewHelpers/ScriptswitchNoscriptViewHelper.php
Normal file
53
Classes/ViewHelpers/ScriptswitchNoscriptViewHelper.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
namespace Cjel\TemplatesAide\ViewHelpers;
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Database\Connection;
|
||||||
|
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||||
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||||
|
|
||||||
|
class ScriptswitchNoscriptViewHelper extends AbstractViewHelper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* As this ViewHelper renders HTML, the output must not be escaped.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $escapeOutput = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string HTML Content
|
||||||
|
*/
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
|
||||||
|
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(
|
||||||
|
// $GLOBALS['TSFE']->fe_user->getKey('ses', 'scriptstate')
|
||||||
|
//);
|
||||||
|
|
||||||
|
$scriptstate = $GLOBALS['TSFE']->fe_user->getKey('ses', 'scriptstate');
|
||||||
|
|
||||||
|
if ($scriptstate) {
|
||||||
|
$_ = '<noscript inline-template>';
|
||||||
|
$_ .= '<div class="here">';
|
||||||
|
$_ .= '<iframe src="/script/disabled">';
|
||||||
|
$_ .= '</iframe>';
|
||||||
|
$_ .= '<meta http-equiv="refresh" content="1" />';
|
||||||
|
$_ .= '</div>';
|
||||||
|
$_ .= '</noscript>';
|
||||||
|
} else {
|
||||||
|
$_ = '
|
||||||
|
<script type="application/javascript">
|
||||||
|
var url = "/script/enabled"
|
||||||
|
var xmlhttp;
|
||||||
|
xmlhttp = new XMLHttpRequest();
|
||||||
|
xmlhttp.onreadystatechange = function(){}
|
||||||
|
xmlhttp.open("GET", url, true);
|
||||||
|
xmlhttp.send();
|
||||||
|
</script>
|
||||||
|
';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $_;
|
||||||
|
}
|
||||||
|
}
|
4
Resources/Public/Css/backend/default/visual.css
Normal file
4
Resources/Public/Css/backend/default/visual.css
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.CodeMirror {
|
||||||
|
border: 1px solid #eee;
|
||||||
|
height: auto !important;
|
||||||
|
}
|
26
build/patches/extension_builder-make-git-dir-configurable.diff
Executable file
26
build/patches/extension_builder-make-git-dir-configurable.diff
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
--- webroot/typo3conf/ext/extension_builder/Classes/Service/FileGenerator.php 2020-06-08 22:07:03.000000000 +0200
|
||||||
|
+++ webroot/typo3conf/ext/extension_builder/Classes/Service/FileGenerator.php 2020-08-12 01:39:57.931302902 +0200
|
||||||
|
@@ -202,10 +202,6 @@
|
||||||
|
GeneralUtility::mkdir($this->extensionDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
- $this->generateGitIgnore();
|
||||||
|
-
|
||||||
|
- $this->generateGitAttributes();
|
||||||
|
-
|
||||||
|
$this->generateEditorConfig();
|
||||||
|
|
||||||
|
$this->generateComposerJson();
|
||||||
|
@@ -240,7 +236,11 @@
|
||||||
|
$this->generateDocumentationFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
- $this->generateEmptyGitRepository();
|
||||||
|
+ $extensionSettings = $extension->getSettings();
|
||||||
|
+ if ($extensionSettings['overwriteSettings']['.git'] ?? false) {
|
||||||
|
+ $this->generateEmptyGitRepository();
|
||||||
|
+ $this->generateGitIgnore();
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function generateYamlSettingsFile()
|
@ -57,3 +57,36 @@ $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['nodeRegistry'][1549297828] = [
|
|||||||
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['c'] = [];
|
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['c'] = [];
|
||||||
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['c'][]
|
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['c'][]
|
||||||
= 'Cjel\TemplatesAide\ViewHelpers';
|
= 'Cjel\TemplatesAide\ViewHelpers';
|
||||||
|
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['n'] = [];
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['n'][]
|
||||||
|
= 'GeorgRinger\News\ViewHelpers';
|
||||||
|
|
||||||
|
call_user_func(
|
||||||
|
function()
|
||||||
|
{
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['script_enabled'] =
|
||||||
|
\Cjel\TemplatesAide\Controller\EIDController::class
|
||||||
|
. '::scriptEnabled';
|
||||||
|
if (isset($_SERVER['REQUEST_URI'])) {
|
||||||
|
$uriParts = explode('/', $_SERVER['REQUEST_URI']);
|
||||||
|
if ($uriParts[1] === 'script' && $uriParts[2] === 'enabled') {
|
||||||
|
$_GET['eID'] = 'script_enabled';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['script_disabled'] =
|
||||||
|
\Cjel\TemplatesAide\Controller\EIDController::class
|
||||||
|
. '::scriptDisabled';
|
||||||
|
if (isset($_SERVER['REQUEST_URI'])) {
|
||||||
|
$uriParts = explode('/', $_SERVER['REQUEST_URI']);
|
||||||
|
if ($uriParts[1] === 'script' && $uriParts[2] === 'disabled') {
|
||||||
|
$_GET['eID'] = 'script_disabled';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['script_enable'] =
|
||||||
|
// \Cjel\TemplatesAide\Controller\EIDController::class
|
||||||
|
// . '::scriptEnable';
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
@ -40,6 +40,9 @@ call_user_func(
|
|||||||
'EXT:templates_aide/Resources/Public/Css/backend/production-stage';
|
'EXT:templates_aide/Resources/Public/Css/backend/production-stage';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$GLOBALS['TBE_STYLES']['skins']['backend']['stylesheetDirectories']['default'] =
|
||||||
|
'EXT:templates_aide/Resources/Public/Css/backend/default';
|
||||||
|
|
||||||
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile(
|
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerPageTSConfigFile(
|
||||||
'templates_aide',
|
'templates_aide',
|
||||||
'Resources/Private/PageTSConfig/default.tsconfig',
|
'Resources/Private/PageTSConfig/default.tsconfig',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user