Commit 351e8d47 authored by eileen's avatar eileen

Set ContactType.name as required in the schema.

I came across this weird WHERE clause & I'm pretty sure it's compensating for a mistake in the schema

I also set what I think are sensible defaults on is_reserved & is_active
parent 7c907de0
......@@ -121,9 +121,7 @@ class CRM_Admin_Form_ContactType extends CRM_Admin_Form {
$params['is_active'] = 1;
}
}
if ($this->_action & CRM_Core_Action::ADD) {
$params['name'] = ucfirst(CRM_Utils_String::munge($params['label']));
}
$contactType = CRM_Contact_BAO_ContactType::add($params);
CRM_Core_Session::setStatus(ts("The Contact Type '%1' has been saved.",
[1 => $contactType->label]
......
......@@ -240,9 +240,8 @@ WHERE subtype.name IS NOT NULL AND subtype.parent_id IS NOT NULL {$ctWHERE}
$sql = '
SELECT type.*, parent.name as parent, parent.label as parent_label
FROM civicrm_contact_type type
LEFT JOIN civicrm_contact_type parent ON type.parent_id = parent.id
WHERE type.name IS NOT NULL
';
LEFT JOIN civicrm_contact_type parent ON type.parent_id = parent.id';
if ($all === FALSE) {
$sql .= ' AND type.is_active = 1';
}
......@@ -581,8 +580,12 @@ WHERE name = %1';
// label or name
if (empty($params['id']) && empty($params['label'])) {
// @todo consider throwing exception instead.
return NULL;
}
if (empty($params['id']) && empty($params['name'])) {
$params['name'] = ucfirst(CRM_Utils_String::munge($params['label']));
}
if (!empty($params['parent_id']) &&
!CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $params['parent_id'])
) {
......@@ -592,7 +595,6 @@ WHERE name = %1';
$contactType = new CRM_Contact_DAO_ContactType();
$contactType->copyValues($params);
$contactType->id = $params['id'] ?? NULL;
$contactType->is_active = CRM_Utils_Array::value('is_active', $params, 0);
$contactType->save();
if ($contactType->find(TRUE)) {
......@@ -604,7 +606,7 @@ WHERE name = %1';
if (!empty($params['id'])) {
$newParams = [
'label' => ts("New %1", [1 => $contact]),
'is_active' => $active,
'is_active' => $contactType->is_active,
];
CRM_Core_BAO_Navigation::processUpdate(['name' => "New $contactName"], $newParams);
}
......
......@@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Contact/ContactType.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:41e6919118b3b6fd2da46ce6aba1da8b)
* (GenCodeChecksum:32038ad57ffa86a8e233d1d337d69f20)
*/
/**
......@@ -139,6 +139,7 @@ class CRM_Contact_DAO_ContactType extends CRM_Core_DAO {
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Name'),
'description' => ts('Internal name of Contact Type (or Subtype).'),
'required' => TRUE,
'maxlength' => 64,
'size' => CRM_Utils_Type::BIG,
'where' => 'civicrm_contact_type.name',
......@@ -213,6 +214,7 @@ class CRM_Contact_DAO_ContactType extends CRM_Core_DAO {
'title' => ts('Contact Type Is Active?'),
'description' => ts('Is this entry active?'),
'where' => 'civicrm_contact_type.is_active',
'default' => '1',
'table_name' => 'civicrm_contact_type',
'entity' => 'ContactType',
'bao' => 'CRM_Contact_BAO_ContactType',
......@@ -224,6 +226,7 @@ class CRM_Contact_DAO_ContactType extends CRM_Core_DAO {
'title' => ts('Contact Type is Reserved?'),
'description' => ts('Is this contact type a predefined system type'),
'where' => 'civicrm_contact_type.is_reserved',
'default' => '0',
'table_name' => 'civicrm_contact_type',
'entity' => 'ContactType',
'bao' => 'CRM_Contact_BAO_ContactType',
......
......@@ -3,3 +3,6 @@
-- https://github.com/civicrm/civicrm-core/pull/17450
ALTER TABLE `civicrm_activity` CHANGE `activity_date_time` `activity_date_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date and time this activity is scheduled to occur. Formerly named scheduled_date_time.';
ALTER TABLE `civicrm_activity` CHANGE `created_date` `created_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'When was the activity was created.';
-- https://github.com/civicrm/civicrm-core/pull/17548
ALTER table civicrm_contact_type modify name varchar(64) not null comment 'Internal name of Contact Type (or Subtype).';
This diff is collapsed.
......@@ -24,6 +24,7 @@
<length>64</length>
<comment>Internal name of Contact Type (or Subtype).</comment>
<add>3.1</add>
<required>true</required>
</field>
<index>
<name>contact_type</name>
......@@ -84,6 +85,7 @@
<name>is_active</name>
<title>Contact Type Is Active?</title>
<type>boolean</type>
<default>1</default>
<comment>Is this entry active?</comment>
<add>3.1</add>
</field>
......@@ -91,6 +93,7 @@
<name>is_reserved</name>
<title>Contact Type is Reserved?</title>
<type>boolean</type>
<default>0</default>
<comment>Is this contact type a predefined system type</comment>
<add>3.1</add>
</field>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment