Skip to content

Commit

Permalink
Merge pull request #30518 from eileenmcnaughton/twomice
Browse files Browse the repository at this point in the history
Add SiteToken entity to the schema
  • Loading branch information
eileenmcnaughton authored Jun 20, 2024
2 parents 3d6e13a + 9356382 commit 7f91ddd
Show file tree
Hide file tree
Showing 5 changed files with 382 additions and 0 deletions.
23 changes: 23 additions & 0 deletions CRM/Core/DAO/SiteToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

/**
* Placeholder class retained for legacy compatibility.
*
* @property int $id
* @property int $domain_id
* @property string $name
* @property string $body_html
* @property string $body_text
* @property bool $is_active
* @property bool $is_reserved
* @property int $created_id
* @property int $modified_id
* @property string $modified_date
*/
class CRM_Core_DAO_SiteToken extends CRM_Core_DAO_Base {
}
20 changes: 20 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveSeventySix.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ public function upgrade_5_76_alpha1($rev): void {
$this->addTask('Alter translation to make string non-required', 'alterColumn', 'civicrm_translation', 'string',
"longtext NULL COMMENT 'Translated string'"
);
$this->addTask('Install SiteToken entity', 'createEntityTable', '5.76.alpha1.SiteToken.entityType.php');
$this->addTask(ts('Create index %1', [1 => 'civicrm_site_token.UI_name_domain_id']), 'addIndex', 'civicrm_site_token', [['name', 'domain_id']], 'UI');
$this->addTask('Create "message header" token', 'create_mesage_header_token');
}

public static function create_mesage_header_token() {
$query = CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_domain');
$domains = $query->fetchAll();
foreach ($domains as $domain) {
CRM_Core_DAO::executeQuery(
"INSERT IGNORE INTO civicrm_site_token (domain_id, name, label, body_html, body_text, is_reserved, is_active)
VALUES(
" . $domain['id'] . ",
'message_header',
'" . ts('Message Header') . "',
'<!-- " . ts('This is the %1 token HTML content.', [1 => '{site.message_header}']) . " -->',
'', 1, 1)"
);
}
return TRUE;
}

}
169 changes: 169 additions & 0 deletions CRM/Upgrade/Incremental/schema/5.76.alpha1.SiteToken.entityType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php

