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>
105 lines
3.6 KiB
PHP
105 lines
3.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Command;
|
|
|
|
use Cake\Console\Arguments;
|
|
use Cake\Console\ConsoleIo;
|
|
use Cake\Console\ConsoleOptionParser;
|
|
|
|
/**
|
|
* Lists polls with owner, activity and expiry date. Never prints admin links.
|
|
*
|
|
* Usage: bin/cake polls list [--expired] [--email=<part>] [--sort=created|activity|title]
|
|
*/
|
|
class PollsListCommand extends PollsCommand
|
|
{
|
|
/**
|
|
* @return string
|
|
*/
|
|
public static function defaultName(): string
|
|
{
|
|
return 'polls list';
|
|
}
|
|
|
|
/**
|
|
* @param \Cake\Console\ConsoleOptionParser $parser Parser
|
|
* @return \Cake\Console\ConsoleOptionParser
|
|
*/
|
|
protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser
|
|
{
|
|
return $parser
|
|
->setDescription(__('Zeigt alle Umfragen mit E-Mail-Adresse, Ablaufdatum und Erinnerung.'))
|
|
->addOption('expired', [
|
|
'help' => __('Nur abgelaufene Umfragen.'),
|
|
'boolean' => true,
|
|
])
|
|
->addOption('email', [
|
|
'help' => __('Nur Umfragen, deren E-Mail-Adresse diesen Text enthält.'),
|
|
])
|
|
->addOption('sort', [
|
|
'help' => __('Sortierung (aufsteigend).'),
|
|
'default' => 'created',
|
|
'choices' => ['created', 'activity', 'title'],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @param \Cake\Console\Arguments $args Arguments
|
|
* @param \Cake\Console\ConsoleIo $io Console
|
|
* @return int
|
|
*/
|
|
public function execute(Arguments $args, ConsoleIo $io): int
|
|
{
|
|
$query = $this->polls()->find()
|
|
->select([
|
|
'Polls.id', 'Polls.title', 'Polls.email', 'Polls.join_code', 'Polls.current_slide_id',
|
|
'Polls.paused_slide_id', 'Polls.last_admin_access', 'Polls.expiry_reminded_at', 'Polls.created',
|
|
])
|
|
->orderBy(['Polls.id' => 'ASC']);
|
|
if ($args->getOption('expired')) {
|
|
$query->find('expired');
|
|
}
|
|
$email = $args->getOption('email');
|
|
if (is_string($email) && $email !== '') {
|
|
$query->where(['Polls.email LIKE' => '%' . addcslashes(strtolower($email), '%_\\') . '%']);
|
|
}
|
|
|
|
/** @var list<\App\Model\Entity\Poll> $polls */
|
|
$polls = $query->all()->toList();
|
|
$sort = (string)$args->getOption('sort');
|
|
if ($sort !== 'created') {
|
|
usort($polls, fn($a, $b): int => match ($sort) {
|
|
'activity' => ($a->last_admin_access ?? $a->created) <=> ($b->last_admin_access ?? $b->created),
|
|
default => strcasecmp($a->title, $b->title),
|
|
});
|
|
}
|
|
|
|
if ($polls === []) {
|
|
$io->out(__('Keine Umfragen gefunden.'));
|
|
|
|
return static::CODE_SUCCESS;
|
|
}
|
|
|
|
$rows = [[__('ID'), __('Code'), __('Titel'), __('E-Mail'), __('Angelegt'), __('Letzter Admin-Besuch'), __('Läuft ab'), __('Erinnert')]];
|
|
foreach ($polls as $poll) {
|
|
$rows[] = [
|
|
(string)$poll->id,
|
|
$poll->join_code,
|
|
mb_strimwidth($poll->title, 0, 40, '…'),
|
|
$poll->email,
|
|
$this->formatDate($poll->created),
|
|
$this->formatDate($poll->last_admin_access),
|
|
$this->formatExpiry($poll),
|
|
$this->formatDate($poll->expiry_reminded_at),
|
|
];
|
|
}
|
|
$io->helper('Table')->output($rows);
|
|
|
|
$expired = count(array_filter($polls, fn($poll): bool => $poll->isExpired()));
|
|
$io->out(__('{0} Umfrage(n), davon {1} abgelaufen.', count($polls), $expired));
|
|
|
|
return static::CODE_SUCCESS;
|
|
}
|
|
}
|