Commit f31b8d81 authored by Wolf-Peter Utz's avatar Wolf-Peter Utz
Browse files

Add DI and remove @inject usages

* Add Constants.php to store extension constants
* Add Services.yaml
* Update backend module mainModule from `voting` to `web`
* Update deprecated usage of `GeneralUtility::verifyFilenameAgainstDenyPattern` to `GeneralUtility::makeInstance(FileNameValidator::class)->isValid`
parent ab5ed30d
<?php
namespace T3o\Election;
class Constants
{
public const EXTENSION_KEY = 'election';
public const EXTENSION_NAME = 'Election';
}
...@@ -20,43 +20,43 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; ...@@ -20,43 +20,43 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter; use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
use T3o\Election\Domain\Model\Configuration; use T3o\Election\Domain\Model\Configuration;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
/**
* Class AbstractBeController
*/
abstract class AbstractBeController extends ActionController abstract class AbstractBeController extends ActionController
{ {
/** /**
* @var BackendUserAuthentication * @var BackendUserAuthentication
*/ */
protected $backendUser = null; protected $backendUser;
/** /**
* @var Configuration * @var Configuration
*/ */
protected $configuration = null; protected $configuration;
/** /**
* @var \T3o\Election\Domain\Repository\ConfigurationRepository * @var ConfigurationRepository
* @inject
*/ */
protected $configurationRepository = null; protected $configurationRepository;
/** /**
* Sets the current configuration * AbstractBeController constructor.
*
* @param ConfigurationRepository $configurationRepository
*/ */
public function initializeObject() public function __construct(ConfigurationRepository $configurationRepository)
{ {
$this->configuration = $this->configurationRepository->findCurrent(); $this->configurationRepository = $configurationRepository;
$this->backendUser = self::getBackendUserAuthentication();
} }
/** /**
* ModuleController constructor. * Sets the current configuration
*/ */
public function __construct() public function initializeObject()
{ {
parent::__construct(); $this->configuration = $this->configurationRepository->findCurrent();
$this->backendUser = self::getBackendUserAuthentication();
} }
/** /**
......
<?php <?php
namespace T3o\Election\Controller; namespace T3o\Election\Controller;
/* /*
...@@ -14,18 +15,11 @@ namespace T3o\Election\Controller; ...@@ -14,18 +15,11 @@ namespace T3o\Election\Controller;
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
use Doctrine\Common\Util\Debug;
use TYPO3\CMS\Core\Messaging\AbstractMessage; use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* Class AbstractProtectedBeController
*/
abstract class AbstractProtectedBeController extends AbstractBeController abstract class AbstractProtectedBeController extends AbstractBeController
{ {
/**
*
*/
protected function initializeAction() protected function initializeAction()
{ {
if (!$this->backendUserHasUserGroup($this->getRequiredUserGroup())) { if (!$this->backendUserHasUserGroup($this->getRequiredUserGroup())) {
...@@ -46,33 +40,32 @@ abstract class AbstractProtectedBeController extends AbstractBeController ...@@ -46,33 +40,32 @@ abstract class AbstractProtectedBeController extends AbstractBeController
protected function errorAction() protected function errorAction()
{ {
$this->clearCacheOnError(); $this->clearCacheOnError();
$message = "";
$message="";
foreach ($this->arguments->getValidationResults()->getFlattenedErrors() as $propertyPath => $errors) { foreach ($this->arguments->getValidationResults()->getFlattenedErrors() as $propertyPath => $errors) {
foreach ($errors as $error) { foreach ($errors as $error) {
$message .= PHP_EOL. 'Error for ' . $propertyPath . ': ' . $error->render(); $message .= PHP_EOL . 'Error for ' . $propertyPath . ': ' . $error->render();
} }
} }
$errorFlashMessage = $this->getErrorFlashMessage(); $errorFlashMessage = $this->getErrorFlashMessage();
if ($errorFlashMessage !== FALSE) { if ($errorFlashMessage !== false) {
$errorFlashMessageObject = new \TYPO3\CMS\Core\Messaging\FlashMessage( $errorFlashMessageObject = new \TYPO3\CMS\Core\Messaging\FlashMessage(
$errorFlashMessage." ".$message, $errorFlashMessage . " " . $message,
'', '',
\TYPO3\CMS\Core\Messaging\FlashMessage::ERROR \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
); );
$this->controllerContext->getFlashMessageQueue()->enqueue($errorFlashMessageObject); $this->controllerContext->getFlashMessageQueue()->enqueue($errorFlashMessageObject);
} }
$referringRequest = $this->request->getReferringRequest(); $referringRequest = $this->request->getReferringRequest();
if ($referringRequest !== NULL) { if ($referringRequest !== null) {
$originalRequest = clone $this->request; $originalRequest = clone $this->request;
$this->request->setOriginalRequest($originalRequest); $this->request->setOriginalRequest($originalRequest);
$this->request->setOriginalRequestMappingResults($this->arguments->getValidationResults()); $this->request->setOriginalRequestMappingResults($this->arguments->getValidationResults());
$this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(), $referringRequest->getControllerExtensionName(), $referringRequest->getArguments()); $this->forward($referringRequest->getControllerActionName(), $referringRequest->getControllerName(),
$referringRequest->getControllerExtensionName(), $referringRequest->getArguments());
} }
$message = 'An error occurred while trying to call ' . get_class($this) . '->' . $this->actionMethodName . '().' . PHP_EOL; $message = 'An error occurred while trying to call ' . get_class($this) . '->' . $this->actionMethodName . '().' . PHP_EOL;
return $message;
return $message;
} }
} }
<?php <?php
namespace T3o\Election\Controller; namespace T3o\Election\Controller;
/* /*
...@@ -15,6 +16,9 @@ namespace T3o\Election\Controller; ...@@ -15,6 +16,9 @@ namespace T3o\Election\Controller;
*/ */
use T3o\Election\Domain\Model\Configuration; use T3o\Election\Domain\Model\Configuration;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Extbase\Domain\Repository\BackendUserGroupRepository;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
/** /**
* Class BeConfigurationController * Class BeConfigurationController
...@@ -26,14 +30,18 @@ class BeConfigurationController extends AbstractProtectedBeController ...@@ -26,14 +30,18 @@ class BeConfigurationController extends AbstractProtectedBeController
const ACTION_UPDATE = 'update'; const ACTION_UPDATE = 'update';
/** /**
* @var \TYPO3\CMS\Extbase\Domain\Repository\BackendUserGroupRepository * @var BackendUserGroupRepository
* @inject
*/ */
protected $backendUserGroupRepository = null; protected $backendUserGroupRepository;
public function __construct(
BackendUserGroupRepository $backendUserGroupRepository,
ConfigurationRepository $configurationRepository
) {
parent::__construct($configurationRepository);
$this->backendUserGroupRepository = $backendUserGroupRepository;
}
/**
*
*/
public function editAction() public function editAction()
{ {
if (null === $this->configuration) { if (null === $this->configuration) {
...@@ -49,6 +57,7 @@ class BeConfigurationController extends AbstractProtectedBeController ...@@ -49,6 +57,7 @@ class BeConfigurationController extends AbstractProtectedBeController
public function updateAction(Configuration $configuration) public function updateAction(Configuration $configuration)
{ {
$this->configurationRepository->update($configuration); $this->configurationRepository->update($configuration);
$this->objectManager->get(PersistenceManager::class)->persistAll();
$this->redirect(BeDashboardController::ACTION_INDEX, BeDashboardController::CONTROLLER_NAME); $this->redirect(BeDashboardController::ACTION_INDEX, BeDashboardController::CONTROLLER_NAME);
} }
...@@ -68,6 +77,7 @@ class BeConfigurationController extends AbstractProtectedBeController ...@@ -68,6 +77,7 @@ class BeConfigurationController extends AbstractProtectedBeController
if (null === $this->configuration) { if (null === $this->configuration) {
return Configuration::AUTH_NONE; return Configuration::AUTH_NONE;
} }
return $this->configuration->getAdministrationGroup(); return $this->configuration->getAdministrationGroup();
} }
} }
<?php <?php
namespace T3o\Election\Controller; namespace T3o\Election\Controller;
/* /*
...@@ -13,10 +14,13 @@ namespace T3o\Election\Controller; ...@@ -13,10 +14,13 @@ namespace T3o\Election\Controller;
* *
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Core\Messaging\AbstractMessage; use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use T3o\Election\Domain\Repository\ElectionCircularRepository; use T3o\Election\Domain\Repository\ElectionCircularRepository;
use T3o\Election\Domain\Repository\ElectorImportRepository; use T3o\Election\Domain\Repository\ElectorImportRepository;
use T3o\Election\Domain\Repository\ElectionRepository;
/** /**
* Dashboard controller * Dashboard controller
...@@ -27,10 +31,17 @@ class BeDashboardController extends AbstractBeController ...@@ -27,10 +31,17 @@ class BeDashboardController extends AbstractBeController
const ACTION_INDEX = 'index'; const ACTION_INDEX = 'index';
/** /**
* @var \T3o\Election\Domain\Repository\ElectionRepository * @var ElectionRepository
* @inject
*/ */
protected $electionRepository = null; protected $electionRepository;
public function __construct(
ElectionRepository $electionRepository,
ConfigurationRepository $configurationRepository
) {
parent::__construct($configurationRepository);
$this->electionRepository = $electionRepository;
}
/** /**
* *
...@@ -46,28 +57,32 @@ class BeDashboardController extends AbstractBeController ...@@ -46,28 +57,32 @@ class BeDashboardController extends AbstractBeController
if ($this->configuration) { if ($this->configuration) {
if ($this->configuration->isGroupConfigComplete()) { if ($this->configuration->isGroupConfigComplete()) {
$electionManagerGroup = $this->configuration->getElectionManagerGroup(); $electionManagerGroup = $this->configuration->getElectionManagerGroup();
} } else {
else {
$this->addFlashMessage( $this->addFlashMessage(
LocalizationUtility::translate('view.be.dashboard.index.no_proper_configuration_msg_body', $this->extensionName), LocalizationUtility::translate('view.be.dashboard.index.no_proper_configuration_msg_body',
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title', $this->extensionName), \T3o\Election\Constants::EXTENSION_NAME),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title',
\T3o\Election\Constants::EXTENSION_NAME),
AbstractMessage::ERROR AbstractMessage::ERROR
); );
if ($GLOBALS['BE_USER']->isAdmin()) { if ($GLOBALS['BE_USER']->isAdmin()) {
$this->redirect('edit','BeConfiguration'); $this->redirect('edit', 'BeConfiguration');
} else { } else {
$this->addFlashMessage( $this->addFlashMessage(
LocalizationUtility::translate('view.be.dashboard.index.no_proper_configuration_msg_body_admin', $this->extensionName), LocalizationUtility::translate('view.be.dashboard.index.no_proper_configuration_msg_body_admin',
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title', $this->extensionName), \T3o\Election\Constants::EXTENSION_NAME),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title',
\T3o\Election\Constants::EXTENSION_NAME),
AbstractMessage::ERROR AbstractMessage::ERROR
); );
} }
} }
} } else {
else {
$this->addFlashMessage( $this->addFlashMessage(
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_body', $this->extensionName), LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_body',
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title', $this->extensionName), \T3o\Election\Constants::EXTENSION_NAME),
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_title',
\T3o\Election\Constants::EXTENSION_NAME),
AbstractMessage::ERROR AbstractMessage::ERROR
); );
} }
...@@ -83,11 +98,12 @@ class BeDashboardController extends AbstractBeController ...@@ -83,11 +98,12 @@ class BeDashboardController extends AbstractBeController
$this->objectManager->get(ElectionCircularRepository::class)->findAll() $this->objectManager->get(ElectionCircularRepository::class)->findAll()
); );
} }
} } else {
else {
$this->addFlashMessage( $this->addFlashMessage(
LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_body', $this->extensionName), LocalizationUtility::translate('view.be.dashboard.index.no_configuration_msg_body',
LocalizationUtility::translate('view.be.dashboard.index.no_electionmanagergroup_msg_body', $this->extensionName), \T3o\Election\Constants::EXTENSION_NAME),
LocalizationUtility::translate('view.be.dashboard.index.no_electionmanagergroup_msg_body',
\T3o\Election\Constants::EXTENSION_NAME),
AbstractMessage::WARNING AbstractMessage::WARNING
); );
} }
......
...@@ -13,7 +13,8 @@ namespace T3o\Election\Controller; ...@@ -13,7 +13,8 @@ namespace T3o\Election\Controller;
* *
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
use TYPO3\CMS\Backend\Utility\BackendUtility;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\DatabaseConnection; use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
...@@ -22,6 +23,8 @@ use T3o\Election\Domain\Model\Elector; ...@@ -22,6 +23,8 @@ use T3o\Election\Domain\Model\Elector;
use T3o\Election\Service\CircularService; use T3o\Election\Service\CircularService;
use T3o\Election\Service\ElectionInvitationService; use T3o\Election\Service\ElectionInvitationService;
use T3o\Election\Utility\MailUtility; use T3o\Election\Utility\MailUtility;
use T3o\Election\Domain\Repository\ElectionCircularRepository;
use T3o\Election\Domain\Repository\ElectionRepository;
/** /**
* Class BeConfigurationController * Class BeConfigurationController
...@@ -41,16 +44,24 @@ class BeElectionCircularController extends AbstractProtectedBeController ...@@ -41,16 +44,24 @@ class BeElectionCircularController extends AbstractProtectedBeController
const ACTION_SEND_PREVIEW = 'sendPreview'; const ACTION_SEND_PREVIEW = 'sendPreview';
/** /**
* @var \T3o\Election\Domain\Repository\ElectionCircularRepository * @var ElectionCircularRepository
* @inject
*/ */
protected $electionCircularRepository = null; protected $electionCircularRepository;
/** /**
* @var \T3o\Election\Domain\Repository\ElectionRepository * @var ElectionRepository
* @inject
*/ */
protected $electionRepository = null; protected $electionRepository;
public function __construct(
ElectionCircularRepository $electionCircularRepository,
ElectionRepository $electionRepository,
ConfigurationRepository $configurationRepository
) {
parent::__construct($configurationRepository);
$this->electionCircularRepository = $electionCircularRepository;
$this->electionRepository = $electionRepository;
}
/** /**
* *
......
...@@ -15,6 +15,10 @@ namespace T3o\Election\Controller; ...@@ -15,6 +15,10 @@ namespace T3o\Election\Controller;
*/ */
use T3o\Election\Domain\Model\Election; use T3o\Election\Domain\Model\Election;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use T3o\Election\Domain\Repository\ElectionRepository;
use T3o\Election\Domain\Repository\ElectorateRepository;
use T3o\Election\Domain\Repository\NomineeRepository;
/** /**
* Class BeConfigurationController * Class BeConfigurationController
...@@ -31,22 +35,31 @@ class BeElectionController extends AbstractProtectedBeController ...@@ -31,22 +35,31 @@ class BeElectionController extends AbstractProtectedBeController
const ACTION_SUMMARY = 'summary'; const ACTION_SUMMARY = 'summary';
/** /**
* @var \T3o\Election\Domain\Repository\ElectionRepository * @var ElectionRepository
* @inject
*/ */
protected $electionRepository = null; protected $electionRepository;
/** /**
* @var \T3o\Election\Domain\Repository\ElectorateRepository * @var ElectorateRepository
* @inject
*/ */
protected $electorateRepository = null; protected $electorateRepository;
/** /**
* @var \T3o\Election\Domain\Repository\NomineeRepository * @var NomineeRepository
* @inject
*/ */
protected $nomineeRepository = null; protected $nomineeRepository ;
public function __construct(
ElectionRepository $electionRepository,
ElectorateRepository $electorateRepository,
NomineeRepository $nomineeRepository,
ConfigurationRepository $configurationRepository
) {
parent::__construct($configurationRepository);
$this->electionRepository = $electionRepository;
$this->electorateRepository = $electorateRepository;
$this->nomineeRepository = $nomineeRepository;
}
/** /**
* *
......
...@@ -13,13 +13,21 @@ namespace T3o\Election\Controller; ...@@ -13,13 +13,21 @@ namespace T3o\Election\Controller;
* *
* The TYPO3 project - inspiring people to share! * The TYPO3 project - inspiring people to share!
*/ */
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use T3o\Election\Domain\Model\ElectionInvitation;
use T3o\Election\Domain\Repository\ConfigurationRepository;
use T3o\Election\Service\ElectionInvitationService;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use T3o\Election\Domain\Model\Dto\ElectorImport as ElectorImportDto; use T3o\Election\Domain\Model\Dto\ElectorImport as ElectorImportDto;
use T3o\Election\Domain\Model\Election; use T3o\Election\Domain\Model\Election;
use T3o\Election\Domain\Model\Elector; use T3o\Election\Domain\Model\Elector;
use T3o\Election\Domain\Model\ElectorImport; use T3o\Election\Domain\Model\ElectorImport;
use T3o\Election\Utility\CsvUtility; use T3o\Election\Utility\CsvUtility;
use T3o\Election\Utility\FileUtility; use T3o\Election\Utility\FileUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use T3o\Election\Domain\Repository\ElectorateRepository;
use T3o\Election\Domain\Repository\ElectorRepository;
use T3o\Election\Domain\Repository\ElectorImportRepository;
/** /**
* Class BeConfigurationController * Class BeConfigurationController
...@@ -38,28 +46,35 @@ class BeElectorController extends AbstractProtectedBeController ...@@ -38,28 +46,35 @@ class BeElectorController extends AbstractProtectedBeController
const ACTION_UPLOAD = 'upload'; const ACTION_UPLOAD = 'upload';
const ACTION_PROCESS_IMPORT = 'processImport'; const ACTION_PROCESS_IMPORT = 'processImport';
const ACTION_OVERWRITE_ALL = 'overwriteAll'; const ACTION_OVERWRITE_ALL = 'overwriteAll';
const ACTION_RESEND_ELECTION_INVITATION = 'resendElectionInvitation';
/** /**
* @var \T3o\Election\Domain\Repository\ElectorateRepository * @var ElectorateRepository
* @inject
*/ */
protected $electorateRepository = null; protected $electorateRepository;
/** /**
* @var \T3o\Election\Domain\Repository\ElectorRepository * @var ElectorRepository
* @inject
*/ */
protected $electorRepository = null; protected $electorRepository;
/** /**
* @var \T3o\Election\Domain\Repository\ElectorImportRepository * @var ElectorImportRepository
* @inject
*/ */
protected $electorImportRepository = null; protected $electorImportRepository;
public function __construct(