-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathSortingCommand.php
More file actions
75 lines (65 loc) · 2.39 KB
/
SortingCommand.php
File metadata and controls
75 lines (65 loc) · 2.39 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?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\Sorting;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
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 SortingCommand extends Command
{
/**
* @var Sorting
*/
protected $sorting;
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',
null,
InputOption::VALUE_NONE,
'enables datahandler logging, should only use for debug issues, not in production'
);
}
public function __construct(Sorting $sorting, ?string $name = null)
{
parent::__construct($name);
$this->sorting = $sorting;
}
public function execute(InputInterface $input, OutputInterface $output): int
{
$dryrun = $input->getOption('apply') !== true;
$pid = (int)$input->getArgument('pid');
Bootstrap::initializeBackendAuthentication();
$GLOBALS['LANG'] = GeneralUtility::makeInstance(LanguageServiceFactory::class)->createFromUserPreferences($GLOBALS['BE_USER']);
$errors = $this->sorting->run(
$dryrun,
$input->getOption('enable-logging'),
$pid
);
if ($output->isVerbose()) {
$output->writeln('Checking ' . ($pid > 0 ? 'page ' . $pid : 'entire pagetree') . ($dryrun ? ' [DRYRUN]' : ''));
foreach ($errors as $error) {
$output->writeln($error);
}
if (empty($errors)) {
$output->writeln('- all good, nothing to do here');
}
}
// return with exit code !0 if errors found
return count($errors) > 0 ? 1 : 0;
}
}