3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 namespace Civi\Api4\Action\MailSettings
;
14 use Civi\Api4\Generic\BasicBatchAction
;
16 class TestConnection
extends BasicBatchAction
{
18 public function __construct($entityName, $actionName) {
19 parent
::__construct($entityName, $actionName, ['id', 'name']);
26 protected function doTask($item) {
28 $mailStore = \CRM_Mailing_MailStore
::getStore($item['name']);
30 catch (\Throwable
$t) {
31 \Civi
::log()->warning('MailSettings: Failed to establish test connection', [
36 'title' => ts("Failed to connect"),
37 'details' => $t->getMessage() . "\n" . ts('(See log for more details.)'),
42 if (empty($mailStore)) {
44 'title' => ts("Failed to connect"),
45 'details' => ts('The mail service was not instantiated.'),
52 $msgs = $mailStore->fetchNext($limitTestCount);
54 catch (\Throwable
$t) {
55 \Civi
::log()->warning('MailSettings: Failed to read test message', [
59 'title' => ts('Failed to read test message'),
60 'details' => $t->getMessage() . "\n" . ts('(See log for more details.)'),
65 if (count($msgs) === 0) {
67 'title' => ts('Connection succeeded.'),
68 'details' => ts('No new messages found.'),
74 'title' => ts('Connection succeeded.'),
75 'details' => ts('Found at least %1 new messages.', [