diff --git a/src/Command/ExportCreateCommand.php b/src/Command/ExportCreateCommand.php index bb1d8e3e..4e28902c 100644 --- a/src/Command/ExportCreateCommand.php +++ b/src/Command/ExportCreateCommand.php @@ -68,6 +68,7 @@ class ExportCreateCommand extends Command ->setName('kimai:export:create') ->setDescription('Create exports') ->setHelp('Create exports by several different filters and sent them via email.') + ->addOption('username', null, InputOption::VALUE_REQUIRED, 'The user to be used for generating the export (e.g. used for permissions and decimal setting)') ->addOption('start', null, InputOption::VALUE_OPTIONAL, 'Start date (format: 2020-01-01, default: start of the month)', null) ->addOption('end', null, InputOption::VALUE_OPTIONAL, 'End date (format: 2020-01-31, default: end of the month)', null) ->addOption('timezone', null, InputOption::VALUE_OPTIONAL, 'Timezone for start and end date query (fallback: server timezone)', null) @@ -236,14 +237,21 @@ class ExportCreateCommand extends Command $body = trim($input->getOption('body')); } - $markAsExported = false; - if ($input->getOption('set-exported')) { - $markAsExported = true; + $query = new ExportQuery(); + + $username = $input->getOption('username'); + if (!empty($username)) { + $user = $this->userRepository->loadUserByUsername($username); + if (null === $user) { + $io->error( + sprintf('The given username "%s" could not be resolved', $username) + ); + + return 1; + } + $query->setCurrentUser($user); } - // =============== VALIDATION END =============== - - $query = new ExportQuery(); $query->setBegin($start); $query->setEnd($end); $query->setExported($exportedFilter); @@ -253,8 +261,6 @@ class ExportCreateCommand extends Command foreach ($users as $user) { $query->addUser($user); } - //$query->setRenderer($template); - //$query->setMarkAsExported($markAsExported); $io = new SymfonyStyle($input, $output); @@ -268,7 +274,7 @@ class ExportCreateCommand extends Command $response = $renderer->render($entries, $query); $file = $this->savePreview($response, $directory); - if ($markAsExported) { + if ($input->getOption('set-exported')) { $this->serviceExport->setExported($entries); } diff --git a/tests/Command/ExportCreateCommandTest.php b/tests/Command/ExportCreateCommandTest.php index 89c62b78..171044be 100644 --- a/tests/Command/ExportCreateCommandTest.php +++ b/tests/Command/ExportCreateCommandTest.php @@ -209,7 +209,7 @@ class ExportCreateCommandTest extends KernelTestCase $data = $this->prepareFixtures($start); - $commandTester = $this->createExport(['--template' => 'csv', '--customer' => [$data[0]->getId()], '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d')]); + $commandTester = $this->createExport(['--template' => 'csv', '--customer' => [$data[0]->getId()], '--start' => $start->format('Y-m-d'), '--end' => $end->format('Y-m-d'), '--username' => UserFixtures::USERNAME_SUPER_ADMIN]); $output = $commandTester->getDisplay(); $this->assertStringContainsString('Saved export to: ', $output);