return [
'name' => 'SiteToken',
'table' => 'civicrm_site_token',
'class' => 'CRM_Core_DAO_SiteToken',
// @todo - uncomment token class when the class is added.
//'token_class' => 'CRM_Core_SiteTokens',
'getInfo' => fn() => [
'title' => ts('Site Token'),
'title_plural' => ts('Site Tokens'),
'description' => ts('Site-wide tokens.'),
'add' => 5.76,
'log' => TRUE,
'icon' => 'fa-code',
],
'getIndices' => fn() => [
'UI_name_domain_id' => [
'fields' => [
'name' => TRUE,
'domain_id' => TRUE,
],
'unique' => TRUE,
'add' => '5.76',
],
],
'getPaths' => fn() => [
'add' => 'civicrm/admin/sitetoken/edit?action=add&reset=1',
'update' => 'civicrm/admin/sitetoken/edit#?SiteToken1=[id]',
'browse' => 'civicrm/admin/sitetoken?action=browse&reset=1',
],
'getFields' => fn() => [
'id' => [
'title' => ts('Site Token ID'),
'sql_type' => 'int unsigned',
'input_type' => 'Number',
'required' => TRUE,
'primary_key' => TRUE,
'auto_increment' => TRUE,
],
'domain_id' => [
'title' => ts('Domain'),
'sql_type' => 'int unsigned',
'input_type' => 'EntityRef',
'required' => TRUE,
'entity_reference' => [
'entity' => 'Domain',
'key' => 'id',
'on_delete' => 'CASCADE',
],
'pseudoconstant' => [
'table' => 'civicrm_domain',
'key_column' => 'id',
'label_column' => 'name',
],
],
'name' => [
'title' => ts('Token Name'),
'sql_type' => 'varchar(64)',
'input_type' => 'Text',
'required' => TRUE,
'description' => ts('Token string, e.g. {site.[name]}'),
'input_attrs' => [
'maxlength' => 64,
],
],
'label' => [
'title' => ts('Token Label'),
'sql_type' => 'varchar(255)',
'input_type' => 'Text',
'required' => TRUE,
'description' => ts('User-visible label in token UI'),
'input_attrs' => [
'label' => ts('Label'),
'maxlength' => 255,
],
],
'body_html' => [
'title' => ts('Token Value (HTML)'),
'sql_type' => 'text',
'input_type' => 'TextArea',
'description' => ts('Value of the token in html format.'),
'input_attrs' => [
'rows' => 8,
'cols' => 80,
],
],
'body_text' => [
'title' => ts('Token Value (Text)'),
'sql_type' => 'text',
'input_type' => 'TextArea',
'description' => ts('Value of the token in text format.'),
'input_attrs' => [
'rows' => 8,
'cols' => 80,
'label' => ts('Body in Text Format'),
],
],
'is_active' => [
'title' => ts('Token Is Active?'),
'sql_type' => 'boolean',
'input_type' => 'CheckBox',
'required' => TRUE,
'description' => ts('Is this token active?'),
'default' => TRUE,
'input_attrs' => [
'label' => ts('Enabled'),
],
],
'is_reserved' => [
'title' => ts('Token Is Reserved?'),
'sql_type' => 'boolean',
'input_type' => 'CheckBox',
'required' => TRUE,
'description' => ts('Is this token reserved?'),
'default' => FALSE,
'input_attrs' => [
'label' => ts('Reserved'),
],
],
'created_id' => [
'title' => ts('Created By Contact ID'),
'sql_type' => 'int unsigned',
'input_type' => 'EntityRef',
'description' => ts('Contact responsible for creating this token'),
'add' => '5.76',
'input_attrs' => [
'label' => ts('Created By'),
],
'entity_reference' => [
'entity' => 'Contact',
'key' => 'id',
'on_delete' => 'SET NULL',
],
],
'modified_id' => [
'title' => ts('Modified By Contact ID'),
'sql_type' => 'int unsigned',
'input_type' => NULL,
'readonly' => TRUE,
'description' => ts('FK to contact table.'),
'add' => '5.76',
'input_attrs' => [
'label' => ts('Modified By'),
],
'entity_reference' => [
'entity' => 'Contact',
'key' => 'id',
'on_delete' => 'SET NULL',
],
],
'modified_date' => [
'title' => ts('Modified Date'),
'sql_type' => 'timestamp',
'input_type' => 'Select Date',
'readonly' => TRUE,
'description' => ts('When the token was created or modified or deleted.'),
'add' => '4.7',
'unique_name' => 'site_token_modified_date',
'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
'usage' => [
'export',
],
'input_attrs' => [
'label' => ts('Modified Date'),
],
],
],
];
169 changes: 169 additions & 0 deletions schema/Core/SiteToken.entityType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php

