Skip to content

Commit

Permalink
Merge pull request #18128 from civicrm/5.29
Browse files Browse the repository at this point in the history
5.29
  • Loading branch information
seamuslee001 authored Aug 12, 2020
2 parents 0dcdc38 + 520d760 commit 0a2a7ca
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 7 deletions.
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
11 changes: 11 additions & 0 deletions CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,17 @@ public static function moveContactBelongings($mergeHandler, $tables, $tableOpera
continue;
}

if ($table === 'civicrm_setting') {
// Per https://lab.civicrm.org/dev/core/-/issues/1934
// Note this line is not unit tested as yet as a quick-fix for a regression
// but it would be better to do a SELECT request & only update if needed (as a general rule
// more selects & less UPDATES will result in less deadlocks while de-duping.
// Note the delete is not important here - it can stay with the deleted contact on the
// off chance they get restored.
$sqls[] = "UPDATE IGNORE civicrm_setting SET contact_id = $mainId WHERE contact_id = $otherId";
continue;
}

// use UPDATE IGNORE + DELETE query pair to skip on situations when
// there's a UNIQUE restriction on ($field, some_other_field) pair
if (isset($cidRefs[$table])) {
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);
}

/**
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

0 comments on commit 0a2a7ca

Please sign in to comment.