[*] исправил пайплайн юнит тестов
[+] добавил миграцию под историю почтовых отправлений
This commit is contained in:
1 parent
65d7f1b4b9
commit
6dbec7bb37
3 files changed
+56
-2
No files matched your search
@@ -22,8 +22,10 @@
|
||||
namespace Core\Helpers;
|
||||
|
||||
use Core\CoreException;
|
||||
use Core\Models\DB;
|
||||
use Core\Models\User;
|
||||
use Core\Helpers\Log;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Класс для отправки E-mail
|
||||
@@ -74,6 +76,9 @@
|
||||
*/
|
||||
private $user = null;
|
||||
|
||||
/** @var string TABLE Таблица с логами отправки */
|
||||
private const TABLE = DB_TABLE_PREFIX . 'mail_history';
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
*/
|
||||
@@ -248,8 +253,29 @@
|
||||
$message[] = '--' . $boundary . '--';
|
||||
$res = [];
|
||||
|
||||
/** @var DB $DB */
|
||||
$DB = DB::getInstance();
|
||||
|
||||
foreach ($array_to as $to) {
|
||||
$res[] = mb_send_mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));
|
||||
$result = mb_send_mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));
|
||||
$res[] = $result;
|
||||
|
||||
try {
|
||||
$DB->addItem(self::TABLE, [
|
||||
'to_mail' => $this->toEmail,
|
||||
'to_name' => $this->toName,
|
||||
'from_mail' => $this->fromEmail,
|
||||
'from_name' => $this->fromName,
|
||||
'subject' => $this->subject,
|
||||
'send' => $result ? CODE_VALUE_Y : CODE_VALUE_N,
|
||||
'template' => $this->templateName,
|
||||
'template_vars' => json_encode($this->templateVars, JSON_UNESCAPED_UNICODE),
|
||||
'body' => $this->body,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
// TODO Просто глушим, однако наверное надо залогировать в файл...
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Log::logToFile('Отправлено письмо', 'Mail.log', ['to' => $this->toEmail, 'subject' => $subject, 'body' => implode(' ', $message)]);
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class MailHistory extends AbstractMigration
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
$this->table = 'd_mail_history';
|
||||
}
|
||||
|
||||
public function change(): void
|
||||
{
|
||||
$table = $this->table($this->table);
|
||||
$table->addColumn('to_mail', 'string', ['limit' => 255, 'default' => null])
|
||||
->addColumn('to_name', 'string', ['limit' => 255, 'null' => true, 'default' => null])
|
||||
->addColumn('from_mail', 'string', ['limit' => 255, 'default' => null])
|
||||
->addColumn('from_name', 'string', ['limit' => 255, 'null' => true, 'default' => null])
|
||||
->addColumn('subject', 'string', ['limit' => 255, 'default' => null])
|
||||
->addColumn('template', 'string', ['limit' => 255, 'null' => true, 'default' => null])
|
||||
->addColumn('template_vars', 'text', ['null' => true, 'default' => null])
|
||||
->addColumn('body', 'text', ['null' => true, 'default' => null])
|
||||
->addColumn('send', 'enum', ['values' => ['Y', 'N'], 'default' => 'N', 'null' => false])
|
||||
->addColumn('date_created', 'datetime', ['default' => 'CURRENT_TIMESTAMP'])
|
||||
->create();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
{
|
||||
public function testGetAllUserData(): void
|
||||
{
|
||||
$this->assertTrue(0, 'Сообщение об ошибке');
|
||||
$this->assertTrue(true, 'Сообщение об ошибке');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user