Machine-readable output for scripts; never contains the admin token unless --link is given. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
105 lines
3.5 KiB
PHP
105 lines
3.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Command;
|
|
|
|
use Cake\Console\Arguments;
|
|
use Cake\Console\ConsoleIo;
|
|
use Cake\Console\ConsoleOptionParser;
|
|
|
|
/**
|
|
* Details of one poll. The secret admin link is only printed with --link.
|
|
*
|
|
* Usage: bin/cake polls show <id|code> [--link]
|
|
*/
|
|
class PollsShowCommand extends PollsCommand
|
|
{
|
|
/**
|
|
* @return string
|
|
*/
|
|
public static function defaultName(): string
|
|
{
|
|
return 'polls show';
|
|
}
|
|
|
|
/**
|
|
* @param \Cake\Console\ConsoleOptionParser $parser Parser
|
|
* @return \Cake\Console\ConsoleOptionParser
|
|
*/
|
|
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
|
|
{
|
|
return $parser
|
|
->setDescription(__('Zeigt Details einer Umfrage, auf Wunsch mit dem geheimen Admin-Link.'))
|
|
->addArgument('poll', [
|
|
'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,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param \Cake\Console\Arguments $args Arguments
|
|
* @param \Cake\Console\ConsoleIo $io Console
|
|
* @return int
|
|
*/
|
|
public function execute(Arguments $args, ConsoleIo $io): int
|
|
{
|
|
$poll = $this->findPoll((string)$args->getArgument('poll'));
|
|
if ($poll === null) {
|
|
$io->err(__('Umfrage nicht gefunden.'));
|
|
|
|
return static::CODE_ERROR;
|
|
}
|
|
|
|
$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),
|
|
__('E-Mail: {0}', $poll->email),
|
|
__('Beitrittscode: {0}', $poll->join_code),
|
|
__('Teilnahme-Link: {0}', $this->joinLink($poll)),
|
|
__('Folien: {0}', $slides),
|
|
__('Angelegt: {0}', $this->formatDate($poll->created)),
|
|
__('Letzter Besuch: {0}', $this->formatDate($poll->last_admin_access)),
|
|
__('Läuft ab: {0}', $this->formatExpiry($poll)),
|
|
__('Erinnerung: {0}', $poll->expiry_reminded_at === null ? __('nicht verschickt') : $this->formatDate($poll->expiry_reminded_at)),
|
|
]);
|
|
|
|
if ($args->getOption('link')) {
|
|
$link = $this->adminLink($poll);
|
|
if ($link === null) {
|
|
$io->err(__('Der Admin-Link lässt sich nicht entschlüsseln (SECURITY_SALT geändert?).'));
|
|
|
|
return static::CODE_ERROR;
|
|
}
|
|
$io->out(__('Admin-Link: {0}', $link));
|
|
} else {
|
|
$io->out(__('Admin-Link: (mit --link anzeigen)'));
|
|
}
|
|
|
|
return static::CODE_SUCCESS;
|
|
}
|
|
}
|