diff --git a/feca_mailshots_plugin/feca_mailshots_plugin.php b/feca_mailshots_plugin/feca_mailshots_plugin.php index 264f7ac..c4c123c 100644 --- a/feca_mailshots_plugin/feca_mailshots_plugin.php +++ b/feca_mailshots_plugin/feca_mailshots_plugin.php @@ -3,7 +3,7 @@ * Plugin Name: FECA Mailshots * Plugin URI: https://fenedge.co.uk/ * Description: FECA mailshots plugin. - * Version: 1.0.33 + * Version: 1.1.0 * Requires at least: 6.0 * Requires PHP: 7.4 * Author: FECA diff --git a/feca_mailshots_plugin/readme.txt b/feca_mailshots_plugin/readme.txt index ff16e49..ba8001a 100644 --- a/feca_mailshots_plugin/readme.txt +++ b/feca_mailshots_plugin/readme.txt @@ -3,7 +3,7 @@ Contributors: feca Requires at least: 6.0 Tested up to: 6.5 Requires PHP: 7.4 -Stable tag: 1.0.0 +Stable tag: 1.1.0 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html diff --git a/feca_mailshots_plugin/src/Admin/AdminRequestHelpers.php b/feca_mailshots_plugin/src/Admin/AdminRequestHelpers.php index db3bb59..c04fa91 100644 --- a/feca_mailshots_plugin/src/Admin/AdminRequestHelpers.php +++ b/feca_mailshots_plugin/src/Admin/AdminRequestHelpers.php @@ -35,6 +35,8 @@ trait AdminRequestHelpers . '.feca-mailshots-admin .feca-minw-240{min-width:240px;}' . '.feca-mailshots-admin .feca-control input,.feca-mailshots-admin .feca-control select,.feca-mailshots-admin .feca-control textarea{margin:0;}' . '.feca-mailshots-admin .feca-control label{white-space:nowrap;padding-left:var(--feca-space-1);font-weight:600;}' + . '.feca-mailshots-admin .feca-inline-control-group{display:flex;align-items:flex-end;gap:var(--feca-space-2);flex-wrap:wrap;padding:8px 10px;border:1px solid #dcdcde;background:#f6f7f7;border-radius:var(--feca-radius);}' + . '.feca-mailshots-admin .feca-inline-control-group .feca-control{padding:0;}' . '.feca-mailshots-admin .feca-button-row{display:flex;gap:var(--feca-space-2);align-items:center;flex-wrap:wrap;margin-top:var(--feca-space-3);margin-bottom:0;padding:0;}' . '.feca-mailshots-admin .feca-button-row .button{margin:0 !important;}' . '.feca-mailshots-admin .feca-button-danger{color:#b32d2e;border-color:#d63638;}' @@ -105,6 +107,7 @@ trait AdminRequestHelpers . '@media (max-width: 782px){' . '.feca-mailshots-admin .feca-control-row{display:block;}' . '.feca-mailshots-admin .feca-control{min-width:0;width:100%;}' + . '.feca-mailshots-admin .feca-inline-control-group{display:block;}' . '}' . ''; } diff --git a/feca_mailshots_plugin/src/Admin/MailshotTestAdminPage.php b/feca_mailshots_plugin/src/Admin/MailshotTestAdminPage.php index bcca5a6..d415051 100644 --- a/feca_mailshots_plugin/src/Admin/MailshotTestAdminPage.php +++ b/feca_mailshots_plugin/src/Admin/MailshotTestAdminPage.php @@ -17,6 +17,7 @@ final class MailshotTestAdminPage private const NONCE_ACTION = 'feca_mailshots_test'; private const DOWNLOAD_MEMORY_LIMIT_ENV = 'FECA_MAILSHOTS_DOWNLOAD_MEMORY_LIMIT'; private const DOWNLOAD_MEMORY_LIMIT_OPTION = 'feca_mailshots_download_memory_limit'; + private const DEFAULT_DOWNLOAD_MEMORY_LIMIT = '512M'; /** @var callable(): MailshotRunService */ private $runServiceFactory; @@ -54,7 +55,17 @@ final class MailshotTestAdminPage return; } - $mailshots = $this->mailshotService()->list(); + $pageErrors = []; + $memoryError = $this->maybeRaiseMemoryLimit($this->resolveDownloadMemoryLimitTarget()); + if ($memoryError !== null) { + $pageErrors[] = $memoryError; + } + try { + $mailshots = $this->mailshotService()->list(); + } catch (\Throwable $e) { + $mailshots = []; + $pageErrors[] = $this->diagnosticError('Unable to load mailshots', 'loading test page', $e); + } $selectedMailshotId = (int) ($this->wp->requestParam('mailshot_id', '0') ?? '0'); if ($selectedMailshotId <= 0 && $mailshots !== []) { $selectedMailshotId = (int) ($mailshots[0]['id'] ?? 0); @@ -62,7 +73,15 @@ final class MailshotTestAdminPage $preview = ['ok' => false, 'rows' => [], 'errors' => ['Create a mailshot before loading recipients.']]; if ($selectedMailshotId > 0) { - $preview = $this->runService()->previewRecipients($selectedMailshotId, 100); + try { + $preview = $this->runService()->previewRecipients($selectedMailshotId, 100); + } catch (\Throwable $e) { + $preview = [ + 'ok' => false, + 'rows' => [], + 'errors' => [$this->diagnosticError('Recipient preview failed', 'loading recipient sample', $e)], + ]; + } } $rows = is_array($preview['rows'] ?? null) ? $preview['rows'] : []; @@ -70,7 +89,12 @@ final class MailshotTestAdminPage if ($selectedRecipientIndex < -1) { $selectedRecipientIndex = 0; } - $defaultEmail = $this->runService()->defaultTestEmail()['default_test_email'] ?? ''; + try { + $defaultEmail = $this->runService()->defaultTestEmail()['default_test_email'] ?? ''; + } catch (\Throwable $e) { + $defaultEmail = ''; + $pageErrors[] = $this->diagnosticError('Unable to load default test email', 'loading test page', $e); + } $testEmail = (string) ($this->wp->requestParam('test_email', (string) $defaultEmail) ?? $defaultEmail); $result = $this->result(); if ((string) ($this->wp->requestParam('render_test', '0') ?? '0') === '1') { @@ -78,8 +102,12 @@ final class MailshotTestAdminPage $result = ['ok' => false, 'errors' => ['Choose a specific recipient row for Render Test.']]; } else { try { - $this->maybeRaiseMemoryLimit($this->resolveDownloadMemoryLimitTarget()); - $result = $this->runService()->renderTest($selectedMailshotId, $selectedRecipientIndex); + $memoryError = $this->maybeRaiseMemoryLimit($this->resolveDownloadMemoryLimitTarget()); + if ($memoryError !== null) { + $result = ['ok' => false, 'errors' => [$memoryError]]; + } else { + $result = $this->runService()->renderTest($selectedMailshotId, $selectedRecipientIndex); + } } catch (\Throwable $e) { $result = ['ok' => false, 'errors' => ['Render test failed: ' . $e->getMessage()]]; } @@ -93,6 +121,14 @@ final class MailshotTestAdminPage echo $this->renderAdminUiStyles(); echo '
Render with a selected recipient context, then optionally send one test email.
'; + if ($pageErrors !== []) { + echo ''; + } + if ($result !== null) { $ok = !empty($result['ok']); $bannerClass = $ok ? 'feca-banner-success' : 'feca-banner-error'; @@ -167,13 +203,15 @@ final class MailshotTestAdminPage echo ''; } echo ''; + echo '