Skip to content

Commit

Permalink
Update pledge acknowledgement to use token processor only
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 22, 2021
1 parent f6c2c37 commit 432b761
Show file tree
Hide file tree
Showing 8 changed files with 4,087 additions and 4,077 deletions.
31 changes: 1 addition & 30 deletions CRM/Pledge/BAO/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,34 +569,6 @@ public static function sendAcknowledgment(&$form, $params) {
$form->assign('payments', $payments);
}

// handle domain token values
$domain = CRM_Core_BAO_Domain::getDomain();
$tokens = [
'domain' => ['name', 'phone', 'address', 'email'],
'contact' => CRM_Core_SelectValues::contactTokens(),
];
$domainValues = [];
foreach ($tokens['domain'] as $token) {
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
}
$form->assign('domain', $domainValues);

// handle contact token values.
$ids = [$params['contact_id']];
$fields = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields()),
['display_name', 'checksum', 'contact_id']
);
foreach ($fields as $key => $val) {
$returnProperties[$val] = TRUE;
}
[$details] = CRM_Utils_Token::getTokenDetails($ids,
$returnProperties,
TRUE, TRUE, NULL,
$tokens,
get_class($form)
);
$form->assign('contact', $details[$params['contact_id']]);

// handle custom data.
if (!empty($params['hidden_custom'])) {
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', NULL, $params['id']);
Expand Down Expand Up @@ -641,8 +613,7 @@ public static function sendAcknowledgment(&$form, $params) {
}
else {
// set the domain values.
$userName = $domainValues['name'] ?? NULL;
$userEmail = $domainValues['email'] ?? NULL;
[$userName, $userEmail] = CRM_Core_BAO_Domain::getNameAndEmail();
}

if (!isset($receiptFrom)) {
Expand Down
9 changes: 9 additions & 0 deletions CRM/Upgrade/Incremental/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ protected function getTemplateUpdates() {
['name' => 'case_activity', 'type' => 'subject'],
],
],
[
'version' => '5.44.alpha1',
'upgrade_descriptor' => ts('Use domain tokens instead of smarty values'),
'label' => ts('Pledge acknowledgement'),
'templates' => [
['name' => 'pledge_acknowledge', 'type' => 'text'],
['name' => 'pledge_acknowledge', 'type' => 'html'],
],
],
];
}

