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 Jul 9, 2023
1 parent f600453 commit 0950075
Show file tree
Hide file tree
Showing 14 changed files with 88 additions and 40 deletions.
13 changes: 7 additions & 6 deletions CRM/Contact/BAO/Group.php
Expand Up @@ -342,6 +342,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 @@ -1091,12 +1096,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
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
2 changes: 1 addition & 1 deletion CRM/Upgrade/Incremental/MessageTemplates.php
Expand Up @@ -351,7 +351,7 @@ protected function getTemplateUpdates() {
],
],
[
'version' => '5.56.alpha1',
'version' => '5.65.alpha1',
'upgrade_descriptor' => ts('Update to use tokens'),
'templates' => [
['name' => 'petition_sign', 'type' => 'text'],
Expand Down
5 changes: 5 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveSixtyFive.php
Expand Up @@ -29,6 +29,11 @@ class CRM_Upgrade_Incremental_php_FiveSixtyFive extends CRM_Upgrade_Incremental_
*/
public function upgrade_5_65_alpha1($rev): void {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
// These 3 should run after the sql file.
$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);

}

}
7 changes: 6 additions & 1 deletion CRM/Upgrade/Incremental/php/FiveSixtyFour.php
Expand Up @@ -33,9 +33,14 @@ public function upgrade_5_64_alpha1($rev): void {
$this->addTask('Drop unused civicrm_action_mapping table', 'dropTable', 'civicrm_action_mapping');
$this->addTask('Update post_URL/cancel_URL in logging tables', 'updateLogging');
$this->addTask('Add in Everybody ACL Role option value', 'addEveryBodyAclOptionValue');
$this->addTask('Fix double json encoding of accepted_credit_cards field in payment processor table', 'fixDoubleEscapingPaymentProcessorCreditCards');
}

/**
* @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
24 changes: 24 additions & 0 deletions CRM/Upgrade/Incremental/sql/5.65.alpha1.mysql.tpl
@@ -1 +1,25 @@
{* file to handle db changes in 5.65.alpha1 during upgrade *}

-- 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}`,
WHERE `frontend_title_{$locale}` IS NULL OR `frontend_title_{$locale}` = '';

UPDATE `civicrm_group`
SET `frontend_description_{$locale}` = `description_{$locale}`,
WHERE `frontend_description_{$locale}` IS NULL OR `frontend_description_{$locale}` = '' AND '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 CRM/Utils/Token.php
Expand Up @@ -926,7 +926,7 @@ public static function &replaceSubscribeInviteTokens($str) {
/**
* Replace welcome/confirmation tokens
*
* @deprecated since 5.64 will be removed around 5.70
* @deprecated since 5.65 will be removed around 5.71
*
* @param string $str
* The string with tokens to be replaced.
Expand Down
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
7 changes: 6 additions & 1 deletion xml/schema/Contact/Group.xml
Expand Up @@ -35,6 +35,7 @@
<type>varchar</type>
<title>Group Name</title>
<length>64</length>
<required>true</required>
<comment>Internal name of Group.</comment>
<add>1.1</add>
</field>
Expand All @@ -43,6 +44,7 @@
<type>varchar</type>
<title>Group Title</title>
<length>255</length>
<required>true</required>
<localizable>true</localizable>
<comment>Name of Group.</comment>
<add>1.1</add>
Expand Down Expand Up @@ -121,6 +123,7 @@
<title>Group Where Clause</title>
<comment>the sql where clause if a saved search acl</comment>
<readonly>true</readonly>
<deprecated>true</deprecated>
<add>1.6</add>
</field>
<field>
Expand All @@ -130,11 +133,13 @@
<comment>the tables to be included in a select data</comment>
<readonly>true</readonly>
<serialize>PHP</serialize>
<deprecated>true</deprecated>
<add>1.6</add>
</field>
<field>
<name>where_tables</name>
<type>text</type>
<deprecated>true</deprecated>
<title>Tables For Where Clause</title>
<comment>the tables to be included in the count statement</comment>
<readonly>true</readonly>
Expand Down Expand Up @@ -295,7 +300,7 @@
<length>255</length>
<localizable>true</localizable>
<comment>Alternative public title for this Group.</comment>
<default>NULL</default>
<required>TRUE</required>
<add>5.31</add>
<html>
<type>Text</type>
Expand Down

0 comments on commit 0950075

Please sign in to comment.