add test batches

This commit is contained in:
root
2026-06-08 23:45:55 -04:00
parent c792b8be05
commit 8d4d610b82
1480 changed files with 22587 additions and 10762 deletions
@@ -8,7 +8,9 @@ use Illuminate\Support\Facades\Log;
class WhatsappInviteEmailService
{
public function __construct(private EmailService $emailService) {}
public function __construct(private EmailService $emailService)
{
}
public function send(array $payload): array
{
@@ -16,13 +18,12 @@ class WhatsappInviteEmailService
$cc = array_values(array_unique(array_filter((array) ($payload['cc_emails'] ?? []))));
$cc = array_values(array_diff($cc, $to));
if (empty($to) && ! empty($cc)) {
if (empty($to) && !empty($cc)) {
$to = $cc;
$cc = [];
}
if (empty($to)) {
Log::warning('WhatsappInvite: no recipients after normalization.');
return ['ok' => false, 'message' => 'No recipients provided.'];
}
@@ -33,7 +34,6 @@ class WhatsappInviteEmailService
$items = $this->buildItems($sections, $links);
if (empty($items)) {
Log::warning('WhatsappInvite: no invite items built.');
return ['ok' => false, 'message' => 'No invite links found.'];
}
@@ -77,12 +77,12 @@ class WhatsappInviteEmailService
foreach ($sections as $section) {
$sid = isset($section['class_section_id']) ? (int) $section['class_section_id'] : 0;
$name = trim((string) ($section['class_section_name'] ?? ($sid ? ('Section '.$sid) : 'Class')));
$name = trim((string) ($section['class_section_name'] ?? ($sid ? ('Section ' . $sid) : 'Class')));
$url = trim((string) ($section['invite_link'] ?? ''));
if ($url === '') {
continue;
}
$key = $sid.'|'.$url;
$key = $sid . '|' . $url;
if (isset($seen[$key])) {
continue;
}
@@ -96,20 +96,20 @@ class WhatsappInviteEmailService
];
}
if (empty($items) && ! empty($links)) {
if (empty($items) && !empty($links)) {
foreach ($links as $i => $url) {
$url = trim((string) $url);
if ($url === '') {
continue;
}
$key = '0|'.$url;
$key = '0|' . $url;
if (isset($seen[$key])) {
continue;
}
$seen[$key] = true;
$items[] = [
'class_section_id' => 0,
'class_section_name' => 'Class Link '.($i + 1),
'class_section_name' => 'Class Link ' . ($i + 1),
'invite_link' => $url,
'qr_src' => $this->generateQrImage($url),
];
@@ -126,23 +126,21 @@ class WhatsappInviteEmailService
}
$dir = storage_path('app/qrcodes');
if (! is_dir($dir)) {
if (! @mkdir($dir, 0775, true) && ! is_dir($dir)) {
if (!is_dir($dir)) {
if (!@mkdir($dir, 0775, true) && !is_dir($dir)) {
Log::error('QR: cannot create dir', ['dir' => $dir]);
return $this->qrFallback($inviteLink);
}
}
if (! is_writable($dir)) {
if (!is_writable($dir)) {
Log::error('QR: dir not writable', ['dir' => $dir]);
return $this->qrFallback($inviteLink);
}
$filename = 'wa_'.md5($inviteLink).'.png';
$path = $dir.DIRECTORY_SEPARATOR.$filename;
$filename = 'wa_' . md5($inviteLink) . '.png';
$path = $dir . DIRECTORY_SEPARATOR . $filename;
if (! is_file($path)) {
if (!is_file($path)) {
$v5BuilderClass = '\\Endroid\\QrCode\\Builder\\Builder';
$v5WriterClass = '\\Endroid\\QrCode\\Writer\\PngWriter';
$v5Encoding = '\\Endroid\\QrCode\\Encoding\\Encoding';
@@ -159,7 +157,7 @@ class WhatsappInviteEmailService
if (class_exists($v5BuilderClass) && class_exists($v5WriterClass)) {
try {
$builder = $v5BuilderClass::create()
->writer(new $v5WriterClass)
->writer(new $v5WriterClass())
->data($inviteLink);
if (class_exists($v5Encoding)) {
$builder->encoding(new $v5Encoding('UTF-8'));
@@ -167,11 +165,11 @@ class WhatsappInviteEmailService
$result = $builder->size(500)->margin(2)->build();
$result->saveToFile($path);
} catch (\Throwable $e) {
$lastErr = 'Endroid v5: '.$e->getMessage();
$lastErr = 'Endroid v5: ' . $e->getMessage();
}
}
if (! is_file($path) && class_exists($writerClass)) {
if (!is_file($path) && class_exists($writerClass)) {
try {
if (class_exists($qrClass) && method_exists($qrClass, 'create')) {
$qr = $qrClass::create($inviteLink);
@@ -185,7 +183,7 @@ class WhatsappInviteEmailService
if (method_exists($qr, 'setMargin')) {
$qr->setMargin(2);
}
$writer = new $writerClass;
$writer = new $writerClass();
$result = $writer->write($qr);
if (method_exists($result, 'saveToFile')) {
$result->saveToFile($path);
@@ -195,21 +193,21 @@ class WhatsappInviteEmailService
}
}
} catch (\Throwable $e) {
$lastErr = 'Endroid v3/v4: '.$e->getMessage();
$lastErr = 'Endroid v3/v4: ' . $e->getMessage();
}
}
if (! is_file($path) && class_exists($chlQRCode) && class_exists($chlQROptions)) {
if (!is_file($path) && class_exists($chlQRCode) && class_exists($chlQROptions)) {
try {
$optsArr = [
'version' => 5,
'outputType' => constant($chlQRCode.'::OUTPUT_IMAGE_PNG'),
'outputType' => constant($chlQRCode . '::OUTPUT_IMAGE_PNG'),
'scale' => 6,
'imageBase64' => false,
'quietzoneSize' => 2,
];
if (class_exists($chlQRMatrix) && defined($chlQRMatrix.'::ECC_H')) {
$optsArr['eccLevel'] = constant($chlQRMatrix.'::ECC_H');
if (class_exists($chlQRMatrix) && defined($chlQRMatrix . '::ECC_H')) {
$optsArr['eccLevel'] = constant($chlQRMatrix . '::ECC_H');
}
$opts = new $chlQROptions($optsArr);
@@ -217,11 +215,11 @@ class WhatsappInviteEmailService
$png = $qrcode->render($inviteLink);
file_put_contents($path, $png);
} catch (\Throwable $e) {
$lastErr = 'chillerlan: '.$e->getMessage();
$lastErr = 'chillerlan: ' . $e->getMessage();
}
}
if (! is_file($path) && $lastErr) {
if (!is_file($path) && $lastErr) {
Log::error('QR generation failed', ['error' => $lastErr]);
}
}
@@ -229,7 +227,7 @@ class WhatsappInviteEmailService
if (is_file($path)) {
$data = @file_get_contents($path);
if ($data !== false) {
return 'data:image/png;base64,'.base64_encode($data);
return 'data:image/png;base64,' . base64_encode($data);
}
}
@@ -239,7 +237,6 @@ class WhatsappInviteEmailService
private function qrFallback(string $inviteLink): string
{
$link = rawurlencode($inviteLink);
return 'https://api.qrserver.com/v1/create-qr-code/?size=260x260&qzone=2&data='.$link;
return 'https://api.qrserver.com/v1/create-qr-code/?size=260x260&qzone=2&data=' . $link;
}
}