-
Notifications
You must be signed in to change notification settings - Fork 31
Return count when row_count is selected #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how this part is relevant. Note that the result-code is important for handling errors in bash scripts. Returning Some examples: set -e
cd path/to/my/ext
git pull
cv upgrade:db
cd .. set -e
cv api4 Contact.get +s display_name --out=list | while read NAME; do
echo "Say hello to $NAME for me"
done cv flush && cv ext:list -R In the first two cases, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just cleanup. This function looks to have been copy/pasted from the api3 function. Api3 returns an |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aah, interesting, so you can
select
therow_count
even though it's not actually a field in the result. This feels weird.... but OK, it appears to work w/AJAX. The AJAX-bindings wrap all results in an extra layer of JSON ({values: ..., count: ...}
).Of course, the patch above works if you select only the
row_count
. If you want to get data as well asrow_count
, then one needs to be more like the AJAX-bindings. I guess one could port the AJAX technique -- and for compatibility purposes, treat it as a flag, e.g.or like:
FWIW, even with the wrapping, there's still a problem with chaining. You can see this in AJAX calls:
I guess a couple questions:
If the answer is "No" on both fronts, then I'd be OK with this kind of special case. Otherwise, it's probably better to make the serialization formats more aligned.