Commit 85558739 authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[TASK] Cleanup repository classes to not rely on extbase initialisation

parent 251d7f63
......@@ -26,24 +26,23 @@ namespace SGalinski\SgMail\Domain\Repository;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\Repository;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Page\PageRepository;
/**
* Abstract Repository
*/
abstract class AbstractRepository extends Repository {
/**
* Initializes the repository default settings
* AbstractRepository constructor.
*
* @return void
* @param ObjectManagerInterface $objectManager
*/
public function initializeObject() {
public function __construct(ObjectManagerInterface $objectManager) {
parent::__construct($objectManager);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var Typo3QuerySettings $querySettings */
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
......@@ -55,34 +54,14 @@ abstract class AbstractRepository extends Repository {
if (TYPO3_MODE === 'BE') {
$querySettings->setIgnoreEnableFields(TRUE);
}
$this->setDefaultQuerySettings($querySettings);
}
/**
* Method creates a statement string of the enableFields for the given database table.
*
* @param string $table
* @param string $alias
* @param bool $ignoreEnableFields
* @return string
* Persist changes to database
*/
protected function getEnableFieldsStatement($table, $alias = '', $ignoreEnableFields = FALSE): string {
if (TYPO3_MODE === 'FE' && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController) {
/** @var PageRepository $pageRepository */
$pageRepository = $GLOBALS['TSFE']->sys_page;
$statement = $pageRepository->enableFields($table);
} else {
$statement = BackendUtility::deleteClause($table);
if (!$ignoreEnableFields) {
$statement .= BackendUtility::BEenableFields($table);
}
}
if ($alias !== '') {
$statement = str_replace($table, $alias, $statement);
}
return $statement;
public function persist() {
$this->persistenceManager->persistAll();
}
}
......@@ -28,6 +28,7 @@ namespace SGalinski\SgMail\Domain\Repository;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
/**
* Frontend User Group Repository
......@@ -35,9 +36,12 @@ use TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup;
class FrontendUserGroupRepository extends \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository {
/**
* initializes the object
* FrontendUserGroupRepository constructor.
*
* @param ObjectManagerInterface $objectManager
*/
public function initializeObject() {
public function __construct(ObjectManagerInterface $objectManager) {
parent::__construct($objectManager);
$this->objectType = FrontendUserGroup::class;
$querySettings = $this->createQuery()->getQuerySettings();
$querySettings->setRespectStoragePage(FALSE);
......
......@@ -32,6 +32,7 @@ use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\Repository;
......@@ -42,11 +43,12 @@ class LayoutRepository extends Repository {
const LAYOUT_TABLE_NAME = 'tx_sgmail_domain_model_layout';
/**
* Initializes the repository default settings
* LayoutRepository constructor.
*
* @return void
* @param ObjectManagerInterface $objectManager
*/
public function initializeObject() {
public function __construct(ObjectManagerInterface $objectManager) {
parent::__construct($objectManager);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '10.4.0', '<')) {
/** @var $querySettings Typo3QuerySettings */
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
......
......@@ -304,11 +304,4 @@ class MailRepository extends AbstractRepository {
return $queryBuilder->orderBy('tstamp', 'desc');
}
/**
* Persist the changes to database
*/
public function persist() {
$this->persistenceManager->persistAll();
}
}
......@@ -82,11 +82,4 @@ class TemplateRepository extends AbstractRepository {
)
)->execute();
}
/**
* Persist changes to database
*/
public function persist() {
$this->persistenceManager->persistAll();
}
}
services:
_defaults:
autowire: true
autoconfigure: true
public: false
SGalinski\SgMail\:
resource: '../Classes/*'
SGalinski\SgMail\Domain\Repository\FrontendUserGroupRepository:
public: true
SGalinski\SgMail\Domain\Repository\LayoutRepository:
public: true
SGalinski\SgMail\Domain\Repository\MailRepository:
public: true
SGalinski\SgMail\Domain\Repository\TemplateRepository:
public: true
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment