Remove the polls menu, keep the single commands
CI / Deploy / PHP 8.5 (push) Successful in 1m2s
CI / Deploy / PHP 8.4 (push) Successful in 1m11s
CI / Deploy / test (push) Successful in 3s
CI / Deploy / deploy (push) Skipped

bin/cake polls list|show|delete|remind|cleanup stay as they are.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-16 13:58:26 +01:00
1 parent 664088e139
commit 349359dad3
6 files changed
+4 -220

No files matched your search

-165
View File
@@ -1,165 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Model\Entity\Poll;
use Cake\Console\Arguments;
use Cake\Console\ConsoleIo;
use Cake\Console\ConsoleOptionParser;
/**
* Menu-driven entry to the poll administration: `bin/cake polls` without a sub command.
* Only wraps the other `polls …` commands, so scripts and cron keep using those directly.
* Every prompt has a safe default (back/quit/no), so a closed stdin ends the menu instead of looping.
*
* Usage: bin/cake polls
*/
class PollsMenuCommand extends PollsCommand
{
/**
* @return string
*/
public static function defaultName(): string
{
return 'polls';
}
/**
* @param \Cake\Console\ConsoleOptionParser $parser Parser
* @return \Cake\Console\ConsoleOptionParser
*/
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
{
return $parser
->setDescription(__('Menügeführte Verwaltung der Umfragen. Für Skripte und Cron: polls list|show|delete|remind|cleanup.'));
}
/**
* @param \Cake\Console\Arguments $args Arguments
* @param \Cake\Console\ConsoleIo $io Console
* @return int
*/
public function execute(Arguments $args, ConsoleIo $io): int
{
while (true) {
$io->out('');
$io->out('<info>' . __('PlenarIO – Umfragen verwalten') . '</info>');
$io->out([
' 1) ' . __('Alle Umfragen anzeigen'),
' 2) ' . __('Abgelaufene Umfragen anzeigen'),
' 3) ' . __('Nach E-Mail-Adresse suchen'),
' 4) ' . __('Umfrage öffnen (Details, Admin-Link, Löschen)'),
' 5) ' . __('Erinnerungen vor dem Ablauf versenden'),
' 6) ' . __('Aufräumen (Erinnern, abgelaufene Umfragen löschen)'),
' 0) ' . __('Beenden'),
]);
switch ($io->askChoice(__('Was möchtest du tun?'), ['1', '2', '3', '4', '5', '6', '0'], '0')) {
case '1':
$this->executeCommand(PollsListCommand::class, [], $io);
break;
case '2':
$this->executeCommand(PollsListCommand::class, ['--expired'], $io);
break;
case '3':
$email = $io->ask(__('Teil der E-Mail-Adresse (leer = zurück)'), '');
if ($email !== '') {
$this->executeCommand(PollsListCommand::class, ['--email=' . $email], $io);
}
break;
case '4':
$this->openPoll($io);
break;
case '5':
$this->confirmed($io, PollsRemindCommand::class, $this->polls()->find('reminderDue')->count());
break;
case '6':
$this->confirmed($io, PollsCleanupCommand::class, $this->polls()->find('expired')->count()
+ $this->polls()->find('reminderDue')->count());
break;
default:
return static::CODE_SUCCESS;
}
}
}
/**
* Shows what a command would do (--dry-run), asks and only then runs it for real.
*
* @param \Cake\Console\ConsoleIo $io Console
* @param class-string<\Cake\Command\Command> $command Command with a --dry-run option
* @param int $affected Number of polls the command would touch
* @return void
*/
protected function confirmed(ConsoleIo $io, string $command, int $affected): void
{
if ($affected === 0) {
$io->out(__('Nichts zu tun.'));
return;
}
$this->executeCommand($command, ['--dry-run'], $io);
if ($io->askChoice(__('Jetzt ausführen?'), ['y', 'n'], 'n') === 'y') {
$this->executeCommand($command, [], $io);
} else {
$io->out(__('Abgebrochen.'));
}
}
/**
* Asks for one poll and offers the actions on it until the user goes back.
*
* @param \Cake\Console\ConsoleIo $io Console
* @return void
*/
protected function openPoll(ConsoleIo $io): void
{
$this->executeCommand(PollsListCommand::class, [], $io);
$reference = $io->ask(__('ID oder Code der Umfrage (leer = zurück)'), '');
if ($reference === '') {
return;
}
$poll = $this->findPoll($reference);
if ($poll === null) {
$io->err(__('Umfrage „{0}“ nicht gefunden.', $reference));
return;
}
$this->executeCommand(PollsShowCommand::class, [(string)$poll->id], $io);
while (true) {
$io->out([
'',
' 1) ' . __('Details anzeigen'),
' 2) ' . __('Admin-Link anzeigen (geheim!)'),
' 3) ' . __('Umfrage endgültig löschen'),
' 0) ' . __('Zurück'),
]);
$choice = $io->askChoice(__('#{0} {1}: Was möchtest du tun?', $poll->id, $this->shorten($poll)), ['1', '2', '3', '0'], '0');
if ($choice === '1') {
$this->executeCommand(PollsShowCommand::class, [(string)$poll->id], $io);
} elseif ($choice === '2') {
$this->executeCommand(PollsShowCommand::class, [(string)$poll->id, '--link'], $io);
} elseif ($choice === '3') {
// The delete command asks for confirmation itself.
$this->executeCommand(PollsDeleteCommand::class, [(string)$poll->id], $io);
if ($this->polls()->find()->where(['Polls.id' => $poll->id])->count() === 0) {
return;
}
} else {
return;
}
}
}
/**
* @param \App\Model\Entity\Poll $poll Poll
* @return string Title, shortened for prompts
*/
protected function shorten(Poll $poll): string
{
return mb_strimwidth($poll->title, 0, 40, '…');
}
}