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

[Ref] cleanup alterActionSchedule #21047

Merged
merged 1 commit into from
Aug 7, 2021
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
14 changes: 4 additions & 10 deletions CRM/Contribute/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function __construct() {
*/
public function checkActive(TokenProcessor $processor) {
return !empty($processor->context['actionMapping'])
&& $processor->context['actionMapping']->getEntity() === 'civicrm_contribution';
&& $processor->context['actionMapping']->getEntity() === $this->getExtendableTableName();
}

/**
Expand All @@ -134,17 +134,11 @@ public function checkActive(TokenProcessor $processor) {
* @param \Civi\ActionSchedule\Event\MailingQueryEvent $e
*/
public function alterActionScheduleQuery(MailingQueryEvent $e): void {
if ($e->mapping->getEntity() !== 'civicrm_contribution') {
if ($e->mapping->getEntity() !== $this->getExtendableTableName()) {
return;
}

$fields = $this->getFieldMetadata();
foreach (array_keys($this->getBasicTokens()) as $token) {
$e->query->select('e.' . $fields[$token]['name'] . ' AS ' . $this->getEntityAlias() . $token);
}
foreach (array_keys($this->getPseudoTokens()) as $token) {
$split = explode(':', $token);
$e->query->select('e.' . $fields[$split[0]]['name'] . ' AS ' . $this->getEntityAlias() . $split[0]);
foreach ($this->getReturnFields() as $token) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton what has happened to the pseudo tokens?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 yeah - it turned out I never needed them - (or perhaps I did before I got it sane) what I was doing was adding in the field they need - ie contribution_status_id - but since that field is ALSO in getReturnFields 'under it's own name' - I don't need the spy-version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(the tests specifically cover these )

$e->query->select('e.' . $token . ' AS ' . $this->getEntityAlias() . $token);
}
}

Expand Down
20 changes: 20 additions & 0 deletions CRM/Core/EntityTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,33 @@ protected function getEntityAlias(): string {
return $this->getApiEntityName() . '__';
}

/**
* Get the name of the table this token class can extend.
*
* The default is based on the entity but some token classes,
* specifically the event class, latch on to other tables - ie
* the participant table.
*/
public function getExtendableTableName(): string {
return CRM_Core_DAO_AllCoreTables::getTableForEntityName($this->getApiEntityName());
}

/**
* Get the relevant bao name.
*/
public function getBAOName(): string {
return CRM_Core_DAO_AllCoreTables::getFullName($this->getApiEntityName());
}

/**
* Get an array of fields to be requested.
*
* @return string[]
*/
public function getReturnFields(): array {
return array_keys($this->getBasicTokens());
}

/**
* Get all the tokens supported by this processor.
*
Expand Down