diff --git a/Classes/Command/SortingCommand.php b/Classes/Command/SortingCommand.php index fc9b8f28..a9785b08 100644 --- a/Classes/Command/SortingCommand.php +++ b/Classes/Command/SortingCommand.php @@ -29,6 +29,7 @@ class SortingCommand extends Command protected function configure() { + $this->addArgument('pid', InputArgument::OPTIONAL, 'limit to this pid', 0); $this->addOption('apply', null, InputOption::VALUE_NONE, 'apply migration'); $this->addOption( 'enable-logging', @@ -47,10 +48,15 @@ public function __construct(Sorting $sorting, string $name = null) public function execute(InputInterface $input, OutputInterface $output): int { $dryrun = $input->getOption('apply') !== true; + $pid = (int)$input->getArgument('pid'); Bootstrap::initializeBackendAuthentication(); Bootstrap::initializeLanguageObject(); - $errors = $this->sorting->run($dryrun, $input->getOption('enable-logging')); + $errors = $this->sorting->run( + $dryrun, + $input->getOption('enable-logging'), + $pid + ); foreach ($errors as $error) { $output->writeln($error); } diff --git a/Classes/Integrity/Database.php b/Classes/Integrity/Database.php index cb9672ef..49b59e4f 100644 --- a/Classes/Integrity/Database.php +++ b/Classes/Integrity/Database.php @@ -129,7 +129,7 @@ public function getChildrenByContainerAndColPos(int $containerId, int $colPos, i return (array)$stm->fetchAllAssociative(); } - public function getContainerRecords(array $cTypes): array + public function getContainerRecords(array $cTypes, ?int $pid): array { $queryBuilder = $this->getQueryBuilder(); $stm = $queryBuilder @@ -145,6 +145,14 @@ public function getContainerRecords(array $cTypes): array $queryBuilder->createNamedParameter(0, Connection::PARAM_INT) ) ); + if (!empty($pid)) { + $stm->andWhere( + $queryBuilder->expr()->eq( + 'pid', + $queryBuilder->createNamedParameter($pid, Connection::PARAM_INT) + ) + ); + } if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() >= 12) { $stm = $stm->executeQuery(); } else { @@ -162,7 +170,7 @@ public function getContainerRecords(array $cTypes): array return $rows; } - public function getContainerRecordsFreeMode(array $cTypes): array + public function getContainerRecordsFreeMode(array $cTypes, ?int $pid): array { $queryBuilder = $this->getQueryBuilder(); $stm = $queryBuilder @@ -182,6 +190,14 @@ public function getContainerRecordsFreeMode(array $cTypes): array $queryBuilder->createNamedParameter(0, Connection::PARAM_INT) ) ); + if (!empty($pid)) { + $stm->andWhere( + $queryBuilder->expr()->eq( + 'pid', + $queryBuilder->createNamedParameter($pid, Connection::PARAM_INT) + ) + ); + } if ((GeneralUtility::makeInstance(Typo3Version::class))->getMajorVersion() >= 12) { $stm = $stm->executeQuery(); } else { diff --git a/Classes/Integrity/Sorting.php b/Classes/Integrity/Sorting.php index 54cf8385..805d2cb4 100644 --- a/Classes/Integrity/Sorting.php +++ b/Classes/Integrity/Sorting.php @@ -54,11 +54,11 @@ public function __construct(Database $database, Registry $tcaRegistry, Container $this->containerService = $containerService; } - public function run(bool $dryRun = true, bool $enableLogging = false): array + public function run(bool $dryRun = true, bool $enableLogging = false, ?int $pid = null): array { $cTypes = $this->tcaRegistry->getRegisteredCTypes(); - $containerRecords = $this->database->getContainerRecords($cTypes); - $containerRecords = array_merge($containerRecords, $this->database->getContainerRecordsFreeMode($cTypes)); + $containerRecords = $this->database->getContainerRecords($cTypes, $pid); + $containerRecords = array_merge($containerRecords, $this->database->getContainerRecordsFreeMode($cTypes, $pid)); $colPosByCType = []; foreach ($cTypes as $cType) { $columns = $this->tcaRegistry->getAvailableColumns($cType);