Merge pull request #21520 from eileenmcnaughton/badger
authorSeamus Lee <seamuslee001@gmail.com>
Mon, 20 Sep 2021 23:11:19 +0000 (09:11 +1000)
committerGitHub <noreply@github.com>
Mon, 20 Sep 2021 23:11:19 +0000 (09:11 +1000)
Participant tokens - remove / replace unsupportable from badges (conversion preparation)

1  2 
CRM/Core/SelectValues.php
CRM/Upgrade/Incremental/MessageTemplates.php
tests/phpunit/CRM/Utils/TokenConsistencyTest.php

index 20e5ebe2167ad269da2c00f9ace9bbacb8fc4829,46c63961c662af29a066705dae66ea3409c5ba5c..2acad7d0b5fe78bf84fa9bd4c72b598797075464
@@@ -494,12 -494,14 +494,12 @@@ class CRM_Core_SelectValues 
     * Domain tokens
     *
     * @return array
 +   *
 +   * @deprecated
     */
    public static function domainTokens() {
 -    return [
 -      '{domain.name}' => ts('Domain name'),
 -      '{domain.address}' => ts('Domain (organization) address'),
 -      '{domain.phone}' => ts('Domain (organization) phone'),
 -      '{domain.email}' => ts('Domain (organization) email'),
 -    ];
 +    $tokenProcessor = new TokenProcessor(Civi::dispatcher(), []);
 +    return $tokenProcessor->listTokens();
    }
  
    /**
    /**
     * Different type of Event Tokens.
     *
 +   * @deprecated
 +   *
     * @return array
     */
 -  public static function eventTokens() {
 -    return [
 -      '{event.event_id}' => ts('Event ID'),
 -      '{event.title}' => ts('Event Title'),
 -      '{event.start_date}' => ts('Event Start Date'),
 -      '{event.end_date}' => ts('Event End Date'),
 -      '{event.event_type}' => ts('Event Type'),
 -      '{event.summary}' => ts('Event Summary'),
 -      '{event.contact_email}' => ts('Event Contact Email'),
 -      '{event.contact_phone}' => ts('Event Contact Phone'),
 -      '{event.description}' => ts('Event Description'),
 -      '{event.location}' => ts('Event Location'),
 -      '{event.fee_amount}' => ts('Event Fees'),
 -      '{event.info_url}' => ts('Event Info URL'),
 -      '{event.registration_url}' => ts('Event Registration URL'),
 -      '{event.balance}' => ts('Event Balance'),
 -    ];
 +  public static function eventTokens(): array {
 +    $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['eventId']]);
 +    $allTokens = $tokenProcessor->listTokens();
 +    foreach (array_keys($allTokens) as $token) {
 +      if (strpos($token, '{domain.') === 0) {
 +        unset($allTokens[$token]);
 +      }
 +    }
 +    return $allTokens;
    }
  
    /**
     * Different type of Contribution Tokens.
     *
 +   * @deprecated
 +   *
     * @return array
     */
    public static function contributionTokens(): array {
      $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['contributionId']]);
 -    return $tokenProcessor->listTokens();
 +    $allTokens = $tokenProcessor->listTokens();
 +    foreach (array_keys($allTokens) as $token) {
 +      if (strpos($token, '{domain.') === 0) {
 +        unset($allTokens[$token]);
 +      }
 +    }
 +    return $allTokens;
    }
  
    /**
     * Different type of Contact Tokens.
     *
 +   * @deprecated
 +   *
     * @return array
     */
    public static function contactTokens(): array {
      $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['contactId']]);
 -    return $tokenProcessor->listTokens();
 +    $allTokens = $tokenProcessor->listTokens();
 +    foreach (array_keys($allTokens) as $token) {
 +      if (strpos($token, '{domain.') === 0) {
 +        unset($allTokens[$token]);
 +      }
 +    }
 +    return $allTokens;
    }
  
    /**
        '{participant.participant_registered_by_id}' => 'Registered By Participant ID',
        '{participant.transferred_to_contact_id}' => 'Transferred to Contact ID',
        '{participant.participant_role}' => 'Participant Role (label)',
-       '{participant.event_title}' => 'Event Title',
-       '{participant.event_start_date}' => 'Event Start Date',
-       '{participant.event_end_date}' => 'Event End Date',
        '{participant.fee_label}' => 'Fee Label',
        '{participant.default_role_id}' => 'Default Role',
        '{participant.template_title}' => 'Event Template Title',
-       '{participant.currency}' => 'Currency',
-       '{participant.participant_note}' => 'Participant Note',
      ];
      $customFields = CRM_Core_BAO_CustomField::getFields('Participant');
  
index eb1928504c3aa713bbacc5668f94d7aa2f8a3aee,a4a0076a8f068afc191459f49377671fe2748636..2c044e32cb51df451d35e95dea22f5a569a3c323
@@@ -251,12 -251,9 +251,12 @@@ class CRM_Upgrade_Incremental_MessageTe
        ],
        [
          'version' => '5.43.alpha1',
 -        'upgrade_descriptor' => ts('Missed text version from 5.20'),
 +        'upgrade_descriptor' => ts('Missed templates from earlier versions'),
          'templates' => [
            ['name' => 'contribution_online_receipt', 'type' => 'text'],
 +          ['name' => 'case_activity', 'type' => 'html'],
 +          ['name' => 'case_activity', 'type' => 'text'],
 +          ['name' => 'case_activity', 'type' => 'subject'],
          ],
        ],
      ];
      ");
    }
  
+   /**
+    * Replace a token with the new preferred option in a print label.
+    *
+    * @param string $old
+    * @param string $new
+    */
+   public function replaceTokenInPrintLabel(string $old, string $new): void {
+     $oldToken = '{' . $old . '}';
+     $newToken = '{' . $new . '}';
+     CRM_Core_DAO::executeQuery("UPDATE civicrm_print_label
+       SET
+         data = REPLACE(data, '$oldToken', '$newToken')
+     ");
+   }
    /**
     * Get the upgrade messages.
     */
index 6bb288bd74d7d5760da506c834d843a5f4ca1eb7,fa9b57ae4cb3ac3a9b97aa278ec0163e129ce2b0..d13406b264fdfca4d058932957836af11bc16e3e
@@@ -85,7 -85,7 +85,7 @@@ class CRM_Utils_TokenConsistencyTest ex
        'smarty' => FALSE,
        'schema' => ['caseId'],
      ]);
 -    $this->assertEquals($expectedTokens, $tokenProcessor->listTokens());
 +    $this->assertEquals(array_merge($expectedTokens, $this->getDomainTokens()), $tokenProcessor->listTokens());
      $tokenProcessor->addRow([
        'caseId' => $this->getCaseID(),
      ]);
