Skip to content

Commit

Permalink
[TASK] Add new argument 'pid' to sorting command
Browse files Browse the repository at this point in the history
  • Loading branch information
kitzberger authored and achimfritz committed Feb 14, 2024
1 parent 823e6de commit aaec4bc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
8 changes: 7 additions & 1 deletion Classes/Command/SortingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
}
Expand Down
20 changes: 18 additions & 2 deletions Classes/Integrity/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions Classes/Integrity/Sorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit aaec4bc

Please sign in to comment.