Merge pull request 'Let polls remind target one poll for testing' (#90) from feature/remind-force into main
Reviewed-on: #90
This commit was merged in pull request #90.
This commit is contained in:
commit
6f20ddf5f7
4 files changed
+77
-7
No files matched your search
+1
-1
@@ -125,7 +125,7 @@ Zum Verwalten per Hand und für Skripte/Cron:
|
|||||||
| `bin/cake polls list [--expired] [--email=text] [--sort=created\|activity\|title] [--json]` | Umfragen mit E-Mail, Ablaufdatum und Erinnerung |
|
| `bin/cake polls list [--expired] [--email=text] [--sort=created\|activity\|title] [--json]` | Umfragen mit E-Mail, Ablaufdatum und Erinnerung |
|
||||||
| `bin/cake polls show <id\|code> [--link] [--json]` | Details; mit `--link` auch der geheime Admin-Link (nur auf Wunsch) |
|
| `bin/cake polls show <id\|code> [--link] [--json]` | Details; mit `--link` auch der geheime Admin-Link (nur auf Wunsch) |
|
||||||
| `bin/cake polls delete <id\|code> [--yes]` | Eine Umfrage samt Folien, Antworten und Bildern löschen (fragt nach) |
|
| `bin/cake polls delete <id\|code> [--yes]` | Eine Umfrage samt Folien, Antworten und Bildern löschen (fragt nach) |
|
||||||
| `bin/cake polls remind [--dry-run]` | Erinnerungsmails für bald ablaufende Umfragen (je Umfrage einmal) |
|
| `bin/cake polls remind [<id\|code>] [--dry-run]` | Erinnerungsmails für bald ablaufende Umfragen (je Umfrage einmal). Mit ID oder Code geht die Mail sofort und erzwungen nur an diese Umfrage, zum Testen: unabhängig vom Erinnerungsfenster und von `POLL_REMINDER_DAYS`, beliebig oft, ohne die Umfrage als erinnert zu markieren (die reguläre Erinnerung kommt trotzdem noch) |
|
||||||
| `bin/cake polls cleanup [--dry-run]` | Der Cronjob: erst erinnern, dann abgelaufene Umfragen löschen, danach verwaiste Bilddateien |
|
| `bin/cake polls cleanup [--dry-run]` | Der Cronjob: erst erinnern, dann abgelaufene Umfragen löschen, danach verwaiste Bilddateien |
|
||||||
|
|
||||||
Eine Umfrage läuft `POLL_RETENTION_DAYS` Tage (Standard 90) nach dem Anlegen ab und wird dann gelöscht, unabhängig davon,
|
Eine Umfrage läuft `POLL_RETENTION_DAYS` Tage (Standard 90) nach dem Anlegen ab und wird dann gelöscht, unabhängig davon,
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ Aufräumen und Erinnerungen, CI/CD, Release-Pakete, Container.
|
|||||||
ist die einzige Stelle, die den Admin-Link ausgibt (nie in `list`).
|
ist die einzige Stelle, die den Admin-Link ausgibt (nie in `list`).
|
||||||
`polls list|show --json` gibt nur JSON aus (`PollsCommand::pollData()`/`printJson()`, Ausgabemodus RAW, sonst würden `<…>` in Titeln als
|
`polls list|show --json` gibt nur JSON aus (`PollsCommand::pollData()`/`printJson()`, Ausgabemodus RAW, sonst würden `<…>` in Titeln als
|
||||||
Markup verschluckt; nie das Token, `adminUrl` nur mit `--link`).
|
Markup verschluckt; nie das Token, `adminUrl` nur mit `--link`).
|
||||||
|
`polls remind <id|code>` erzwingt die Erinnerung für genau eine Umfrage (Testzweck): ignoriert Fenster, Marker und `POLL_REMINDER_DAYS`,
|
||||||
|
setzt `expiry_reminded_at` nicht, braucht aber ein Ablaufdatum (`POLL_RETENTION_DAYS` > 0).
|
||||||
Tests: `PollsCommandsTest.php` (leert vorher alle Umfragen).
|
Tests: `PollsCommandsTest.php` (leert vorher alle Umfragen).
|
||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
|
|||||||
@@ -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.
|
* 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.
|
* `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
|
class PollsRemindCommand extends PollsCommand
|
||||||
{
|
{
|
||||||
@@ -35,6 +39,10 @@ class PollsRemindCommand extends PollsCommand
|
|||||||
{
|
{
|
||||||
return $parser
|
return $parser
|
||||||
->setDescription(__('Erinnert Besitzer per E-Mail, bevor ihre Umfrage automatisch gelöscht wird.'))
|
->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', [
|
->addOption('dry-run', [
|
||||||
'help' => __('Nur anzeigen, nichts verschicken.'),
|
'help' => __('Nur anzeigen, nichts verschicken.'),
|
||||||
'boolean' => true,
|
'boolean' => true,
|
||||||
@@ -48,15 +56,31 @@ class PollsRemindCommand extends PollsCommand
|
|||||||
*/
|
*/
|
||||||
public function execute(Arguments $args, ConsoleIo $io): int
|
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).'));
|
$io->out(__('Erinnerungen sind aus (POLL_REMINDER_DAYS=0 oder Umfragen laufen nie ab).'));
|
||||||
|
|
||||||
return static::CODE_SUCCESS;
|
return static::CODE_SUCCESS;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
$dryRun = (bool)$args->getOption('dry-run');
|
|
||||||
/** @var list<\App\Model\Entity\Poll> $due */
|
/** @var list<\App\Model\Entity\Poll> $due */
|
||||||
$due = $this->polls()->find('reminderDue')->orderBy(['Polls.id' => 'ASC'])->all()->toList();
|
$due = $this->polls()->find('reminderDue')->orderBy(['Polls.id' => 'ASC'])->all()->toList();
|
||||||
|
}
|
||||||
|
|
||||||
$sent = 0;
|
$sent = 0;
|
||||||
$failed = 0;
|
$failed = 0;
|
||||||
@@ -78,9 +102,11 @@ class PollsRemindCommand extends PollsCommand
|
|||||||
$failed++;
|
$failed++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!$forced) {
|
||||||
// Only the marker column; the poll may have been changed meanwhile.
|
// Only the marker column; the poll may have been changed meanwhile.
|
||||||
$this->polls()->updateAll(['expiry_reminded_at' => DateTime::now()], ['id' => $poll->id]);
|
$this->polls()->updateAll(['expiry_reminded_at' => DateTime::now()], ['id' => $poll->id]);
|
||||||
$io->out(__('Erinnert: {0}', $label));
|
}
|
||||||
|
$io->out(($forced ? __('Erinnert (erzwungen, nicht markiert): {0}', $label) : __('Erinnert: {0}', $label)));
|
||||||
$sent++;
|
$sent++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use App\Test\TestCase\PlenarioTestTrait;
|
|||||||
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
|
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
|
||||||
use Cake\Core\Configure;
|
use Cake\Core\Configure;
|
||||||
use Cake\I18n\DateTime;
|
use Cake\I18n\DateTime;
|
||||||
|
use Cake\TestSuite\EmailTrait;
|
||||||
use Cake\TestSuite\TestCase;
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,6 +16,7 @@ use Cake\TestSuite\TestCase;
|
|||||||
class PollsCommandsTest extends TestCase
|
class PollsCommandsTest extends TestCase
|
||||||
{
|
{
|
||||||
use ConsoleIntegrationTestTrait;
|
use ConsoleIntegrationTestTrait;
|
||||||
|
use EmailTrait;
|
||||||
use PlenarioTestTrait;
|
use PlenarioTestTrait;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
@@ -193,6 +195,46 @@ class PollsCommandsTest extends TestCase
|
|||||||
$this->assertNotEmpty($youngToken . $dueToken);
|
$this->assertNotEmpty($youngToken . $dueToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRemindCanBeForcedForOnePoll(): void
|
||||||
|
{
|
||||||
|
[$young] = $this->createPoll('Frisch', 'frisch@example.org');
|
||||||
|
[$other] = $this->createPoll('Anderer', 'anderer@example.org');
|
||||||
|
|
||||||
|
// Not in the reminder window at all, yet it is sent on request, to this poll only.
|
||||||
|
$this->exec('polls remind ' . $young->join_code);
|
||||||
|
$this->assertExitSuccess();
|
||||||
|
$this->assertOutputContains('erzwungen');
|
||||||
|
$this->assertMailCount(1);
|
||||||
|
$this->assertMailSentTo('frisch@example.org');
|
||||||
|
$this->assertNull($this->pollsTable()->get($young->id)->expiry_reminded_at, 'a forced reminder does not mark the poll');
|
||||||
|
|
||||||
|
// Sendable again (also after a regular reminder), still not marked.
|
||||||
|
$this->pollsTable()->updateAll(['expiry_reminded_at' => DateTime::now()], ['id' => $young->id]);
|
||||||
|
$this->exec('polls remind ' . $young->id);
|
||||||
|
$this->assertExitSuccess();
|
||||||
|
$this->assertMailCount(2);
|
||||||
|
|
||||||
|
// Dry run sends nothing.
|
||||||
|
$this->exec('polls remind ' . $other->id . ' --dry-run');
|
||||||
|
$this->assertOutputContains('Würde erinnern');
|
||||||
|
$this->assertMailCount(2);
|
||||||
|
|
||||||
|
// Works with reminders switched off, fails without an expiry date and for unknown polls.
|
||||||
|
Configure::write('Plenario.retention.reminderDays', 0);
|
||||||
|
$this->exec('polls remind ' . $other->id);
|
||||||
|
$this->assertExitSuccess();
|
||||||
|
$this->assertMailCount(3);
|
||||||
|
|
||||||
|
$this->exec('polls remind 99999');
|
||||||
|
$this->assertExitError();
|
||||||
|
$this->assertErrorContains('nicht gefunden');
|
||||||
|
|
||||||
|
Configure::write('Plenario.retention.days', 0);
|
||||||
|
$this->exec('polls remind ' . $other->id);
|
||||||
|
$this->assertExitError();
|
||||||
|
$this->assertMailCount(3);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCleanupRemindsThenDeletesOnlyExpiredPollsAndIsIdempotent(): void
|
public function testCleanupRemindsThenDeletesOnlyExpiredPollsAndIsIdempotent(): void
|
||||||
{
|
{
|
||||||
[$old] = $this->createPoll('Alt');
|
[$old] = $this->createPoll('Alt');
|
||||||
|
|||||||
Reference in new issue
Block a user