Add poll expiry, reminder mail and polls admin CLI
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>
This commit is contained in:
1 parent
4caff47a09
commit
a19cd8339e
20 files changed
+976
-1
No files matched your search
@@ -9,6 +9,7 @@ use ArrayObject;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Event\EventInterface;
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\RulesChecker;
|
||||
use Cake\ORM\Table;
|
||||
@@ -276,6 +277,45 @@ class PollsTable extends Table
|
||||
return $query->where(['Polls.join_code' => static::normalizeJoinCode($code)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls past their expiry date (created + retention, see Poll::expiresAt()); none if the retention is 0.
|
||||
*
|
||||
* @param \Cake\ORM\Query\SelectQuery $query Query
|
||||
* @return \Cake\ORM\Query\SelectQuery
|
||||
*/
|
||||
public function findExpired(SelectQuery $query): SelectQuery
|
||||
{
|
||||
$days = (int)Configure::read('Plenario.retention.days', 90);
|
||||
if ($days <= 0) {
|
||||
return $query->where('1 = 0');
|
||||
}
|
||||
|
||||
return $query->where(['Polls.created <' => DateTime::now()->subDays($days)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Polls whose reminder is due and not yet sent: inside the last `reminderDays` before the expiry,
|
||||
* but not expired yet (then it is too late, they are deleted).
|
||||
*
|
||||
* @param \Cake\ORM\Query\SelectQuery $query Query
|
||||
* @return \Cake\ORM\Query\SelectQuery
|
||||
*/
|
||||
public function findReminderDue(SelectQuery $query): SelectQuery
|
||||
{
|
||||
$lead = Poll::reminderLeadDays();
|
||||
if ($lead === 0) {
|
||||
return $query->where('1 = 0');
|
||||
}
|
||||
$days = (int)Configure::read('Plenario.retention.days', 90);
|
||||
$now = DateTime::now();
|
||||
|
||||
return $query->where([
|
||||
'Polls.expiry_reminded_at IS' => null,
|
||||
'Polls.created <=' => $now->subDays($days - $lead),
|
||||
'Polls.created >=' => $now->subDays($days),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Cake\ORM\Query\SelectQuery $query Query
|
||||
* @param string $key Embed key
|
||||
|
||||
Reference in new issue
Block a user