@@@ -203,7 -203,7 +203,7 @@@ N
        'smarty' => FALSE,
        'schema' => ['contribution_recurId'],
      ]);
 -    $this->assertEquals($this->getContributionRecurTokens(), $tokenProcessor->listTokens());
 +    $this->assertEquals(array_merge($this->getContributionRecurTokens(), $this->getDomainTokens()), $tokenProcessor->listTokens());
      $tokenString = implode("\n", array_keys($this->getContributionRecurTokens()));
  
      $tokenProcessor->addMessage('html', $tokenString, 'text/plain');
@@@ -406,7 -406,7 +406,7 @@@ Check'
      $tokens = $tokenProcessor->listTokens();
      // Add in custom tokens as token processor supports these.
      $expectedTokens['{membership.custom_1}'] = 'Enter text here :: Group with field text';
 -    $this->assertEquals($expectedTokens, $tokens);
 +    $this->assertEquals(array_merge($expectedTokens, $this->getDomainTokens()), $tokens);
      $tokenProcessor->addMessage('html', $tokenString, 'text/plain');
      $tokenProcessor->addRow(['membershipId' => $this->getMembershipID()]);
      $tokenProcessor->evaluate();
@@@ -477,7 -477,7 +477,7 @@@ December 21st, 200
    }
  
    /**
 -   * Get declared membership tokens.
 +   * Get declared participant tokens.
     *
     * @return string[]
     */
        '{participant.participant_registered_by_id}' => 'Registered By Participant ID',
        '{participant.transferred_to_contact_id}' => 'Transferred to Contact ID',
        '{participant.participant_role}' => 'Participant Role (label)',
