From 9bcbb69f107616bd1650ae68235d09f5d48b276a Mon Sep 17 00:00:00 2001 From: colemanw Date: Tue, 11 May 2021 16:59:45 -0400 Subject: [PATCH] Return count when row_count is selected When the api is selecting only row_count it should return the count, otherwise the output looks like an empty array --- src/Command/Api4Command.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Command/Api4Command.php b/src/Command/Api4Command.php index 995381df..4e8c6fde 100644 --- a/src/Command/Api4Command.php +++ b/src/Command/Api4Command.php @@ -132,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { throw new \RuntimeException("Please enable APIv4 before running APIv4 commands."); } - list($entity, $action) = explode('.', $input->getArgument('Entity.action')); + [$entity, $action] = explode('.', $input->getArgument('Entity.action')); $params = $this->parseParams($input); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE || $input->getOption('dry-run')) { $output->writeln("{$I}Entity{$_I}: {$C}$entity{$_C}"); @@ -149,11 +149,14 @@ protected function execute(InputInterface $input, OutputInterface $output) { $columns = empty($params['select']) ? array_keys($result->first()) : $params['select']; $this->sendTable($input, $output, (array) $result, $columns); } + elseif (!empty($params['select']) && $params['select'] === ['row_count']) { + $this->sendResult($input, $output, $result->count()); + } else { $this->sendResult($input, $output, $result); } - return empty($result['is_error']) ? 0 : 1; + return 0; } /**