Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions Classes/Command/DeleteChildrenWithUnusedColPosCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace B13\Container\Command;

/*
* This file is part of TYPO3 CMS-based extension "container" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use B13\Container\Integrity\Error\UnusedColPosWarning;
use B13\Container\Integrity\Integrity;
use B13\Container\Integrity\IntegrityFix;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Localization\LanguageServiceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class DeleteChildrenWithUnusedColPosCommand extends Command
{
/**
* @var Integrity
*/
protected $integrity;

/**
* @var IntegrityFix
*/
protected $integrityFix;

public function __construct(Integrity $integrity, IntegrityFix $integrityFix, ?string $name = null)
{
$this->integrity = $integrity;
$this->integrityFix = $integrityFix;
parent::__construct($name);
}

public function execute(InputInterface $input, OutputInterface $output): int
{
Bootstrap::initializeBackendAuthentication();
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']);
$res = $this->integrity->run();
foreach ($res['warnings'] as $warning) {
if ($warning instanceof UnusedColPosWarning) {
$this->integrityFix->deleteChildrenWithUnusedColPos($warning);
}
}
return 0;
}
}
8 changes: 8 additions & 0 deletions Classes/Integrity/Error/UnusedColPosWarning.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public function __construct(array $childRecord, array $containerRecord)
. ' with CType ' . $containerRecord['CType'];
}

/**
* @return array
*/
public function getChildRecord(): array
{
return $this->childRecord;
}

/**
* @return string
*/
Expand Down
11 changes: 11 additions & 0 deletions Classes/Integrity/IntegrityFix.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use B13\Container\Integrity\Error\ChildInTranslatedContainerError;
use B13\Container\Integrity\Error\NonExistingParentWarning;
use B13\Container\Integrity\Error\UnusedColPosWarning;
use B13\Container\Integrity\Error\WrongL18nParentError;
use B13\Container\Integrity\Error\WrongPidError;
use B13\Container\Tca\Registry;
Expand Down Expand Up @@ -60,6 +61,16 @@ public function deleteChildrenWithNonExistingParent(NonExistingParentWarning $no
$dataHandler->process_cmdmap();
}

public function deleteChildrenWithUnusedColPos(UnusedColPosWarning $unusedColPosWarning): void
{
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->enableLogging = false;
$childRecord = $unusedColPosWarning->getChildRecord();
$cmd = ['tt_content' => [$childRecord['uid'] => ['delete' => 1]]];
$dataHandler->start([], $cmd);
$dataHandler->process_cmdmap();
}

public function changeContainerParentToDefaultLanguageContainer(ChildInTranslatedContainerError $e): void
{
$translatedContainer = $e->getContainerRecord();
Expand Down
6 changes: 6 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ services:
command: 'container:deleteChildrenWithNonExistingParent'
schedulable: false
description: delete all child records with a non existing parent record (they are displayed as unsued)
B13\Container\Command\DeleteChildrenWithUnusedColPosCommand:
tags:
- name: 'console.command'
command: 'container:deleteChildrenWithUnusedColPos'
schedulable: false
description: delete all child records with a colPos that is not available for the parent CType (they are displayed as unsued)
B13\Container\Command\IntegrityCommand:
tags:
- name: 'console.command'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ bin/typo3 container:fixLanguageMode
bin/typo3 container:fixContainerParentForConnectedMode
bin/typo3 container:deleteChildrenWithWrongPid
bin/typo3 container:deleteChildrenWithNonExistingParent
bin/typo3 container:deleteChildrenWithUnusedColPos
```

## TODOs
Expand Down
Loading