Add --json to polls list and polls show
Machine-readable output for scripts; never contains the admin token unless --link is given. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
664088e139
commit
3d6ade668f
6 files changed
+115
-2
No files matched your search
@@ -34,6 +34,10 @@ class PollsShowCommand extends PollsCommand
|
||||
'help' => __('ID oder Beitrittscode der Umfrage.'),
|
||||
'required' => true,
|
||||
])
|
||||
->addOption('json', [
|
||||
'help' => __('Ausgabe als JSON statt als Text (für Skripte).'),
|
||||
'boolean' => true,
|
||||
])
|
||||
->addOption('link', [
|
||||
'help' => __('Auch den Admin-Link ausgeben (enthält das geheime Token!).'),
|
||||
'boolean' => true,
|
||||
@@ -55,6 +59,21 @@ class PollsShowCommand extends PollsCommand
|
||||
}
|
||||
|
||||
$slides = $this->fetchTable('Slides')->find()->where(['poll_id' => $poll->id])->count();
|
||||
if ($args->getOption('json')) {
|
||||
$data = $this->pollData($poll) + ['slides' => $slides, 'adminUrl' => null];
|
||||
if ($args->getOption('link')) {
|
||||
$data['adminUrl'] = $this->adminLink($poll);
|
||||
if ($data['adminUrl'] === null) {
|
||||
$io->err(__('Der Admin-Link lässt sich nicht entschlüsseln (SECURITY_SALT geändert?).'));
|
||||
|
||||
return static::CODE_ERROR;
|
||||
}
|
||||
}
|
||||
$this->printJson($io, $data);
|
||||
|
||||
return static::CODE_SUCCESS;
|
||||
}
|
||||
|
||||
$io->out([
|
||||
__('ID: {0}', $poll->id),
|
||||
__('Titel: {0}', $poll->title),
|
||||
|
||||
Reference in new issue
Block a user