Skip to content

Commit 4256828

Browse files
author
Dominic Tubach
committed
Load funding case from database for update event
Previously the funding case was fetched from cache so previous and current funding case in `FundingCasePreUpdateEvent` and `FundingCaseUpdatedEvent` where the same object.
1 parent 3ec59f0 commit 4256828

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Civi/Funding/FundingCase/FundingCaseManager.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,11 @@ public function getOrCreate(array $allowedExistingStatusList, int $contactId, ar
229229
return $fundingCase ?? $this->create($contactId, $values);
230230
}
231231

232+
/**
233+
* @throws \CRM_Core_Exception
234+
*/
232235
public function update(FundingCaseEntity $fundingCase): void {
233-
$previousFundingCase = $this->get($fundingCase->getId());
236+
$previousFundingCase = $this->getWithoutCache($fundingCase->getId());
234237
Assert::notNull($previousFundingCase, 'Funding case could not be loaded');
235238
if ($fundingCase->getModificationDate() == $previousFundingCase->getModificationDate()) {
236239
$fundingCase->setModificationDate(new \DateTime(date('Y-m-d H:i:s')));
@@ -315,4 +318,12 @@ private function getFundingCaseFromApiResultOrNull(Result $result): ?FundingCase
315318
return $fundingCases[0] ?? NULL;
316319
}
317320

321+
/**
322+
* @throws \CRM_Core_Exception
323+
*/
324+
private function getWithoutCache(int $id): ?FundingCaseEntity {
325+
// @phpstan-ignore argument.type
326+
return FundingCaseEntity::fromArrayOrNull($this->api4->getEntity(FundingCase::getEntityName(), $id));
327+
}
328+
318329
}

tests/phpunit/Civi/Funding/FundingCase/FundingCaseManagerTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ public function testUpdate(): void {
409409
\CRM_Core_Session::singleton()->set('userID', $contact['id']);
410410
FundingCaseContactRelationFixture::addContact($contact['id'], $fundingCase->getId(), ['test_permission']);
411411

412-
$updatedFundingCase = FundingCaseEntity::fromArray($fundingCase->toArray());
412+
$updatedFundingCase = $this->fundingCaseManager->get($fundingCase->getId());
413+
static::assertNotNull($updatedFundingCase);
413414
$updatedFundingCase->setStatus('updated');
414415

415416
// Reload to have permission fields required for the event object comparison.

0 commit comments

Comments
 (0)