mirror of
https://github.com/FriendsOfTYPO3/tea.git
synced 2024-11-09 03:36:13 +01:00
parent
277a167621
commit
72d449b9bd
2 changed files with 13 additions and 11 deletions
|
@ -24,13 +24,13 @@ final class CreateTestDataCommand extends Command
|
||||||
[
|
[
|
||||||
'title' => 'Darjeeling',
|
'title' => 'Darjeeling',
|
||||||
'description' => 'I love that tea!',
|
'description' => 'I love that tea!',
|
||||||
'sys_language_uid' => 0
|
'sys_language_uid' => 0,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'title' => 'Earl Grey',
|
'title' => 'Earl Grey',
|
||||||
'description' => 'A nice tea!',
|
'description' => 'A nice tea!',
|
||||||
'sys_language_uid' => 0
|
'sys_language_uid' => 0,
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
{
|
{
|
||||||
|
@ -51,23 +51,24 @@ final class CreateTestDataCommand extends Command
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
/** @var integer $pageId */
|
/** @var int $pageId */
|
||||||
$pageId = $input->getArgument('pageId') ?? 0;
|
$pageId = $input->getArgument('pageId') ?? 0;
|
||||||
/** @var boolean $deleteDataBefore */
|
/** @var bool $deleteDataBefore */
|
||||||
$deleteDataBefore = $input->getOption('delete-data-before') ?? false;
|
$deleteDataBefore = $input->getOption('delete-data-before') ?? false;
|
||||||
$table = 'tx_tea_domain_model_tea';
|
$table = 'tx_tea_domain_model_tea';
|
||||||
$connectionForTable = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
|
$connectionForTable = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
|
||||||
|
|
||||||
if($deleteDataBefore) {
|
if ($deleteDataBefore) {
|
||||||
$query = $connectionForTable;
|
$query = $connectionForTable;
|
||||||
$query->delete($table, ['pid' => $pageId], [Connection::PARAM_INT]);
|
$query->delete($table, ['pid' => $pageId], [Connection::PARAM_INT]);
|
||||||
$output->writeln(sprintf('Existing data in page %s deleted.',$pageId));
|
$output->writeln(sprintf('Existing data in page %s deleted.', $pageId));
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $connectionForTable;
|
$query = $connectionForTable;
|
||||||
foreach ($this->teaData as $item) {
|
foreach ($this->teaData as $item) {
|
||||||
$item = ['pid' => $pageId, ...$item];
|
$item = ['pid' => $pageId, ...$item];
|
||||||
$query->insert($table,
|
$query->insert(
|
||||||
|
$table,
|
||||||
$item
|
$item
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,11 @@ return static function (ContainerConfigurator $containerConfigurator) {
|
||||||
->exclude('../Classes/Domain/Model/*');
|
->exclude('../Classes/Domain/Model/*');
|
||||||
|
|
||||||
$services->set(CreateTestDataCommand::class)
|
$services->set(CreateTestDataCommand::class)
|
||||||
->tag('console.command', [
|
->tag(
|
||||||
|
'console.command',
|
||||||
|
[
|
||||||
'command' => 'tea:createtestdata',
|
'command' => 'tea:createtestdata',
|
||||||
'description'=>'Create test data in existing sysfolder'
|
'description' => 'Create test data in existing sysfolder',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue