From 7d89596ba33a9f4e4e8bdaf8f6ab9a0c84bf3610 Mon Sep 17 00:00:00 2001
From: Matthias Adrowski <matthias.adrowski@sgalinski.de>
Date: Tue, 15 Mar 2022 11:53:09 +0100
Subject: [PATCH] [TASK] TYPO3 Constant migration + guards

---
 .../Domain/Repository/AbstractRepository.php  | 34 ++----------------
 Configuration/TCA/Overrides/pages.php         |  2 +-
 Configuration/TCA/Overrides/sys_template.php  |  1 +
 Configuration/TCA/Overrides/tt_content.php    |  1 +
 ext_localconf.php                             |  1 +
 ext_tables.php                                | 35 +++++++++----------
 6 files changed, 24 insertions(+), 50 deletions(-)

diff --git a/Classes/Domain/Repository/AbstractRepository.php b/Classes/Domain/Repository/AbstractRepository.php
index 10fc116..26a1770 100644
--- a/Classes/Domain/Repository/AbstractRepository.php
+++ b/Classes/Domain/Repository/AbstractRepository.php
@@ -27,6 +27,7 @@ namespace SGalinski\SgNews\Domain\Repository;
  ***************************************************************/
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Http\ApplicationType;
 use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
 use TYPO3\CMS\Extbase\Persistence\QueryInterface;
 use TYPO3\CMS\Extbase\Persistence\Repository;
@@ -43,44 +44,15 @@ abstract class AbstractRepository extends Repository {
 	 * @return void
 	 */
 	public function initializeObject() {
-		/** @var $querySettings Typo3QuerySettings */
+		/** @var Typo3QuerySettings $querySettings  */
 		$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
 		$querySettings->setRespectStoragePage(FALSE);
-		if (TYPO3_MODE === 'BE') {
+		if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
 			$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
-	 * @throws \InvalidArgumentException
-	 */
-	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;
-	}
-
 	/**
 	 * This count returns the right amount of results, in contrast to $query->execute()->count(), which does not respect
 	 * the language- nor the workspace overlay.
diff --git a/Configuration/TCA/Overrides/pages.php b/Configuration/TCA/Overrides/pages.php
index 020528d..2febe1b 100644
--- a/Configuration/TCA/Overrides/pages.php
+++ b/Configuration/TCA/Overrides/pages.php
@@ -1,5 +1,5 @@
 <?php
-
+defined('TYPO3') or die();
 /**
  *
  * Copyright notice
diff --git a/Configuration/TCA/Overrides/sys_template.php b/Configuration/TCA/Overrides/sys_template.php
index dd729bc..6c3b279 100644
--- a/Configuration/TCA/Overrides/sys_template.php
+++ b/Configuration/TCA/Overrides/sys_template.php
@@ -1,4 +1,5 @@
 <?php
+defined('TYPO3') or die();
 /**
  *
  * Copyright notice
diff --git a/Configuration/TCA/Overrides/tt_content.php b/Configuration/TCA/Overrides/tt_content.php
index 7494177..697f27a 100644
--- a/Configuration/TCA/Overrides/tt_content.php
+++ b/Configuration/TCA/Overrides/tt_content.php
@@ -1,4 +1,5 @@
 <?php
+defined('TYPO3') or die();
 /**
  *
  * Copyright notice
diff --git a/ext_localconf.php b/ext_localconf.php
index 3444aeb..5998629 100644
--- a/ext_localconf.php
+++ b/ext_localconf.php
@@ -1,4 +1,5 @@
 <?php
+defined('TYPO3') or die();
 /**
  *
  * Copyright notice
diff --git a/ext_tables.php b/ext_tables.php
index 9068794..eaa6714 100644
--- a/ext_tables.php
+++ b/ext_tables.php
@@ -1,4 +1,5 @@
 <?php
+defined('TYPO3') or die();
 /**
  *
  * Copyright notice
@@ -30,23 +31,21 @@ call_user_func(
 			'tx_sgnews_domain_model_author'
 		);
 
-		if (TYPO3_MODE === 'BE') {
-			$navigationComponentId = 'TYPO3/CMS/Backend/PageTree/PageTreeElement';
-			\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
-				'SgNews',
-				'web',
-				'News',
-				'',
-				[
-					\SGalinski\SgNews\Controller\BackendController::class => 'index',
-				],
-				[
-					'access' => 'user,group',
-					'icon' => 'EXT:sg_news/Resources/Public/Icons/module-sgnews.svg',
-					'labels' => 'LLL:EXT:sg_news/Resources/Private/Language/locallang.xlf',
-					'navigationComponentId' => $navigationComponentId
-				]
-			);
-		}
+		$navigationComponentId = 'TYPO3/CMS/Backend/PageTree/PageTreeElement';
+		\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
+			'SgNews',
+			'web',
+			'News',
+			'',
+			[
+				\SGalinski\SgNews\Controller\BackendController::class => 'index',
+			],
+			[
+				'access' => 'user,group',
+				'icon' => 'EXT:sg_news/Resources/Public/Icons/module-sgnews.svg',
+				'labels' => 'LLL:EXT:sg_news/Resources/Private/Language/locallang.xlf',
+				'navigationComponentId' => $navigationComponentId
+			]
+		);
 	}
 );
-- 
GitLab