From: Johan Cwiklinski Date: Tue, 20 Oct 2020 06:17:13 +0000 (+0200) Subject: Mailing fixes; closes #1497 X-Git-Tag: 0.9.4.2~15 X-Git-Url: https://git.agnieray.net/?a=commitdiff_plain;h=597ceaf7a06ce17182809ab83493961222c163e1;p=galette.git Mailing fixes; closes #1497 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 --- diff --git a/galette/lib/Galette/Controllers/Crud/MailingsController.php b/galette/lib/Galette/Controllers/Crud/MailingsController.php index 1bf1e0187..27a4dad87 100644 --- a/galette/lib/Galette/Controllers/Crud/MailingsController.php +++ b/galette/lib/Galette/Controllers/Crud/MailingsController.php @@ -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 diff --git a/galette/lib/Galette/Core/Mailing.php b/galette/lib/Galette/Core/Mailing.php index 84278cfba..6814a3a01 100644 --- a/galette/lib/Galette/Core/Mailing.php +++ b/galette/lib/Galette/Core/Mailing.php @@ -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 - * @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) { diff --git a/galette/lib/Galette/Core/MailingHistory.php b/galette/lib/Galette/Core/MailingHistory.php index 65941739e..fa5d00106 100644 --- a/galette/lib/Galette/Core/MailingHistory.php +++ b/galette/lib/Galette/Core/MailingHistory.php @@ -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();