Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#1936 Make the price field value label field not required #18123

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CRM/Core/I18n/SchemaStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static function &columns() {
'help_post' => "text COMMENT 'Description and/or help text to display after this field.'",
],
'civicrm_price_field_value' => [
'label' => "varchar(255) NOT NULL COMMENT 'Price field option label'",
'label' => "varchar(255) DEFAULT NULL COMMENT 'Price field option label'",
'description' => "text DEFAULT NULL COMMENT 'Price field option description.'",
'help_pre' => "text DEFAULT NULL COMMENT 'Price field option pre help text.'",
'help_post' => "text DEFAULT NULL COMMENT 'Price field option post field help.'",
Expand Down Expand Up @@ -586,7 +586,6 @@ public static function &widgets() {
'civicrm_price_field_value' => [
'label' => [
'type' => "Text",
'required' => "true",
],
'description' => [
'type' => "TextArea",
Expand Down
6 changes: 3 additions & 3 deletions CRM/Price/DAO/PriceFieldValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Price/PriceFieldValue.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:28432a14b1b1523380eb41e8e481037d)
* (GenCodeChecksum:11a02f3576be10e8c2a0ea47a19e2dac)
*/

/**
Expand Down Expand Up @@ -226,10 +226,10 @@ public static function &fields() {
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Name'),
'description' => ts('Price field option name'),
'required' => TRUE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_price_field_value.name',
'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
Expand All @@ -244,10 +244,10 @@ public static function &fields() {
'type' => CRM_Utils_Type::T_STRING,
'title' => ts('Label'),
'description' => ts('Price field option label'),
'required' => TRUE,
'maxlength' => 255,
'size' => CRM_Utils_Type::HUGE,
'where' => 'civicrm_price_field_value.label',
'default' => 'NULL',
'table_name' => 'civicrm_price_field_value',
'entity' => 'PriceFieldValue',
'bao' => 'CRM_Price_BAO_PriceFieldValue',
Expand Down
29 changes: 29 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveTwentyNine.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,35 @@ public function upgrade_5_29_alpha1($rev) {
}
}

/**
* Upgrade function.
*
* @param string $rev
*/
public function upgrade_5_29_beta1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Make label field non required on price field value', 'priceFieldValueLabelNonRequired');
}

/**
* Make the price field value label column non required
* @return bool
*/
public static function priceFieldValueLabelNonRequired() {
$locales = CRM_Core_I18n::getMultilingual();
if ($locales) {
foreach ($locales as $locale) {
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_price_field_value CHANGE `label_{$locale}` `label_{$locale}` varchar(255) DEFAULT NULL COMMENT 'Price field option label'", [], TRUE, NULL, FALSE, FALSE);
CRM_Core_DAO::executeQuery("UPDATE civicrm_price_field_value SET label_{$locale} = NULL WHERE label_{$locale} = 'null'", [], TRUE, NULL, FALSE, FALSE);
}
}
else {
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_price_field_value CHANGE `label` `label` varchar(255) DEFAULT NULL COMMENT 'Price field option label'", [], TRUE, NULL, FALSE, FALSE);
CRM_Core_DAO::executeQuery("UPDATE civicrm_price_field_value SET label = NULL WHERE label = 'null'", [], TRUE, NULL, FALSE, FALSE);
}
return TRUE;
}

/**
* Install sequentialCreditNotes extension.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class PriceFieldValueCreationSpecProvider implements Generic\SpecProviderInterfa
public function modifySpec(RequestSpec $spec) {
// Name will be auto-generated from label if not supplied
$spec->getFieldByName('name')->setRequired(FALSE);
// Ensure that label is required this matches v3 API but doesn't match DAO because form fields allow for NULLs
$spec->getFieldByName('label')->setRequired(TRUE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 so I'm inclined to go with it not being required in either api - I think the reason it was required was nasty munging behaviour. If that's hard to deal with I'm OK with apiv4 not matching v3 - as long as v4 is 'right'

(am also OK punting that for master)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea but it seems it has been required in the API since v4.5 e825f02 so it would feel very strange to break that but maybe its ok for v4. Also the JIRA mentioned in that commit looks wrong https://issues.civicrm.org/jira/browse/CRM-14788. I would say keep label required for the moment and can manage in master

}

/**
Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/CRM/Price/BAO/PriceFieldValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,43 @@ public function testVisibilityFieldExists() {
$this->assertEquals('visibility', $fields['visibility_id']['pseudoconstant']['optionGroupName']);
}

public function testEmptyStringLabel() {
// Put stuff here that should happen before all tests in this unit.
$priceSetParams = [
'name' => 'default_goat_priceset',
'title' => 'Goat accommodation',
'is_active' => 1,
'help_pre' => "Where does your goat sleep",
'help_post' => "thank you for your time",
'extends' => 2,
'financial_type_id' => 1,
'is_quick_config' => 1,
'is_reserved' => 1,
];

$price_set = $this->callAPISuccess('price_set', 'create', $priceSetParams);
$this->priceSetID = $price_set['id'];

$priceFieldParams = [
'price_set_id' => $this->priceSetID,
'name' => 'grassvariety',
'label' => 'Grass Variety',
'html_type' => 'Text',
'is_enter_qty' => 1,
'is_active' => 1,
];
$priceField = $this->callAPISuccess('price_field', 'create', $priceFieldParams);
$this->priceFieldID = $priceField['id'];
$this->_params = [
'price_field_id' => $this->priceFieldID,
'name' => 'rye_grass',
'label' => '',
'amount' => 1,
'financial_type_id' => 1,
];
$priceFieldValue = CRM_Price_BAO_PriceFieldValue::create($this->_params);
$priceFieldValue->find(TRUE);
$this->assertEquals('', $priceFieldValue->label);
}

}
4 changes: 2 additions & 2 deletions xml/schema/Price/PriceFieldValue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
<title>Name</title>
<length>255</length>
<comment>Price field option name</comment>
<required>true</required>
<html>
<type>Text</type>
</html>
<add>3.3</add>
<default>NULL</default>
</field>
<field>
<name>label</name>
Expand All @@ -50,11 +50,11 @@
<length>255</length>
<localizable>true</localizable>
<comment>Price field option label</comment>
<required>true</required>
<html>
<type>Text</type>
</html>
<add>3.3</add>
<default>NULL</default>
</field>
<field>
<name>description</name>
Expand Down