-       '{participant.event_title}' => 'Event Title',
-       '{participant.event_start_date}' => 'Event Start Date',
-       '{participant.event_end_date}' => 'Event End Date',
        '{participant.fee_label}' => 'Fee Label',
        '{participant.default_role_id}' => 'Default Role',
        '{participant.template_title}' => 'Event Template Title',
-       '{participant.currency}' => 'Currency',
-       '{participant.participant_note}' => 'Participant Note',
        '{participant.' . $this->getCustomFieldName('text') . '}' => 'Enter text here :: Group with field text',
      ];
    }
  
 +  /**
 +   * Test that domain tokens are consistently rendered.
 +   */
 +  public function testDomainTokenConsistency(): void {
 +    $tokens = CRM_Core_SelectValues::domainTokens();
 +    $this->assertEquals($this->getDomainTokens(), $tokens);
 +    $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [
 +      'controller' => __CLASS__,
 +      'smarty' => FALSE,
 +    ]);
 +    $tokens['{domain.id}'] = 'Domain ID';
 +    $tokens['{domain.description}'] = 'Domain Description';
 +    $this->assertEquals($tokens, $tokenProcessor->listTokens());
 +  }
 +
 +  /**
 +   * Get declared participant tokens.
 +   *
 +   * @return string[]
 +   */
 +  public function getDomainTokens(): array {
 +    return [
 +      '{domain.name}' => ts('Domain name'),
 +      '{domain.address}' => ts('Domain (organization) address'),
 +      '{domain.phone}' => ts('Domain (organization) phone'),
 +      '{domain.email}' => 'Domain (organization) email',
 +      '{domain.id}' => ts('Domain ID'),
 +      '{domain.description}' => ts('Domain Description'),
 +    ];
 +  }
 +
 +  /**
 +   * Test that domain tokens are consistently rendered.
 +   */
 +  public function testEventTokenConsistency(): void {
 +    $tokens = CRM_Core_SelectValues::eventTokens();
 +    $this->assertEquals($this->getEventTokens(), $tokens);
 +    $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [
 +      'controller' => __CLASS__,
 +      'smarty' => FALSE,
 +      'schema' => ['eventId'],
 +    ]);
 +    $this->assertEquals(array_merge($tokens, $this->getDomainTokens()), $tokenProcessor->listTokens());
 +  }
 +
 +  /**
 +   * Get expected event tokens.
 +   *
 +   * @return string[]
 +   */
 +  protected function getEventTokens(): array {
 +    return [
 +      '{event.event_id}' => 'Event ID',
 +      '{event.title}' => 'Event Title',
 +      '{event.start_date}' => 'Event Start Date',
 +      '{event.end_date}' => 'Event End Date',
 +      '{event.event_type}' => 'Event Type',
 +      '{event.summary}' => 'Event Summary',
 +      '{event.contact_email}' => 'Event Contact Email',
 +      '{event.contact_phone}' => 'Event Contact Phone',
 +      '{event.description}' => 'Event Description',
 +      '{event.location}' => 'Event Location',
 +      '{event.fee_amount}' => 'Event Fee',
 +      '{event.info_url}' => 'Event Info URL',
 +      '{event.registration_url}' => 'Event Registration URL',
 +      '{event.balance}' => 'Event Balance',
 +    ];
 +  }
 +
  }