Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load funding case from database for update event #415

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Civi/Funding/FundingCase/FundingCaseManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,11 @@ public function getOrCreate(array $allowedExistingStatusList, int $contactId, ar
return $fundingCase ?? $this->create($contactId, $values);
}

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

/**
* @throws \CRM_Core_Exception
*/
private function getWithoutCache(int $id): ?FundingCaseEntity {
// @phpstan-ignore argument.type
return FundingCaseEntity::fromArrayOrNull($this->api4->getEntity(FundingCase::getEntityName(), $id));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ public function testUpdate(): void {
\CRM_Core_Session::singleton()->set('userID', $contact['id']);
FundingCaseContactRelationFixture::addContact($contact['id'], $fundingCase->getId(), ['test_permission']);

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

// Reload to have permission fields required for the event object comparison.
Expand Down
Loading