[TASK] Add objectmanager via constructor DI injection

This commit is contained in:
Benjamin Serfhos 2018-10-29 14:29:31 +01:00
parent 2c5ab1b57a
commit 2ee4a88a67

View file

@ -27,12 +27,18 @@ use Codappix\SearchCore\Domain\Index\TcaIndexer;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility; use TYPO3\CMS\Core\Utility\RootlineUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
/** /**
* Specific indexer for Pages, will basically add content of page. * Specific indexer for Pages, will basically add content of page.
*/ */
class PagesIndexer extends TcaIndexer class PagesIndexer extends TcaIndexer
{ {
/**
* @var ObjectManagerInterface
*/
protected $objectManager;
/** /**
* @var TcaTableServiceInterface * @var TcaTableServiceInterface
*/ */
@ -44,20 +50,16 @@ class PagesIndexer extends TcaIndexer
*/ */
protected $fileRepository; protected $fileRepository;
/**
* @param TcaTableServiceInterface $tcaTableService
* @param TcaTableServiceInterface $contentTableService
* @param ConnectionInterface $connection
* @param ConfigurationContainerInterface $configuration
*/
public function __construct( public function __construct(
TcaTableServiceInterface $tcaTableService, TcaTableServiceInterface $tcaTableService,
TcaTableServiceInterface $contentTableService, TcaTableServiceInterface $contentTableService,
ConnectionInterface $connection, ConnectionInterface $connection,
ConfigurationContainerInterface $configuration ConfigurationContainerInterface $configuration,
ObjectManagerInterface $objectManager
) { ) {
parent::__construct($tcaTableService, $connection, $configuration); parent::__construct($tcaTableService, $connection, $configuration);
$this->contentTableService = $contentTableService; $this->contentTableService = $contentTableService;
$this->objectManager = $objectManager;
} }
protected function prepareRecord(array &$record) protected function prepareRecord(array &$record)
@ -141,8 +143,7 @@ class PagesIndexer extends TcaIndexer
protected function fetchAccess(int $uid, array $pageAccess): array protected function fetchAccess(int $uid, array $pageAccess): array
{ {
try { try {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class); $rootline = $this->objectManager->get(RootlineUtility::class, $uid)->get();
$rootline = $objectManager->get(RootlineUtility::class, $uid)->get();
} catch (\RuntimeException $e) { } catch (\RuntimeException $e) {
$this->logger->notice( $this->logger->notice(
sprintf('Could not fetch rootline for page %u, because: %s', $uid, $e->getMessage()), sprintf('Could not fetch rootline for page %u, because: %s', $uid, $e->getMessage()),