]> git.agnieray.net Git - galette.git/commitdiff
Mailing fixes; closes #1497
authorJohan Cwiklinski <johan@x-tnd.be>
Tue, 20 Oct 2020 06:17:13 +0000 (08:17 +0200)
committerJohan Cwiklinski <johan@x-tnd.be>
Sun, 25 Oct 2020 07:48:11 +0000 (08:48 +0100)
Fix mailing temporary path
Do not rely on Password::makeRandomPassword for paths
Fix attachments preview when using a template mailing
Fix some other attachments issues
Do not redirecto on mailing edition page
Ensure redirection is unset when done
Fix possible undefined index

galette/lib/Galette/Controllers/Crud/MailingsController.php
galette/lib/Galette/Core/Mailing.php
galette/lib/Galette/Core/MailingHistory.php

index 1bf1e01870b8707ccc52fe9a456bdfbece90218a..27a4dad876eda53a99b0eab6b9cefa04f998ffdf 100644 (file)
@@ -89,6 +89,7 @@ class MailingsController extends CrudController
                 $m->removeAttachments(true);
             }
             $this->session->mailing = null;
+            $this->session->redirect_mailing = null;
         }
 
         $params = array();
@@ -238,6 +239,7 @@ class MailingsController extends CrudController
                 $m->removeAttachments(true);
             }
             $this->session->mailing = null;
+            $this->session->redirect_mailing = null;
             if (isset($this->session->filter_mailing)) {
                 $filters = $this->session->filter_mailing;
                 $filters->selected = [];
@@ -311,7 +313,7 @@ class MailingsController extends CrudController
                     $mailing->message = $post['mailing_corps'];
                 }
 
-                switch ($post['sender']) {
+                switch ($post['sender'] ?? false) {
                     case GaletteMail::SENDER_CURRENT:
                         $member = new Adherent($this->zdb, (int)$this->login->id, false);
                         $mailing->setSender(
@@ -402,6 +404,7 @@ class MailingsController extends CrudController
                     $filters->selected = null;
                     $this->session->filter_members = $filters;
                     $this->session->mailing = null;
+                    $this->session->redirect_mailing = null;
                     $success_detected[] = _T("Mailing has been successfully sent!");
                     $goto = $redirect_url;
                 }
@@ -427,6 +430,8 @@ class MailingsController extends CrudController
                 if ($histo->storeMailing() !== false) {
                     $success_detected[] = _T("Mailing has been successfully saved.");
                     $this->session->mailing = null;
+                    $this->session->redirect_mailing = null;
+                    $goto = $this->router->pathFor('mailings');
                 }
             }
         }
@@ -736,7 +741,7 @@ class MailingsController extends CrudController
             $mailing->subject = $post['subject'];
             $mailing->message = $post['body'];
             $mailing->html = ($post['html'] === 'true');
-            $attachments = (isset($post['attachments']) ? $post['attachments'] : []);
+            $attachments = $mailing->attachments;
         }
 
         // display page
index 84278cfbae5799788a85cf29acbdbcf96f7181fd..6814a3a0154323c6c3786a38964fefdf2077aa78 100644 (file)
@@ -7,7 +7,7 @@
  *
  * PHP version 5
  *
- * Copyright © 2009-2014 The Galette Team
+ * Copyright © 2009-2020 The Galette Team
  *
  * This file is part of Galette (http://galette.tuxfamily.org).
  *
@@ -28,7 +28,7 @@
  * @package   Galette
  *
  * @author    Johan Cwiklinski <johan@x-tnd.be>
- * @copyright 2009-2014 The Galette Team
+ * @copyright 2009-2020 The Galette Team
  * @license   http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
  * @link      http://galette.tuxfamily.org
  * @since     Available since 0.7dev - 2009-03-07
@@ -104,10 +104,17 @@ class Mailing extends GaletteMail
      */
     private function generateNewId(): string
     {
-        global $zdb;
+        $id = '';
+        $chars = 'abcdefghjkmnpqrstuvwxyz0123456789';
+        $i = 0;
+        $size = 30;
+        while ($i <= $size - 1) {
+            $num = mt_rand(0, strlen($chars) - 1)  % strlen($chars);
+            $id .= substr($chars, $num, 1);
+            $i++;
+        }
 
-        $pass = new Password($zdb);
-        $this->id = $pass->makeRandomPassword(30);
+        $this->id = $id;
         $this->generateTmpPath($this->id);
         return $this->id;
     }
@@ -122,10 +129,7 @@ class Mailing extends GaletteMail
     private function generateTmpPath($id = null)
     {
         if ($id === null) {
-            global $zdb;
-
-            $pass = new Password($zdb);
-            $id = $pass->makeRandomPassword(30);
+            $id = $this->generateNewId();
         }
         $this->tmp_path = GALETTE_ATTACHMENTS_PATH . '/' . $id;
     }
@@ -339,10 +343,10 @@ class Mailing extends GaletteMail
         ) {
             foreach ($this->attachments as &$attachment) {
                 $old_path = $attachment->getDestDir() . $attachment->getFileName();
-                $new_path = GALETTE_ATTACHMENTS_PATH . $this->id . '/' .
+                $new_path = GALETTE_ATTACHMENTS_PATH . $id . '/' .
                     $attachment->getFileName();
-                if (!file_exists(GALETTE_ATTACHMENTS_PATH . $this->id)) {
-                    mkdir(GALETTE_ATTACHMENTS_PATH . $this->id);
+                if (!file_exists(GALETTE_ATTACHMENTS_PATH . $id)) {
+                    mkdir(GALETTE_ATTACHMENTS_PATH . $id);
                 }
                 $moved = rename($old_path, $new_path);
                 if ($moved) {
index 65941739e164ad714f3a1277541b3d7e352b02f5..fa5d0010695841ad8480a488ecd8a398d915d624 100644 (file)
@@ -396,7 +396,7 @@ class MailingHistory extends History
             } else {
                 if ($this->mailing->tmp_path !== false) {
                     //attachments are still in a temporary path, move them
-                    $this->mailing->moveAttachments($this->id);
+                    $this->mailing->moveAttachments($this->id ?? $this->mailing->history_id);
                 }
                 //existing stored mailing. Just update row.
                 $this->update();