Skip to content

Commit

Permalink
Merge pull request #31888 from colemanw/domainMatch
Browse files Browse the repository at this point in the history
ManagedEntity - Ensure multisite domain entities match on domain_id
  • Loading branch information
monishdeb authored Jan 31, 2025
2 parents 0de644a + 1c6d104 commit a207a31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Civi/Managed/MultisiteManaged.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ protected function makeCopies(array $managedRecord): array {
if ($index) {
$copy['name'] .= '_' . $domainId;
}
// Add concrete domain_id to the values
$copy['params']['values']['domain_id'] = $domainId;
// If matching is enabled, ensure we also match on domain_id
if (isset($copy['params']['match']) && !in_array('domain_id', $copy['params']['match'])) {
$copy['params']['match'][] = 'domain_id';
}
$copies[] = $copy;
}
return $copies;
Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/api/v4/Entity/ManagedEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,14 @@ public function testMultiDomainNavigation(): void {
'weight' => 50,
'domain_id' => 'current_domain',
],
'match' => ['name'],
],
];
$managedRecords = [];
\CRM_Utils_Hook::managed($managedRecords, ['unit.test.fake.ext']);
$result = \CRM_Utils_Array::findAll($managedRecords, ['module' => 'unit.test.fake.ext', 'name' => 'Navigation_Test_Domains']);
$this->assertCount(1, $result);
$this->assertSame(['name'], $result[0]['params']['match']);

// Enable multisite with multiple domains
\Civi::settings()->set('is_enabled', TRUE);
Expand All @@ -697,11 +699,13 @@ public function testMultiDomainNavigation(): void {
// Base entity should not have been renamed
$result = \CRM_Utils_Array::findAll($managedRecords, ['module' => 'unit.test.fake.ext', 'name' => 'Navigation_Test_Domains']);
$this->assertCount(1, $result);
$this->assertSame(['name', 'domain_id'], $result[0]['params']['match']);

// New item should have been inserted for extra domains
foreach (array_slice($allDomains->column('id'), 1) as $domain) {
$result = \CRM_Utils_Array::findAll($managedRecords, ['module' => 'unit.test.fake.ext', 'name' => 'Navigation_Test_Domains_' . $domain]);
$this->assertCount(1, $result);
$this->assertSame(['name', 'domain_id'], $result[0]['params']['match']);
}
}

Expand Down

0 comments on commit a207a31

Please sign in to comment.