Expand Down
4 changes: 4 additions & 0 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,10 @@ public static function getTokenDeprecations(): array {
'$last_name' => 'contact.last_name',
'$displayName' => 'contact.display_name',
],
'pledge_acknowledgement' => [
'$domain' => 'no longer available / relevant',
'$contact' => 'no longer available / relevant',
],
],
];
}
Expand Down
8,072 changes: 4,036 additions & 4,036 deletions sql/civicrm_generated.mysql

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion tests/phpunit/CRM/Pledge/Form/PledgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,28 @@ class CRM_Pledge_Form_PledgeTest extends CiviUnitTestCase {
public function testPostProcess(): void {
$mut = new CiviMailUtils($this);
$loggedInUser = $this->createLoggedInUser();
$this->addLocationBlockToDomain();
$this->swapMessageTemplateForInput('pledge_acknowledge', '{domain.name} {contact.first_name}');

$form = $this->getFormObject('CRM_Pledge_Form_Pledge', [
'amount' => 10,
'installments' => 1,
'contact_id' => $this->individualCreate(),
'is_acknowledge' => 1,
'start_date' => '2021-01-04',
'create_date' => '2021-01-04',
'from_email_address' => Email::get()
->addWhere('contact_id', '=', $loggedInUser)
->addSelect('id')->execute()->first()['id'],
]);
$form->buildForm();
$form->postProcess();
$mut->checkAllMailLog(['Default Domain Name Anthony']);
$mut->checkAllMailLog([
'Default Domain Name Anthony',
123,
'fixme.domainemail@example.org',
'<p>Dear Anthony,</p>',
]);
$mut->clearMessages();
$this->revertTemplateToReservedTemplate('pledge_acknowledge');
}
Expand Down
30 changes: 24 additions & 6 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
* <http://www.gnu.org/licenses/>.
*/

use Civi\Api4\Address;
use Civi\Api4\Contribution;
use Civi\Api4\CustomField;
use Civi\Api4\CustomGroup;
use Civi\Api4\FinancialType;
use Civi\Api4\LineItem;
use Civi\Api4\MembershipType;
use Civi\Api4\OptionGroup;
use Civi\Api4\Phone;
use Civi\Api4\RelationshipType;
use Civi\Payment\System;
use Civi\Api4\OptionValue;
Expand Down Expand Up @@ -731,7 +733,7 @@ public function membershipStatusCreate($name = 'test member status') {
*
* @throws \CRM_Core_Exception
*/
public function membershipStatusDelete(int $membershipStatusID) {
public function membershipStatusDelete(int $membershipStatusID): void {
$this->callAPISuccess('Membership', 'get', ['status_id' => $membershipStatusID, 'api.Membership.delete' => 1]);
$this->callAPISuccess('MembershipStatus', 'Delete', ['id' => $membershipStatusID]);
}
Expand Down Expand Up @@ -1010,10 +1012,8 @@ public function entityTagAdd($params) {
*
* @return int
* id of created pledge
*
* @throws \CRM_Core_Exception
*/
public function pledgeCreate($params) {
public function pledgeCreate($params): int {
$params = array_merge([
'pledge_create_date' => date('Ymd'),
'start_date' => date('Ymd'),
Expand Down Expand Up @@ -3612,8 +3612,8 @@ public function createCase($clientId, $loggedInUser = NULL, $extra = []) {
'status_id' => 1,
'case_type' => 'housing_support',
'subject' => 'Case Subject',
'start_date' => date("Y-m-d"),
'start_date_time' => date("YmdHis"),
'start_date' => date('Y-m-d'),
'start_date_time' => date('YmdHis'),
'medium_id' => 2,
'activity_details' => '',
], $extra);
Expand Down Expand Up @@ -3799,4 +3799,22 @@ protected function ensureMembershipPriceSetExists(): void {
");
}

/**
* Add an address block to the current domain.
*
* @noinspection PhpUnhandledExceptionInspection
*/
protected function addLocationBlockToDomain(): void {
$contactID = CRM_Core_BAO_Domain::getDomain()->contact_id;
Phone::create()
->setValues(['phone' => 123, 'contact_id' => $contactID])
->execute()
->first()['id'];
Address::create()->setValues([
'street_address' => '10 Downing Street',
'city' => 'London',
'contact_id' => $contactID,
])->execute()->first();
}

}
4 changes: 2 additions & 2 deletions xml/templates/message_templates/pledge_acknowledge_html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<tr>
<td>
{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}<p>{$greeting},</p>{/if}
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}<p>{$greeting},</p>{/if}
<p>{ts}Thank you for your generous pledge.{/ts}</p>
</td>
</tr>
Expand Down Expand Up @@ -80,7 +80,7 @@

<tr>
<td colspan="2" {$valueStyle}>
<p>{ts 1=$domain.phone 2=$domain.email}Please contact us at %1 or send email to %2 if you have questions
<p>{ts 1='{domain.phone}' 2='{domain.email}'}Please contact us at %1 or send email to %2 if you have questions
or need to modify your payment schedule.{/ts}</p>
</td>
</tr>
Expand Down
4 changes: 2 additions & 2 deletions xml/templates/message_templates/pledge_acknowledge_text.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}<p>{$greeting},</p>{/if}
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}<p>{$greeting},</p>{/if}

{ts}Thank you for your generous pledge.{/ts}

Expand Down Expand Up @@ -30,7 +30,7 @@
{/if}


{ts 1=$domain.phone 2=$domain.email}Please contact us at %1 or send email to %2 if you have questions
{ts 1='{domain.phone}' 2='{domain.email}'}Please contact us at %1 or send email to %2 if you have questions
or need to modify your payment schedule.{/ts}

{if $customGroup}
Expand Down

0 comments on commit 432b761

Please sign in to comment.