]> _ Git - psq.git/commitdiff
batch email better tags + unbuscribe
authorLouis Jeckel <louis.jeckel@outlook.com>
Thu, 15 Oct 2020 11:21:10 +0000 (13:21 +0200)
committerLouis Jeckel <louis.jeckel@outlook.com>
Thu, 15 Oct 2020 11:21:10 +0000 (13:21 +0200)
app/Events/DispatchMailgunEvent.php
app/Http/Controllers/Admin/PublishController.php
app/Jobs/ProcessEmailBatch.php
app/Mail/BatchMail.php

index 7242e7a407e8f87e7aab222ea321c0fe14222284..3ef943155625f0650a20afcd9484e9f2d8056b4c 100644 (file)
@@ -73,8 +73,11 @@ class DispatchMailgunEvent implements ShouldBroadcast
         $event->touch();
         $this->data = $event;
 
+        /**
+         * @todo track unsubscribes
+         */
         if($event->event === 'unsubscribed') {
-            $event->user->unsubscribe();
+//            $event->user->unsubscribe();
         }
 
 
index 5eb5bd807667483024161630131978b17e30c1a7..76788ffcd2ec8d5aaabd33f3ab468719aa7ee157 100644 (file)
@@ -41,7 +41,10 @@ class PublishController extends Controller
         $recipientGroup = Arr::get($data, 'recipient_group');
 
         $batch->subject = Arr::get($data, 'email.subject');
-        $batch->content = ['body' => Arr::get($data, 'email.content')];
+        $batch->content = [
+            'body' => Arr::get($data, 'email.content'),
+            'link' => Arr::get($data, 'email.link')
+        ];
         $batch->file_id = Arr::get($data, 'file.id');
         $batch->sent_to = [];
 
index 54c2c99d3028c2f62a70308538111b5296fedc49..3580bb50f4e6631d4c238d0eb2cb9af0ebf63d21 100644 (file)
@@ -103,7 +103,7 @@ class ProcessEmailBatch implements ShouldQueue
                 $this->batch->content['body'],
                 $this->batch->subject,
                 $this->type,
-                null,
+                $this->batch->content['link'] ?? null,
                 optional($this->batch->file)->coverUrl
             ))->render();
 
@@ -115,7 +115,7 @@ class ProcessEmailBatch implements ShouldQueue
                 'subject' => $this->batch->subject,
                 'recipient-variables' => $variables,
                 'html' => $view,
-                'o:tag' => [$this->batch->getTag(), config('app.env').'_batch'],
+                'o:tag' => [$this->batch->getTag(), config('app.env').'_batch_'.BatchMail::getView($this->type)],
                 'o:testmode' => config('mail.mailgun.test_mode', 'yes'),
             ];
 
index 69a05fe9acc66c48baa6fe400e688619167defc2..65c2c2f73bb361e0b451eeaed4a493c852644db4 100644 (file)
@@ -26,7 +26,7 @@ class BatchMail extends Mailable
 
     public const MAIL_TYPE_NEWSLETTER = 2;
 
-    protected array $viewMap = [
+    public const VIEW_MAP = [
         self::MAIL_TYPE_PDF_FILE => 'batch-pdf',
         self::MAIL_TYPE_NEWSLETTER => 'newsletter'
     ];
@@ -54,7 +54,7 @@ class BatchMail extends Mailable
         $this->image = $image;
 
 
-        $this->emailView = Arr::get($this->viewMap, $type ?? 0);
+        $this->emailView = self::getView($type);
 
         $this->content = $this->emailView === 'batch-pdf' ?
             (Html2Markdown::convert($content)) :
@@ -65,6 +65,15 @@ class BatchMail extends Mailable
         }
     }
 
+    /**
+     * @param $id
+     * @return string
+     */
+    public static function getView($id)
+    {
+        return Arr::get(self::VIEW_MAP, $id ?? 0);
+    }
+
     /**
      * Build the message.
      *