Let polls remind target one poll for testing
CI / Deploy / PHP 8.5 (push) Successful in 1m6s
CI / Deploy / PHP 8.4 (push) Successful in 1m12s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped

`polls remind <id|code>` sends the reminder to that poll right away,
ignoring the reminder window, an earlier reminder and POLL_REMINDER_DAYS.
A forced reminder does not set the reminded marker.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-16 14:10:08 +01:00
1 parent 4f03414d7a
commit f21aead039
4 files changed
+80 -10

No files matched your search

+35 -9
View File
@@ -15,7 +15,11 @@ use Cake\I18n\DateTime;
* Idempotent: a poll is marked after a successful send; a failed send is retried at the next run.
* `polls cleanup` runs this first, a separate cron entry is not needed.
*
* Usage: bin/cake polls remind [--dry-run]
* With an id or code the reminder goes to that one poll right now (for testing the mail): regardless of the
* reminder window, of an earlier reminder and of POLL_REMINDER_DAYS. A forced reminder does not set the
* "reminded" marker, so the regular reminder still goes out when it is due.
*
* Usage: bin/cake polls remind [<id|code>] [--dry-run]
*/
class PollsRemindCommand extends PollsCommand
{
@@ -35,6 +39,10 @@ class PollsRemindCommand extends PollsCommand
{
return $parser
->setDescription(__('Erinnert Besitzer per E-Mail, bevor ihre Umfrage automatisch gelöscht wird.'))
->addArgument('poll', [
'help' => __('Optional: ID oder Beitrittscode. Verschickt die Erinnerung sofort und erzwungen an diese Umfrage (zum Testen), ohne sie als erinnert zu markieren.'),
'required' => false,
])
->addOption('dry-run', [
'help' => __('Nur anzeigen, nichts verschicken.'),
'boolean' => true,
@@ -48,16 +56,32 @@ class PollsRemindCommand extends PollsCommand
*/
public function execute(Arguments $args, ConsoleIo $io): int
{
if (Poll::reminderLeadDays() === 0) {
$dryRun = (bool)$args->getOption('dry-run');
$reference = $args->getArgument('poll');
$forced = $reference !== null;
if ($forced) {
$poll = $this->findPoll((string)$reference);
if ($poll === null) {
$io->err(__('Umfrage „{0}“ nicht gefunden.', $reference));
return static::CODE_ERROR;
}
if ($poll->expiresAt() === null) {
$io->err(__('Umfragen laufen nie ab (POLL_RETENTION_DAYS=0), die Mail braucht ein Ablaufdatum.'));
return static::CODE_ERROR;
}
$due = [$poll];
} elseif (Poll::reminderLeadDays() === 0) {
$io->out(__('Erinnerungen sind aus (POLL_REMINDER_DAYS=0 oder Umfragen laufen nie ab).'));
return static::CODE_SUCCESS;
} else {
/** @var list<\App\Model\Entity\Poll> $due */
$due = $this->polls()->find('reminderDue')->orderBy(['Polls.id' => 'ASC'])->all()->toList();
}
$dryRun = (bool)$args->getOption('dry-run');
/** @var list<\App\Model\Entity\Poll> $due */
$due = $this->polls()->find('reminderDue')->orderBy(['Polls.id' => 'ASC'])->all()->toList();
$sent = 0;
$failed = 0;
foreach ($due as $poll) {
@@ -78,9 +102,11 @@ class PollsRemindCommand extends PollsCommand
$failed++;
continue;
}
// Only the marker column; the poll may have been changed meanwhile.
$this->polls()->updateAll(['expiry_reminded_at' => DateTime::now()], ['id' => $poll->id]);
$io->out(__('Erinnert: {0}', $label));
if (!$forced) {
// Only the marker column; the poll may have been changed meanwhile.
$this->polls()->updateAll(['expiry_reminded_at' => DateTime::now()], ['id' => $poll->id]);
}
$io->out(($forced ? __('Erinnert (erzwungen, nicht markiert): {0}', $label) : __('Erinnert: {0}', $label)));
$sent++;
}