From: Eileen McNaughton Date: Tue, 3 Jun 2014 11:14:40 +0000 (+1200) Subject: CRM-14778 handle missing name field X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e0c1764e1a3b85805c18e592dfe1b27fed5fea4a;p=civicrm-core.git CRM-14778 handle missing name field --- diff --git a/CRM/Price/BAO/PriceField.php b/CRM/Price/BAO/PriceField.php index 7b4ebb81f3..89598bf8c6 100644 --- a/CRM/Price/BAO/PriceField.php +++ b/CRM/Price/BAO/PriceField.php @@ -56,7 +56,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField { * @access public * @static */ - static function &add(&$params) { + static function add(&$params) { $priceFieldBAO = new CRM_Price_BAO_PriceField(); $priceFieldBAO->copyValues($params); @@ -90,7 +90,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField { return $priceField; } - $options = $optionsIds = array(); + $optionsIds = array(); $maxIndex = CRM_Price_Form_Field::NUM_OPTION; if ($priceField->html_type == 'Text') { diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 2f069a1072..c22510487a 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -56,6 +56,9 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { * @static */ static function create(&$params) { + if(empty($params['id']) && empty($params['name'])) { + $params['name'] = CRM_Utils_String::munge($params['title'], '_', 242); + } $priceSetBAO = new CRM_Price_BAO_PriceSet(); $priceSetBAO->copyValues($params); if (self::eventPriceSetDomainID()) { @@ -104,17 +107,16 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { * * @param string $entity * - * @return id $priceSetID + * @return array $defaultPriceSet default price set * * @access public * @static * */ public static function getDefaultPriceSet($entity = 'contribution') { - if ($entity == 'contribution') { - $entityName = 'default_contribution_amount'; - } - else if ($entity == 'membership') { + + $entityName = 'default_contribution_amount'; + if ($entity == 'membership') { $entityName = 'default_membership_type_amount'; } @@ -158,7 +160,7 @@ WHERE ps.name = '{$entityName}' * Return a list of all forms which use this price set. * * @param int $id id of price set - * @param bool|\str $simpleReturn - get raw data. Possible values: 'entity', 'table' + * @param bool|string $simpleReturn - get raw data. Possible values: 'entity', 'table' * * @return array */ @@ -384,13 +386,13 @@ WHERE ct.id = cp.financial_type_id AND } /** - * Find a price_set_id associatied with the given option value or field ID + * Find a price_set_id associated with the given option value or field ID * * @param array $params (reference) an assoc array of name/value pairs * array may contain either option id or * price field id * - * @return price set id on success, null otherwise + * @return integer|NULL price set id on success, null otherwise * @static * @access public */ @@ -474,7 +476,6 @@ WHERE ct.id = cp.financial_type_id AND public static function getSetDetail($setID, $required = TRUE, $validOnly = FALSE) { // create a new tree $setTree = array(); - $select = $from = $where = $orderBy = ''; $priceFields = array( 'id', @@ -560,7 +561,7 @@ WHERE id = %1"; } /** - * @param $form + * @param CRM_Core_Form $form * @param $id * @param string $entityTable * @param bool $validOnly @@ -809,7 +810,7 @@ WHERE id = %1"; /** * Function to build the price set form. * - * @param $form + * @param CRM_Core_Form $form * * @return void * @access public @@ -955,7 +956,7 @@ WHERE id = %1"; /** * Get field ids of a price set * - * @param int id Price Set id + * @param int $id Price Set id * * @return array of the field ids * @@ -1234,18 +1235,16 @@ WHERE ps.id = %1 return false; } - /* + /** * Copy priceSet when event/contibution page is copied * * @params string $baoName BAO name * @params int $id old event/contribution page id * @params int $newId newly created event/contribution page id * - */ - /** - * @param $baoName - * @param $id - * @param $newId + * @param string $baoName + * @param integer $id + * @param integer $newId */ static function copyPriceSet($baoName, $id, $newId) { $priceSetId = CRM_Price_BAO_PriceSet::getFor($baoName, $id); diff --git a/api/v3/PriceSet.php b/api/v3/PriceSet.php index 2a1635c636..4e4b0aa5a6 100644 --- a/api/v3/PriceSet.php +++ b/api/v3/PriceSet.php @@ -71,6 +71,7 @@ function civicrm_api3_price_set_create($params) { * @param array $params array or parameters determined by getfields */ function _civicrm_api3_price_set_create_spec(&$params) { + $params['title']['api.required'] = TRUE; } /** diff --git a/tests/phpunit/api/v3/PriceSetTest.php b/tests/phpunit/api/v3/PriceSetTest.php index e56f68dcbe..63edd734f1 100644 --- a/tests/phpunit/api/v3/PriceSetTest.php +++ b/tests/phpunit/api/v3/PriceSetTest.php @@ -58,6 +58,9 @@ class api_v3_PriceSetTest extends CiviUnitTestCase { function tearDown() { } + /** + * + */ public function testCreatePriceSet() { $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); @@ -65,6 +68,18 @@ class api_v3_PriceSetTest extends CiviUnitTestCase { $this->getAndCheck($this->_params, $result['id'], $this->_entity); } + /** + * Check that no name doesn't cause failure + */ + public function testCreatePriceSetNoName() { + $params = $this->_params; + unset($params['name']); + $result = $this->callAPISuccess($this->_entity, 'create', $params); + } + + /** + * + */ public function testGetBasicPriceSet() { $getParams = array( 'name' => 'default_contribution_amount',