-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathDeleteChildrenWithNonExistingParentCommand.php
More file actions
60 lines (52 loc) · 1.89 KB
/
DeleteChildrenWithNonExistingParentCommand.php
File metadata and controls
60 lines (52 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?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\NonExistingParentWarning;
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 DeleteChildrenWithNonExistingParentCommand 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
{
$exitCode = 0;
Bootstrap::initializeBackendAuthentication();
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']);
// this fetches all errors / warnings, including unrelated
$res = $this->integrity->run();
foreach ($res['warnings'] as $warning) {
if ($warning instanceof NonExistingParentWarning) {
$exitCode = 1;
$this->integrityFix->deleteChildrenWithNonExistingParent($warning);
}
}
// return with exit code !0 if errors found
return $exitCode;
}
}