Skip to content

Commit

Permalink
dev/core#4213 Make frontend_title, name required for Group entity
Browse files Browse the repository at this point in the history
This follows up on having done this for contribution_page recently.

It will mean we can consistently refer to frontend_title in tokens
and other places where what we really mean is ... frontend_title.
  • Loading branch information
eileenmcnaughton committed Jun 22, 2023
1 parent 2e3ab90 commit 75f450a
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 45 deletions.
2 changes: 1 addition & 1 deletion CRM/Case/xml/configuration.sample/case_sample.mysql.tpl
Expand Up @@ -98,4 +98,4 @@ SELECT 'Benefits Specialist is', {localize}'{ts escape="sql"}Benefits Specialist
-- *
-- *******************************************************/

INSERT INTO `civicrm_group` ( `name`, {localize field='title'}`title`{/localize}, `description`, `source`, `saved_search_id`, `is_active`, `visibility`, `where_clause`, `select_tables`, `where_tables`, `group_type`, `cache_date`, `parents`, `children`, `is_hidden` ) (SELECT 'Case_Resources', {localize}'{ts escape="sql"}Case Resources{/ts}'{/localize}, 'Contacts in this group are listed with their phone number and email when viewing case. You also can send copies of case activities to these contacts.', NULL, NULL, 1, 'User and User Admin Only', ' ( `civicrm_group_contact-5`.group_id IN ( 5 ) AND `civicrm_group_contact-5`.status IN ("Added") ) ', '{literal}a:10:{s:15:"civicrm_contact";i:1;s:15:"civicrm_address";i:1;s:22:"civicrm_state_province";i:1;s:15:"civicrm_country";i:1;s:13:"civicrm_email";i:1;s:13:"civicrm_phone";i:1;s:10:"civicrm_im";i:1;s:19:"civicrm_worldregion";i:1;s:25:"`civicrm_group_contact-5`";s:114:" LEFT JOIN civicrm_group_contact `civicrm_group_contact-5` ON contact_a.id = `civicrm_group_contact-5`.contact_id ";s:6:"gender";i:1;}{/literal}', '{literal}a:2:{s:15:"civicrm_contact";i:1;s:25:"`civicrm_group_contact-5`";s:114:" LEFT JOIN civicrm_group_contact `civicrm_group_contact-5` ON contact_a.id = `civicrm_group_contact-5`.contact_id ";}{/literal}', '2', NULL, NULL, NULL, 0 FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_group` WHERE `name` = 'Case_Resources'));
INSERT INTO `civicrm_group` ( `name`, {localize field='title'}`title`{/localize},{localize field='frontend_title'}`frontend_title`{/localize}, `description`, `source`, `saved_search_id`, `is_active`, `visibility`, `where_clause`, `select_tables`, `where_tables`, `group_type`, `cache_date`, `parents`, `children`, `is_hidden` ) (SELECT 'Case_Resources', {localize}'{ts escape="sql"}Case Resources{/ts}'{/localize},{localize}'{ts escape="sql"}Case Resources{/ts}'{/localize}, 'Contacts in this group are listed with their phone number and email when viewing case. You also can send copies of case activities to these contacts.', NULL, NULL, 1, 'User and User Admin Only', ' ( `civicrm_group_contact-5`.group_id IN ( 5 ) AND `civicrm_group_contact-5`.status IN ("Added") ) ', '{literal}a:10:{s:15:"civicrm_contact";i:1;s:15:"civicrm_address";i:1;s:22:"civicrm_state_province";i:1;s:15:"civicrm_country";i:1;s:13:"civicrm_email";i:1;s:13:"civicrm_phone";i:1;s:10:"civicrm_im";i:1;s:19:"civicrm_worldregion";i:1;s:25:"`civicrm_group_contact-5`";s:114:" LEFT JOIN civicrm_group_contact `civicrm_group_contact-5` ON contact_a.id = `civicrm_group_contact-5`.contact_id ";s:6:"gender";i:1;}{/literal}', '{literal}a:2:{s:15:"civicrm_contact";i:1;s:25:"`civicrm_group_contact-5`";s:114:" LEFT JOIN civicrm_group_contact `civicrm_group_contact-5` ON contact_a.id = `civicrm_group_contact-5`.contact_id ";}{/literal}', '2', NULL, NULL, NULL, 0 FROM dual WHERE NOT EXISTS (SELECT * FROM `civicrm_group` WHERE `name` = 'Case_Resources'));
13 changes: 7 additions & 6 deletions CRM/Contact/BAO/Group.php
Expand Up @@ -343,6 +343,11 @@ public static function create(&$params) {
'parents' => NULL,
];

if (empty($params['id']) && empty($params['frontend_title'])) {
// If we were calling writeRecord it would handle this, but we need
// to migrate the other bits of magic.
$params['frontend_title'] = $params['title'];
}
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, 'Group', $params['id'] ?? NULL, $params);

Expand Down Expand Up @@ -1105,12 +1110,8 @@ public static function getGroupsHierarchy(
$title = $dao->title;
$description = $dao->description;
if ($public) {
if (!empty($dao->frontend_title)) {
$title = $dao->frontend_title;
}
if (!empty($dao->frontend_description)) {
$description = $dao->frontend_description;
}
$title = $dao->frontend_title;
$description = $dao->frontend_description;
}
if ($dao->parents) {
$parentArray = explode(',', $dao->parents);
Expand Down
18 changes: 13 additions & 5 deletions CRM/Contact/DAO/Group.php
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Contact/Group.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:e98767d560ee98268e800a2aec983cea)
* (GenCodeChecksum:5cb6d58b6f91122093003d8c0db4fab1)
*/

/**
Expand Down Expand Up @@ -68,7 +68,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO {
/**
* Internal name of Group.
*
* @var string|null
* @var string
* (SQL type: varchar(64))
* Note that values will be retrieved from the database as a string.
*/
Expand All @@ -77,7 +77,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO {
/**
* Name of Group.
*
* @var string|null
* @var string
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
Expand Down Expand Up @@ -134,6 +134,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO {
* @var string|null
* (SQL type: text)
* Note that values will be retrieved from the database as a string.
* @deprecated
*/
public $where_clause;

Expand All @@ -143,6 +144,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO {
* @var string|null
* (SQL type: text)
* Note that values will be retrieved from the database as a string.
* @deprecated
*/
public $select_tables;

Expand All @@ -152,6 +154,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO {
* @var string|null
* (SQL type: text)
* Note that values will be retrieved from the database as a string.
* @deprecated
*/
public $where_tables;

Expand Down Expand Up @@ -238,7 +241,7 @@ class CRM_Contact_DAO_Group extends CRM_Core_DAO {
/**
* Alternative public title for this Group.
*
* @var string|null
* @var string
* (SQL type: varchar(255))
* Note that values will be retrieved from the database as a string.
*/
Expand Down Expand Up @@ -324,6 +327,7 @@ public static function &fields() {
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Group Name'),
'description' => ts('Internal name of Group.'),
'required' => TRUE,
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
'usage' => [
Expand All @@ -344,6 +348,7 @@ public static function &fields() {
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Group Title'),
'description' => ts('Name of Group.'),
'required' => TRUE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'usage' => [
Expand Down Expand Up @@ -494,6 +499,7 @@ public static function &fields() {
'entity' => 'Group',
'bao' => 'CRM_Contact_BAO_Group',
'localizable' => 0,
'deprecated' => TRUE,
'readonly' => TRUE,
'add' => '1.6',
],
Expand All @@ -514,6 +520,7 @@ public static function &fields() {
'bao' => 'CRM_Contact_BAO_Group',
'localizable' => 0,
'serialize' => self::SERIALIZE_PHP,
'deprecated' => TRUE,
'readonly' => TRUE,
'add' => '1.6',
],
Expand All @@ -534,6 +541,7 @@ public static function &fields() {
'bao' => 'CRM_Contact_BAO_Group',
'localizable' => 0,
'serialize' => self::SERIALIZE_PHP,
'deprecated' => TRUE,
'readonly' => TRUE,
'add' => '1.6',
],
Expand Down Expand Up @@ -756,6 +764,7 @@ public static function &fields() {
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Public Group Title'),
'description' => ts('Alternative public title for this Group.'),
'required' => TRUE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'usage' => [
Expand All @@ -765,7 +774,6 @@ public static function &fields() {
'token' => FALSE,
],
'where' => 'civicrm_group.frontend_title',
'default' => NULL,
'table_name' => 'civicrm_group',
'entity' => 'Group',
'bao' => 'CRM_Contact_BAO_Group',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/CodeGen/GenerateData.php
Expand Up @@ -1141,7 +1141,7 @@ private function addGroup() {
// add the 3 groups first
foreach ($this->sampleData['group'] as $groupName) {
$group = new CRM_Contact_BAO_Group();
$group->name = $group->title = $groupName;
$group->name = $group->title = $group->frontend_title = $groupName;
$group->group_type = "12";
$group->visibility = 'Public Pages';
$group->is_active = 1;
Expand Down
6 changes: 4 additions & 2 deletions CRM/Core/I18n/SchemaStructure.php
Expand Up @@ -92,8 +92,8 @@ public static function &columns() {
'description' => "text COMMENT 'Optional description.'",
],
'civicrm_group' => [
'title' => "varchar(255) COMMENT 'Name of Group.'",
'frontend_title' => "varchar(255) DEFAULT NULL COMMENT 'Alternative public title for this Group.'",
'title' => "varchar(255) NOT NULL COMMENT 'Name of Group.'",
'frontend_title' => "varchar(255) NOT NULL COMMENT 'Alternative public title for this Group.'",
'frontend_description' => "text DEFAULT NULL COMMENT 'Alternative public description of the group.'",
],
'civicrm_contribution_page' => [
Expand Down Expand Up @@ -416,9 +416,11 @@ public static function &widgets() {
'civicrm_group' => [
'title' => [
'type' => "Text",
'required' => "true",
],
'frontend_title' => [
'type' => "Text",
'required' => "TRUE",
],
'frontend_description' => [
'type' => "TextArea",
Expand Down
4 changes: 2 additions & 2 deletions CRM/Group/Form/Edit.php
Expand Up @@ -62,13 +62,13 @@ class CRM_Group_Form_Edit extends CRM_Core_Form {
*/
protected function setEntityFields() {
$this->entityFields = [
'frontend_title' => ['name' => 'frontend_title', 'required' => TRUE],
'frontend_description' => ['name' => 'frontend_description'],
'title' => [
'name' => 'title',
'required' => TRUE,
],
'description' => ['name' => 'description'],
'frontend_title' => ['name' => 'frontend_title'],
'frontend_description' => ['name' => 'frontend_description'],
];
}

Expand Down
8 changes: 4 additions & 4 deletions CRM/Mailing/Event/BAO/MailingEventUnsubscribe.php
Expand Up @@ -278,18 +278,18 @@ public static function unsub_from_mailing($job_id, $queue_id, $hash, $return = F
}
while ($doAdded->fetch()) {
$returnGroups[$doAdded->group_id] = [
'title' => !empty($doAdded->frontend_title) ? $doAdded->frontend_title : $doAdded->title,
'description' => !empty($doAdded->frontend_description) ? $doAdded->frontend_description : $doAdded->description,
'title' => $doAdded->frontend_title,
'description' => $doAdded->frontend_description,
];
}
return $returnGroups;
}
else {
while ($doCached->fetch()) {
$groups[$doCached->group_id] = !empty($doCached->frontend_title) ? $doCached->frontend_title : $doCached->title;
$groups[$doCached->group_id] = $doCached->frontend_title;
}
while ($doAdded->fetch()) {
$groups[$doAdded->group_id] = !empty($doAdded->frontend_title) ? $doAdded->frontend_title : $doAdded->title;
$groups[$doAdded->group_id] = $doAdded->frontend_title;
}
}
$transaction = new CRM_Core_Transaction();
Expand Down
4 changes: 2 additions & 2 deletions CRM/Mailing/Form/Subscribe.php
Expand Up @@ -89,8 +89,8 @@ public function buildQuickForm() {
while ($dao->fetch()) {
$row = [];
$row['id'] = $dao->id;
$row['title'] = $dao->frontend_title ?? $dao->title;
$row['description'] = $dao->frontend_description ?? $dao->description;
$row['title'] = $dao->frontend_title;
$row['description'] = $dao->frontend_description;
$row['checkbox'] = CRM_Core_Form::CB_PREFIX . $row['id'];
$this->addElement('checkbox',
$row['checkbox'],
Expand Down
9 changes: 9 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveSixtyFour.php
Expand Up @@ -30,8 +30,17 @@ class CRM_Upgrade_Incremental_php_FiveSixtyFour extends CRM_Upgrade_Incremental_
public function upgrade_5_64_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Update post_URL/cancel_URL in logging tables', 'updateLogging');
$this->addTask('Make Group.name required', 'alterColumn', 'civicrm_group', 'name', "varchar(255) NOT NULL COMMENT 'Unique name for identifying contribution page'");
$this->addTask('Make Group.title required', 'alterColumn', 'civicrm_group', 'title', "varchar(255) NOT NULL COMMENT 'Contribution Page title. For top of page display'", TRUE);
$this->addTask('Make Group.frontend_title required', 'alterColumn', 'civicrm_group', 'frontend_title', "varchar(255) NOT NULL COMMENT 'Contribution Page Public title'", TRUE);
}

/**
* @param $ctx
*
* @return bool
* @throws \Civi\Core\Exception\DBQueryException
*/
public static function updateLogging($ctx): bool {
if (\Civi::settings()->get('logging')) {
$dsn = defined('CIVICRM_LOGGING_DSN') ? CRM_Utils_SQL::autoSwitchDSN(CIVICRM_LOGGING_DSN) : CRM_Utils_SQL::autoSwitchDSN(CIVICRM_DSN);
Expand Down
21 changes: 21 additions & 0 deletions CRM/Upgrade/Incremental/sql/5.64.alpha1.mysql.tpl
Expand Up @@ -6,3 +6,24 @@ ALTER TABLE civicrm_uf_group
CHANGE `post_URL` `post_url` varchar(255) DEFAULT NULL COMMENT 'Redirect to URL on submit.',
CHANGE `cancel_URL` `cancel_url` varchar(255) DEFAULT NULL COMMENT 'Redirect to URL when Cancel button clicked.'
;

-- Ensure new name field is not null/unique. Setting to ID is a bit lazy - but it works.
UPDATE civicrm_group SET `name` = `id` WHERE name IS NULL;

-- Add name field, make frontend_title required (in conjunction with php function)
{if $multilingual}
{foreach from=$locales item=locale}
UPDATE `civicrm_group`
SET `frontend_title_{$locale}` = `title_{$locale}`,
`frontend_description_{$locale}` = `description_{$locale}`
WHERE `frontend_description_{$locale}` IS NULL OR `frontend_description_{$locale}` = '';
{/foreach}
{else}
UPDATE `civicrm_group`
SET `frontend_title` = `title`
WHERE `frontend_title` IS NULL OR `frontend_title` = '';

UPDATE `civicrm_group`
SET `frontend_description` = `description`
WHERE `frontend_description` IS NULL OR `frontend_description` = '' AND description <> '';
{/if}
2 changes: 1 addition & 1 deletion Civi/Api4/Service/Spec/Provider/TitleFieldSpecProvider.php
Expand Up @@ -44,7 +44,7 @@ public function modifySpec(RequestSpec $spec): void {
* @inheritDoc
*/
public function applies($entity, $action): bool {
return in_array($entity, ['PaymentProcessor', 'ContributionPage']) && $action === 'create';
return in_array($entity, ['PaymentProcessor', 'ContributionPage', 'group']) && $action === 'create';
}

}
26 changes: 12 additions & 14 deletions templates/CRM/Group/Form/Edit.tpl
Expand Up @@ -22,31 +22,29 @@
</div>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
<table class="form-layout">
<tr class="crm-group-form-block-title">
<td class="label">{$form.title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_group' field='title' id=$group.id}{/if}</td>
<td>{$form.title.html|crmAddClass:huge}
{if !empty($group.saved_search_id)}&nbsp;({ts}Smart Group{/ts}){/if}
</td>
</tr>

<tr class="crm-group-form-block-description">
<td class="label">{$form.description.label}</td>
<td>{$form.description.html}</td>
</tr>

<tr><td colspan="2">{ts}If either of the following fields are filled out they will be used instead of the title or description field in profiles and Mailing List Subscription/unsubscribe forms{/ts}</td></tr>

<tr class="crm-group-form-block-frontend-title">
<td class="label">{$form.frontend_title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_group' field='frontend_title' id=$group.id}{/if}</td>
<td>{$form.frontend_title.html|crmAddClass:huge}
{if !empty($group.saved_search_id)}&nbsp;({ts}Smart Group{/ts}){/if}
{if !empty($group.saved_search_id)}&nbsp;({ts}Smart Group{/ts}){/if}
</td>
</tr>

<tr class="crm-group-form-block-frontend-description">
<td class="label">{$form.frontend_description.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_group' field='frontend_description' id=$group.id}{/if}</td>
<td>{$form.frontend_description.html}</td>
</tr>
<tr class="crm-group-form-block-title">
<td class="label">{$form.title.label} {if $action == 2}{include file='CRM/Core/I18n/Dialog.tpl' table='civicrm_group' field='title' id=$group.id}{/if}</td>
<td>{$form.title.html|crmAddClass:huge}
{if !empty($group.saved_search_id)}&nbsp;({ts}Smart Group{/ts}){/if}
</td>
</tr>

<tr class="crm-group-form-block-description">
<td class="label">{$form.description.label}</td>
<td>{$form.description.html}</td>
</tr>

{if !empty($form.group_type)}
<tr class="crm-group-form-block-group_type">
Expand Down
Expand Up @@ -5,4 +5,4 @@ INSERT INTO `civicrm_mapping_field` (`id`, `mapping_id`, `name`, `contact_type`,

INSERT INTO `civicrm_saved_search` (`id`, `form_values`, `mapping_id`, `search_custom_id`) VALUES (75, 'a:7:{s:5:"qfKey";s:32:"30ba24b74dd8ceb5710384b962004599";s:6:"mapper";a:2:{i:1;a:2:{i:0;a:3:{i:0;s:10:"Individual";i:1;s:5:"email";i:2;s:1:" ";}i:1;a:3:{i:0;s:10:"Individual";i:1;s:7:"on_hold";i:2;s:1:" ";}}i:2;a:1:{i:0;a:1:{i:0;s:0:"";}}}s:8:"operator";a:2:{i:1;a:2:{i:0;s:11:"IS NOT NULL";i:1;s:1:"=";}i:2;a:1:{i:0;s:0:"";}}s:5:"value";a:2:{i:1;a:2:{i:0;s:0:"";i:1;s:1:"1";}i:2;a:1:{i:0;s:0:"";}}s:4:"task";s:2:"13";s:8:"radio_ts";s:6:"ts_all";s:11:"uf_group_id";s:0:"";}', 149, NULL);

INSERT INTO `civicrm_group` (`id`, `name`, `title`, `description`, `source`, `saved_search_id`, `is_active`, `visibility`, `where_clause`, `select_tables`, `where_tables`, `group_type`, `cache_date`, `refresh_date`, `parents`, `children`, `is_hidden`, `is_reserved`, `created_id`) VALUES (242, '_Integrity__emails_on_hold', '@ Integrity - emails on hold', NULL, NULL, 75, 1, 'User and User Admin Only', ' ( `civicrm_group_contact_cache_242`.group_id = 242 ) ', 'a:10:{s:15:"civicrm_contact";i:1;s:15:"civicrm_address";i:1;s:22:"civicrm_state_province";i:1;s:15:"civicrm_country";i:1;s:13:"civicrm_email";i:1;s:13:"civicrm_phone";i:1;s:10:"civicrm_im";i:1;s:19:"civicrm_worldregion";i:1;s:33:"`civicrm_group_contact_cache_242`";s:136:" LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_242` ON contact_a.id = `civicrm_group_contact_cache_242`.contact_id ";s:6:"gender";i:1;}', 'a:2:{s:15:"civicrm_contact";i:1;s:33:"`civicrm_group_contact_cache_242`";s:136:" LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_242` ON contact_a.id = `civicrm_group_contact_cache_242`.contact_id ";}', NULL, NULL, NULL, NULL, NULL, 0, 0, NULL);
INSERT INTO `civicrm_group` (`id`, `name`, `title`, `frontend_title`, `description`, `source`, `saved_search_id`, `is_active`, `visibility`, `where_clause`, `select_tables`, `where_tables`, `group_type`, `cache_date`, `refresh_date`, `parents`, `children`, `is_hidden`, `is_reserved`, `created_id`) VALUES (242, '_Integrity__emails_on_hold', '@ Integrity - emails on hold','@ Integrity - emails on hold', NULL, NULL, 75, 1, 'User and User Admin Only', ' ( `civicrm_group_contact_cache_242`.group_id = 242 ) ', 'a:10:{s:15:"civicrm_contact";i:1;s:15:"civicrm_address";i:1;s:22:"civicrm_state_province";i:1;s:15:"civicrm_country";i:1;s:13:"civicrm_email";i:1;s:13:"civicrm_phone";i:1;s:10:"civicrm_im";i:1;s:19:"civicrm_worldregion";i:1;s:33:"`civicrm_group_contact_cache_242`";s:136:" LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_242` ON contact_a.id = `civicrm_group_contact_cache_242`.contact_id ";s:6:"gender";i:1;}', 'a:2:{s:15:"civicrm_contact";i:1;s:33:"`civicrm_group_contact_cache_242`";s:136:" LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_242` ON contact_a.id = `civicrm_group_contact_cache_242`.contact_id ";}', NULL, NULL, NULL, NULL, NULL, 0, 0, NULL);

0 comments on commit 75f450a

Please sign in to comment.