From 24e5a94662213e7d8e92b28aa5dd324b5d479874 Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Fri, 12 Nov 2021 13:49:54 +0100 Subject: [PATCH] chg: [mailinglist:addIndividual] Removed possiblity to edit individual already in the list This can be confusing and require special handling when saving joinData --- src/Controller/MailingListsController.php | 28 ++--------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/src/Controller/MailingListsController.php b/src/Controller/MailingListsController.php index ae3fc14..0282287 100644 --- a/src/Controller/MailingListsController.php +++ b/src/Controller/MailingListsController.php @@ -2,6 +2,7 @@ namespace App\Controller; use App\Controller\AppController; +use App\Model\Entity\Individual; use Cake\Utility\Inflector; use Cake\Utility\Hash; use Cake\Utility\Text; @@ -173,16 +174,13 @@ class MailingListsController extends AppController 'id IN' => $memberIDs ])->all()->toArray(); $memberToLink = []; - $memberToUpdate = []; foreach ($members as $i => $member) { $includePrimary = in_array('primary', $chosen_emails[$member->id]); $chosen_emails[$member->id] = array_filter($chosen_emails[$member->id], function($entry) { return $entry != 'primary'; }); $members[$i]->_joinData = new Entity(['include_primary_email' => $includePrimary]); - if (in_array($member->id, $linkedIndividualsIDs)) { // individual already in the list - // $memberToUpdate[] = $members[$i]; - } else { // new individual to add to the list + if (!in_array($member->id, $linkedIndividualsIDs)) { // individual are not already in the list $memberToLink[] = $members[$i]; } } @@ -198,28 +196,6 @@ class MailingListsController extends AppController } } - // update existing individuals - if (!empty($memberToUpdate)) { - $memberToUpdateIDs = Hash::extract($memberToUpdate, '{n}.id'); - $metaFieldsToRemove = array_filter($mailingList->meta_fields, function($metaField) use ($memberToUpdateIDs) { - return in_array($metaField->parent_id, $memberToUpdateIDs); - }); - - // Trying to update `include_primary`... - // $success = (bool)$this->MailingLists->Individuals->unlink($mailingList, $memberToUpdate, ['atomic' => false]); - // $success = $success && (bool)$this->MailingLists->Individuals->link($mailingList, $memberToUpdate); - - // Remove and add relevant meta fields - // $success = (bool)$this->MailingLists->MetaFields->unlink($mailingList, $metaFieldsToRemove, ['atomic' => false]); - // if ($success && !empty($chosen_emails[$member->id])) { // Include any remaining emails from the metaFields - // $emailsFromMetaFields = $this->MailingLists->MetaFields->find()->where([ - // 'id IN' => $chosen_emails[$member->id] - // ])->all()->toArray(); - // $success = (bool)$this->MailingLists->MetaFields->link($mailingList, $emailsFromMetaFields); - // } - } - - if ($success) { $message = __n('{0} individual added to the mailing list.', '{0} Individuals added to the mailing list.', count($members), count($members)); $mailingList = $this->MailingLists->get($mailingList->id);