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 16, 2023
1 parent 34558a5 commit 138e389
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
8 changes: 2 additions & 6 deletions CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -1105,12 +1105,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion CRM/Group/Form/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function setEntityFields() {
'required' => TRUE,
],
'description' => ['name' => 'description'],
'frontend_title' => ['name' => 'frontend_title'],
'frontend_title' => ['name' => 'frontend_title', 'required' => TRUE],
'frontend_description' => ['name' => 'frontend_description'],
];
}
Expand Down
4 changes: 4 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveSixtyFour.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ 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('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);

}

}
16 changes: 16 additions & 0 deletions CRM/Upgrade/Incremental/sql/5.64.alpha1.mysql.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@ 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}`
WHERE `frontend_title_{$locale}` IS NULL OR `frontend_title_{$locale}` = '';
{/foreach}
{else}
UPDATE `civicrm_group`
SET `frontend_title` = `title`
WHERE `frontend_title` IS NULL OR `frontend_title` = '';
{/if}
7 changes: 6 additions & 1 deletion xml/schema/Contact/Group.xml
Original file line number Diff line number Diff line change
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 138e389

Please sign in to comment.