Browse code

Remove the random temporary prefix from the filename of the email attachment

Benjamin Roth authored on18/03/2025 14:31:25
Showing1 changed files
... ...
@@ -166,7 +166,8 @@ class ShopwareExportNewsletterJob extends AbstractController
166 166
             ];
167 167
         }
168 168
 
169
-        $filename = $srcDir . '/' . (!empty($email) && Validator::isEmail($email) ? substr(md5(uniqid()), 0, 10) . '_' : '') . 'recipients_' . date("Ymd", $intStart) . '_' . date("Ymd", $intEnd) . '.csv';
169
+        $strRandomPrefix = (!empty($email) && Validator::isEmail($email) ? substr(md5(uniqid()), 0, 10) . '_' : '');
170
+        $filename = $srcDir . '/' . $strRandomPrefix . 'recipients_' . date("Ymd", $intStart) . '_' . date("Ymd", $intEnd) . '.csv';
170 171
         \file_put_contents($filename, $this->serializer->encode($arrCSV, 'csv', $this->csvContext));
171 172
 
172 173
         // If email is provided, send the CSV file
... ...
@@ -180,7 +181,7 @@ class ShopwareExportNewsletterJob extends AbstractController
180 181
                 ->to($email)
181 182
                 ->subject('Newsletter Export')
182 183
                 ->text('Attached is the exported list of newsletter recipients.')
183
-                ->attachFromPath($filename, basename($filename), 'text/csv');
184
+                ->attachFromPath($filename, str_replace($strRandomPrefix,'',basename($filename)), 'text/csv');
184 185
 
185 186
             try
186 187
             {