Polls are deleted POLL_RETENTION_DAYS (default 90) after creation by the cron job `bin/cake polls cleanup`. POLL_REMINDER_DAYS (default 14) before that the owner gets a one-time reminder mail (expiry_reminded_at). New commands: polls list, show (admin link only with --link), delete, remind, cleanup. The expiry date is shown in the creation mail and the dashboard. Docs: README, AGENTS.md, .env.example. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Command;
|
|
|
|
use Cake\Console\Arguments;
|
|
use Cake\Console\ConsoleIo;
|
|
use Cake\Console\ConsoleOptionParser;
|
|
|
|
/**
|
|
* Deletes polls for good (slides, answers and images included). Unknown polls are an error (exit code 1).
|
|
*
|
|
* Usage: bin/cake polls delete <id|code> [--yes]
|
|
*/
|
|
class PollsDeleteCommand extends PollsCommand
|
|
{
|
|
/**
|
|
* @return string
|
|
*/
|
|
public static function defaultName(): string
|
|
{
|
|
return 'polls delete';
|
|
}
|
|
|
|
/**
|
|
* @param \Cake\Console\ConsoleOptionParser $parser Parser
|
|
* @return \Cake\Console\ConsoleOptionParser
|
|
*/
|
|
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
|
|
{
|
|
return $parser
|
|
->setDescription(__('Löscht Umfragen endgültig, samt Folien, Antworten und Bildern.'))
|
|
->addArgument('poll', [
|
|
'help' => __('ID oder Beitrittscode der Umfrage.'),
|
|
'required' => true,
|
|
])
|
|
->addOption('yes', [
|
|
'short' => 'y',
|
|
'help' => __('Ohne Rückfrage löschen.'),
|
|
'boolean' => true,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param \Cake\Console\Arguments $args Arguments
|
|
* @param \Cake\Console\ConsoleIo $io Console
|
|
* @return int
|
|
*/
|
|
public function execute(Arguments $args, ConsoleIo $io): int
|
|
{
|
|
$reference = (string)$args->getArgument('poll');
|
|
$poll = $this->findPoll($reference);
|
|
if ($poll === null) {
|
|
$io->err(__('Umfrage "{0}" nicht gefunden.', $reference));
|
|
|
|
return static::CODE_ERROR;
|
|
}
|
|
|
|
$io->out(__('#{0} {1} ({2}), angelegt {3}', $poll->id, $poll->title, $poll->email, $this->formatDate($poll->created)));
|
|
if (!$args->getOption('yes') && $io->askChoice(__('Diese Umfrage endgültig löschen?'), ['y', 'n'], 'n') !== 'y') {
|
|
$io->out(__('Abgebrochen.'));
|
|
|
|
return static::CODE_ERROR;
|
|
}
|
|
|
|
return $this->deletePolls([$poll], $io) === 1 ? static::CODE_SUCCESS : static::CODE_ERROR;
|
|
}
|
|
}
|