-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Adds Support for MM-Records to excluded Tables
Resolves: https://projekte.in2code.de/issues/65827
- Loading branch information
1 parent
feaff09
commit 8486183
Showing
8 changed files
with
231 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace In2code\In2publishCore\Component\Core\Demand\Type; | ||
|
||
use In2code\In2publishCore\Component\Core\Record\Model\Node; | ||
|
||
class MmDemand implements Demand | ||
{ | ||
use UniqueRecordKeyGenerator; | ||
|
||
protected string $from; | ||
protected string $property; | ||
/** @var mixed */ | ||
protected $value; | ||
protected Node $record; | ||
|
||
/** | ||
* @param mixed $value | ||
*/ | ||
public function __construct(string $from, string $property, $value, Node $record) | ||
{ | ||
$this->from = $from; | ||
$this->property = $property; | ||
$this->value = $value; | ||
$this->record = $record; | ||
} | ||
|
||
public function addToDemandsArray(array &$demands): void | ||
{ | ||
$uniqueRecordKey = $this->createUniqueRecordKey($this->record); | ||
$demands[$this->from][$this->property][$this->value][$uniqueRecordKey] = $this->record; | ||
} | ||
|
||
public function addToMetaArray(array &$meta, array $frame): void | ||
{ | ||
$meta[$this->from][$this->property][] = $frame; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
Classes/Component/Core/DemandResolver/Mm/MmDemandResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace In2code\In2publishCore\Component\Core\DemandResolver\Mm; | ||
|
||
use Doctrine\DBAL\Exception; | ||
use In2code\In2publishCore\Component\Core\Demand\CallerAwareDemandsCollection; | ||
use In2code\In2publishCore\Component\Core\Demand\Demands; | ||
use In2code\In2publishCore\Component\Core\Demand\Type\MmDemand; | ||
use In2code\In2publishCore\Component\Core\Demand\Type\SelectDemand; | ||
use In2code\In2publishCore\Component\Core\DemandResolver\DemandResolver; | ||
use In2code\In2publishCore\Component\Core\DemandResolver\Exception\InvalidDemandException; | ||
use In2code\In2publishCore\Component\Core\Record\Factory\RecordFactoryInjection; | ||
use In2code\In2publishCore\Component\Core\RecordCollection; | ||
use In2code\In2publishCore\Component\Core\RecordIndexInjection; | ||
use In2code\In2publishCore\Component\Core\Repository\DualDatabaseRepositoryInjection; | ||
use In2code\In2publishCore\Component\Core\Repository\ForeignSingleDatabaseRepositoryInjection; | ||
use In2code\In2publishCore\Component\Core\Repository\LocalSingleDatabaseRepositoryInjection; | ||
|
||
class MmDemandResolver implements DemandResolver | ||
{ | ||
use RecordFactoryInjection; | ||
use RecordIndexInjection; | ||
use DualDatabaseRepositoryInjection; | ||
use LocalSingleDatabaseRepositoryInjection; | ||
use ForeignSingleDatabaseRepositoryInjection; | ||
|
||
public function resolveDemand(Demands $demands, RecordCollection $recordCollection): void | ||
{ | ||
foreach ($demands->getDemandsByType(MmDemand::class) as $mmTable => $fields) { | ||
foreach ($fields as $field => $valueMaps) { | ||
try { | ||
$rows = $this->dualDatabaseRepository->findMmByProperty( | ||
$mmTable, | ||
$field, | ||
array_keys($valueMaps) | ||
); | ||
} catch (Exception $exception) { | ||
if ($demands instanceof CallerAwareDemandsCollection) { | ||
$callers = $demands->getMeta(MmDemand::class, $mmTable, $field); | ||
$exception = new InvalidDemandException($callers, $exception); | ||
} | ||
throw $exception; | ||
} | ||
foreach ($rows as $mmId => $recordInfo) { | ||
$mmRecord = $this->recordIndex->getRecord($mmTable, $mmId); | ||
if (null === $mmRecord) { | ||
$mmRecord = $this->recordFactory->createMmRecord( | ||
$mmTable, | ||
$mmId, | ||
$recordInfo['local'] ?? [], | ||
$recordInfo['foreign'] ?? [], | ||
); | ||
if (null === $mmRecord) { | ||
continue; | ||
} | ||
} | ||
$mapValue = $mmRecord->getProp($field); | ||
foreach ($valueMaps[$mapValue] as $parent) { | ||
$parent->addChild($mmRecord); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
Classes/Component/Core/Resolver/SelectStandaloneMmResolver.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace In2code\In2publishCore\Component\Core\Resolver; | ||
|
||
use In2code\In2publishCore\Component\Core\Demand\Demands; | ||
use In2code\In2publishCore\Component\Core\Demand\Type\JoinDemand; | ||
use In2code\In2publishCore\Component\Core\Demand\Type\MmDemand; | ||
use In2code\In2publishCore\Component\Core\Demand\Type\StandaloneMmDemand; | ||
use In2code\In2publishCore\Component\Core\PreProcessing\PreProcessor\AbstractProcessor; | ||
use In2code\In2publishCore\Component\Core\Record\Model\Record; | ||
use In2code\In2publishCore\Service\ReplaceMarkersService; | ||
use In2code\In2publishCore\Service\ReplaceMarkersServiceInject; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
use function preg_match; | ||
|
||
class SelectStandaloneMmResolver extends AbstractResolver | ||
{ | ||
use ReplaceMarkersServiceInject; | ||
|
||
protected string $mmTable; | ||
protected string $selectField; | ||
|
||
public function configure( | ||
string $mmTable, | ||
string $selectField | ||
): void { | ||
$this->mmTable = $mmTable; | ||
$this->selectField = $selectField; | ||
} | ||
|
||
public function getTargetTables(): array | ||
{ | ||
return [$this->mmTable]; | ||
} | ||
|
||
public function resolve(Demands $demands, Record $record): void | ||
{ | ||
$value = $record->getId(); | ||
|
||
$demand = new MmDemand($this->mmTable, $this->selectField, $value, $record); | ||
|
||
$demands->addDemand($demand); | ||
} | ||
|
||
public function __serialize(): array | ||
{ | ||
return [ | ||
'metaInfo' => $this->metaInfo, | ||
'mmTable' => $this->mmTable, | ||
'selectField' => $this->selectField, | ||
]; | ||
} | ||
|
||
public function __unserialize(array $data): void | ||
{ | ||
$this->metaInfo = $data['metaInfo']; | ||
$this->configure( | ||
$data['mmTable'], | ||
$data['selectField'], | ||
); | ||
$this->injectReplaceMarkersService(GeneralUtility::makeInstance(ReplaceMarkersService::class)); | ||
} | ||
} |