fix: [mailinglist] Edition was not possible in some cases
parent
c0d25578a0
commit
2ba3e3ce00
|
@ -91,32 +91,35 @@ class MailingListsController extends AppController
|
||||||
->contain('MetaFields')
|
->contain('MetaFields')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
$filteringActive = !empty($queryParams['quickFilter']);
|
||||||
$matchingMetaFieldParentIDs = [];
|
$matchingMetaFieldParentIDs = [];
|
||||||
// Collect individuals having a matching meta_field
|
if ($filteringActive) {
|
||||||
foreach ($mailingList->meta_fields as $metaField) {
|
// Collect individuals having a matching meta_field for the requested search value
|
||||||
if (
|
foreach ($mailingList->meta_fields as $metaField) {
|
||||||
empty($queryParams['quickFilter']) ||
|
if (
|
||||||
(
|
empty($queryParams['quickFilter']) ||
|
||||||
str_contains($metaField->field, 'email') &&
|
(
|
||||||
str_contains($metaField->value, $queryParams['quickFilter'])
|
str_contains($metaField->field, 'email') &&
|
||||||
)
|
str_contains($metaField->value, $queryParams['quickFilter'])
|
||||||
) {
|
)
|
||||||
$matchingMetaFieldParentIDs[$metaField->parent_id] = true;
|
) {
|
||||||
|
$matchingMetaFieldParentIDs[$metaField->parent_id] = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$matchingMetaFieldParentIDs = array_keys($matchingMetaFieldParentIDs);
|
$matchingMetaFieldParentIDs = array_keys($matchingMetaFieldParentIDs);
|
||||||
$mailingList = $this->MailingLists->loadInto($mailingList, [
|
$mailingList = $this->MailingLists->loadInto($mailingList, [
|
||||||
'Individuals' => function (Query $q) use ($queryParams, $quickFilter, $matchingMetaFieldParentIDs) {
|
'Individuals' => function (Query $q) use ($queryParams, $quickFilter, $filteringActive, $matchingMetaFieldParentIDs) {
|
||||||
$conditions = [];
|
$conditions = [];
|
||||||
if (!empty($queryParams)) {
|
if (!empty($queryParams)) {
|
||||||
$conditions = $this->CRUD->genQuickFilterConditions($queryParams, $quickFilter);
|
$conditions = $this->CRUD->genQuickFilterConditions($queryParams, $quickFilter);
|
||||||
}
|
}
|
||||||
if (!empty($matchingMetaFieldParentIDs)) {
|
if ($filteringActive && !empty($matchingMetaFieldParentIDs)) {
|
||||||
$conditions[] = function (QueryExpression $exp) use ($matchingMetaFieldParentIDs) {
|
$conditions[] = function (QueryExpression $exp) use ($matchingMetaFieldParentIDs) {
|
||||||
return $exp->in('Individuals.id', $matchingMetaFieldParentIDs);
|
return $exp->in('Individuals.id', $matchingMetaFieldParentIDs);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (!empty($queryParams['quickFilter'])) {
|
if ($filteringActive && !empty($queryParams['quickFilter'])) {
|
||||||
$conditions[] = [
|
$conditions[] = [
|
||||||
'MailingListsIndividuals.include_primary_email' => true,
|
'MailingListsIndividuals.include_primary_email' => true,
|
||||||
'Individuals.email LIKE' => "%{$queryParams['quickFilter']}%"
|
'Individuals.email LIKE' => "%{$queryParams['quickFilter']}%"
|
||||||
|
@ -247,10 +250,13 @@ class MailingListsController extends AppController
|
||||||
$success = false;
|
$success = false;
|
||||||
if (!is_null($individual_id)) {
|
if (!is_null($individual_id)) {
|
||||||
$individualToRemove = $this->MailingLists->Individuals->get($individual_id);
|
$individualToRemove = $this->MailingLists->Individuals->get($individual_id);
|
||||||
$metaFieldsToRemove = $this->MailingLists->MetaFields->find()->where([
|
$metaFieldsIDsToRemove = Hash::extract($mailingList, 'meta_fields.{n}.id');
|
||||||
'id IN' => Hash::extract($mailingList, 'meta_fields.{n}.id'),
|
if (!empty($metaFieldsIDsToRemove)) {
|
||||||
'parent_id' => $individual_id,
|
$metaFieldsToRemove = $this->MailingLists->MetaFields->find()->where([
|
||||||
])->all()->toArray();
|
'id IN' => $metaFieldsIDsToRemove,
|
||||||
|
'parent_id' => $individual_id,
|
||||||
|
])->all()->toArray();
|
||||||
|
}
|
||||||
$success = (bool)$this->MailingLists->Individuals->unlink($mailingList, [$individualToRemove]);
|
$success = (bool)$this->MailingLists->Individuals->unlink($mailingList, [$individualToRemove]);
|
||||||
if ($success && !empty($metaFieldsToRemove)) {
|
if ($success && !empty($metaFieldsToRemove)) {
|
||||||
$success = (bool)$this->MailingLists->MetaFields->unlink($mailingList, $metaFieldsToRemove);
|
$success = (bool)$this->MailingLists->MetaFields->unlink($mailingList, $metaFieldsToRemove);
|
||||||
|
@ -273,11 +279,12 @@ class MailingListsController extends AppController
|
||||||
$individualsToRemove = $this->MailingLists->Individuals->find()->where([
|
$individualsToRemove = $this->MailingLists->Individuals->find()->where([
|
||||||
'id IN' => array_map('intval', $params['ids'])
|
'id IN' => array_map('intval', $params['ids'])
|
||||||
])->all()->toArray();
|
])->all()->toArray();
|
||||||
$metaFieldsToRemove = $this->MailingLists->MetaFields->find()->where([
|
$metaFieldsIDsToRemove = Hash::extract($mailingList, 'meta_fields.{n}.id');
|
||||||
'id IN' => Hash::extract($mailingList, 'meta_fields.{n}.id'),
|
if (!empty($metaFieldsIDsToRemove)) {
|
||||||
'parent_id IN' => Hash::extract($mailingList, 'meta_fields.{n}.id')
|
$metaFieldsToRemove = $this->MailingLists->MetaFields->find()->where([
|
||||||
])->all()->toArray();
|
'id IN' => $metaFieldsIDsToRemove,
|
||||||
dd($metaFieldsToRemove);
|
])->all()->toArray();
|
||||||
|
}
|
||||||
$unlinkSuccesses = 0;
|
$unlinkSuccesses = 0;
|
||||||
foreach ($individualsToRemove as $individualToRemove) {
|
foreach ($individualsToRemove as $individualToRemove) {
|
||||||
$success = (bool)$this->MailingLists->Individuals->unlink($mailingList, [$individualToRemove]);
|
$success = (bool)$this->MailingLists->Individuals->unlink($mailingList, [$individualToRemove]);
|
||||||
|
|
Loading…
Reference in New Issue