Share repeated controller and service code
- AppController: joinUrl(), adminUrlFor(), setPollInterval() and protect() instead of copies in Admin-, Home-, Participate- and EmbedController. - PollMailer::sendSafely() replaces two try/catch blocks around mail sending. - Slide::optionIds() replaces five identical array_map() calls. - PollStateService: one pollPayload() for presenter and embed; the vote action passes the already loaded slide instead of loading it again. - ResultsService::forSlide() takes the answer/comment limit and the rating flag, so ReportService no longer queries answers, comments and the scale distribution twice and the export loads the slides only once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ad537b9b34
commit
3e44ded107
14 files changed
+189
-137
No files matched your search
@@ -4,13 +4,36 @@ declare(strict_types=1);
|
||||
namespace App\Mailer;
|
||||
|
||||
use App\Model\Entity\Poll;
|
||||
use Cake\Log\Log;
|
||||
use Cake\Mailer\Mailer;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Mails sent by PlenarIO. Templates: templates/email/{html,text}/.
|
||||
*/
|
||||
class PollMailer extends Mailer
|
||||
{
|
||||
/**
|
||||
* Sends a mail like send(), but logs transport errors instead of throwing them,
|
||||
* so the user gets a friendly hint and the action itself still succeeds.
|
||||
*
|
||||
* @param string $action Mailer action, e.g. "adminLink"
|
||||
* @param array<mixed> $args Arguments of the action
|
||||
* @return bool Whether the mail was handed to the transport
|
||||
*/
|
||||
public function sendSafely(string $action, array $args): bool
|
||||
{
|
||||
try {
|
||||
$this->send($action, $args);
|
||||
|
||||
return true;
|
||||
} catch (Throwable $e) {
|
||||
Log::error(sprintf('Mail delivery failed (%s): %s', $action, $e->getMessage()));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mail with the secret admin link after a poll was created.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user