return [
'name' => 'SiteToken',
'table' => 'civicrm_site_token',
'class' => 'CRM_Core_DAO_SiteToken',
// @todo - uncomment token class when the class is added.
//'token_class' => 'CRM_Core_SiteTokens',
'getInfo' => fn() => [
'title' => ts('Site Token'),
'title_plural' => ts('Site Tokens'),
'description' => ts('Site-wide tokens.'),
'add' => 5.76,
'log' => TRUE,
'icon' => 'fa-code',
],
'getIndices' => fn() => [
'UI_name_domain_id' => [
'fields' => [
'name' => TRUE,
'domain_id' => TRUE,
],
'unique' => TRUE,
'add' => '5.76',
],
],
'getPaths' => fn() => [
'add' => 'civicrm/admin/sitetoken/edit?action=add&reset=1',
'update' => 'civicrm/admin/sitetoken/edit#?SiteToken1=[id]',
'browse' => 'civicrm/admin/sitetoken?action=browse&reset=1',
],
'getFields' => fn() => [
'id' => [
'title' => ts('Site Token ID'),
'sql_type' => 'int unsigned',
'input_type' => 'Number',
'required' => TRUE,
'primary_key' => TRUE,
'auto_increment' => TRUE,
],
'domain_id' => [
'title' => ts('Domain'),
'sql_type' => 'int unsigned',
'input_type' => 'EntityRef',
'required' => TRUE,
'entity_reference' => [
'entity' => 'Domain',
'key' => 'id',
'on_delete' => 'CASCADE',
],
'pseudoconstant' => [
'table' => 'civicrm_domain',
'key_column' => 'id',
'label_column' => 'name',
],
],
'name' => [
'title' => ts('Token Name'),
'sql_type' => 'varchar(64)',
'input_type' => 'Text',
'required' => TRUE,
'description' => ts('Token string, e.g. {site.[name]}'),
'input_attrs' => [
'maxlength' => 64,
],
],
'label' => [
'title' => ts('Token Label'),
'sql_type' => 'varchar(255)',
'input_type' => 'Text',
'required' => TRUE,
'description' => ts('User-visible label in token UI'),
'input_attrs' => [
'label' => ts('Label'),
'maxlength' => 255,
],
],
'body_html' => [
'title' => ts('Token Value (HTML)'),
'sql_type' => 'text',
'input_type' => 'TextArea',
'description' => ts('Value of the token in html format.'),
'input_attrs' => [
'rows' => 8,
'cols' => 80,
],
],
'body_text' => [
'title' => ts('Token Value (Text)'),
'sql_type' => 'text',
'input_type' => 'TextArea',
'description' => ts('Value of the token in text format.'),
'input_attrs' => [
'rows' => 8,
'cols' => 80,
'label' => ts('Body in Text Format'),
],
],
'is_active' => [
'title' => ts('Token Is Active?'),
'sql_type' => 'boolean',
'input_type' => 'CheckBox',
'required' => TRUE,
'description' => ts('Is this token active?'),
'default' => TRUE,
'input_attrs' => [
'label' => ts('Enabled'),
],
],
'is_reserved' => [
'title' => ts('Token Is Reserved?'),
'sql_type' => 'boolean',
'input_type' => 'CheckBox',
'required' => TRUE,
'description' => ts('Is this token reserved?'),
'default' => FALSE,
'input_attrs' => [
'label' => ts('Reserved'),
],
],
'created_id' => [
'title' => ts('Created By Contact ID'),
'sql_type' => 'int unsigned',
'input_type' => 'EntityRef',
'description' => ts('Contact responsible for creating this token'),
'add' => '5.76',
'input_attrs' => [
'label' => ts('Created By'),
],
'entity_reference' => [
'entity' => 'Contact',
'key' => 'id',
'on_delete' => 'SET NULL',
],
],
'modified_id' => [
'title' => ts('Modified By Contact ID'),
'sql_type' => 'int unsigned',
'input_type' => NULL,
'readonly' => TRUE,
'description' => ts('FK to contact table.'),
'add' => '5.76',
'input_attrs' => [
'label' => ts('Modified By'),
],
'entity_reference' => [
'entity' => 'Contact',
'key' => 'id',
'on_delete' => 'SET NULL',
],
],
'modified_date' => [
'title' => ts('Modified Date'),
'sql_type' => 'timestamp',
'input_type' => 'Select Date',
'readonly' => TRUE,
'description' => ts('When the token was created or modified or deleted.'),
'add' => '4.7',
'unique_name' => 'site_token_modified_date',
'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
'usage' => [
'export',
],
'input_attrs' => [
'label' => ts('Modified Date'),
],
],
],
];
1 change: 1 addition & 0 deletions tests/phpunit/CRM/Dedupe/MergerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,7 @@ public function getStaticCIDRefs() {
0 => 'created_id',
],
'civicrm_saved_search' => ['created_id', 'modified_id'],
'civicrm_site_token' => ['created_id', 'modified_id'],
'civicrm_relationship' => [
0 => 'contact_id_a',
1 => 'contact_id_b',
Expand Down

0 comments on commit 7f91ddd

Please sign in to comment.