Skip to content

Commit

Permalink
[BUGFIX] Use object manager in TYPO3 v10 to instantiate dataMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
featdd committed Jan 5, 2022
1 parent 97e1d36 commit 8c93afd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Classes/Domain/Repository/AbstractStatisticRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Exception;
use Mindshape\MindshapeCookieConsent\Domain\Model\Configuration;
use Mindshape\MindshapeCookieConsent\Utility\DatabaseUtility;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
Expand All @@ -32,6 +33,11 @@
*/
abstract class AbstractStatisticRepository extends Repository
{
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
*/
protected $dataMapper;

/**
* @var array
*/
Expand All @@ -46,6 +52,12 @@ public function initializeObject(): void
$querySettings->setRespectStoragePage(false);

$this->setDefaultQuerySettings($querySettings);

$typo3Version = GeneralUtility::makeInstance(Typo3Version::class);

$this->dataMapper = version_compare('10.4', $typo3Version->getBranch(), '==')
? $this->objectManager->get(DataMapper::class)
: GeneralUtility::makeInstance(DataMapper::class);
}

/**
Expand Down Expand Up @@ -79,7 +91,7 @@ public function findByMonth(Configuration $configuration, DateTime $date): Query
*/
public function findAvailableMonths(int $languageUid = 0): array
{
$tableName = GeneralUtility::makeInstance(DataMapper::class)->convertClassNameToTableName($this->objectType);
$tableName = $this->dataMapper->convertClassNameToTableName($this->objectType);
$languageField = $GLOBALS['TCA'][$tableName]['ctrl']['languageField'];

$queryBuilder = DatabaseUtility::queryBuilder();
Expand Down

0 comments on commit 8c93afd

Please sign in to comment.