$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, 'Address', CRM_Utils_Array::value('id', $params), $params);
- // if id is set & is_primary isn't we can assume no change
- if (is_numeric(CRM_Utils_Array::value('is_primary', $params)) || empty($params['id'])) {
- CRM_Core_BAO_Block::handlePrimary($params, get_class());
- }
+ CRM_Core_BAO_Block::handlePrimary($params, get_class());
// (prevent chaining 1 and 3) CRM-21214
if (isset($params['master_id']) && !CRM_Utils_System::isNull($params['master_id'])) {
* @throws API_Exception
*/
public static function handlePrimary(&$params, $class) {
+ if (isset($params['id']) && CRM_Utils_System::isNull($params['is_primary'] ?? NULL)) {
+ // if id is set & is_primary isn't we can assume no change)
+ return;
+ }
$table = CRM_Core_DAO_AllCoreTables::getTableForClass($class);
if (!$table) {
throw new API_Exception("Failed to locate table for class [$class]");
* @return object
*/
public static function create($params) {
- // if id is set & is_primary isn't we can assume no change
- if (is_numeric(CRM_Utils_Array::value('is_primary', $params)) || empty($params['id'])) {
- CRM_Core_BAO_Block::handlePrimary($params, get_class());
- }
+ CRM_Core_BAO_Block::handlePrimary($params, get_class());
$hook = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($hook, 'Email', CRM_Utils_Array::value('id', $params), $params);
* @throws \API_Exception
*/
public static function add($params) {
- if (empty($params['id']) || is_numeric($params['is_primary'] ?? NULL)) {
- CRM_Core_BAO_Block::handlePrimary($params, __CLASS__);
- }
+ CRM_Core_BAO_Block::handlePrimary($params, __CLASS__);
return self::writeRecord($params);
}
* @throws \CRM_Core_Exception
*/
public static function add($params) {
- if (empty($params['id']) || is_numeric($params['is_primary'] ?? NULL)) {
- CRM_Core_BAO_Block::handlePrimary($params, __CLASS__);
- }
+ CRM_Core_BAO_Block::handlePrimary($params, __CLASS__);
return self::writeRecord($params);
}
*
* @param array $params
*
- * @return object
+ * @return \CRM_Core_DAO_Phone
+ *
* @throws API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function create($params) {
// Ensure mysql phone function exists
CRM_Core_DAO::checkSqlFunctionsExist();
-
- if (is_numeric(CRM_Utils_Array::value('is_primary', $params)) ||
- // if id is set & is_primary isn't we can assume no change
- empty($params['id'])
- ) {
- CRM_Core_BAO_Block::handlePrimary($params, get_class());
- }
+ CRM_Core_BAO_Block::handlePrimary($params, get_class());
return self::writeRecord($params);
}
*
* @return array
* array of phone objects
+ * @throws \CRM_Core_Exception
*/
public static function &getValues($entityBlock) {
$getValues = CRM_Core_BAO_Block::getValues('phone', $entityBlock);
protected $_params;
protected $_entity;
+ /**
+ * Should location types be checked to ensure primary addresses are correctly assigned after each test.
+ *
+ * @var bool
+ */
+ protected $isLocationTypesOnPostAssert = TRUE;
+
public function setUp() {
$this->_entity = 'Phone';
parent::setUp();
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType,
'phone' => '(123) 456-7890',
- 'is_primary' => 1,
+ 'is_primary' => TRUE,
'phone_type_id' => 1,
];
}
/**
* @param int $version
+ *
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
public function testCreatePhone($version) {
$this->_apiversion = $version;
- $result = $this->callAPIAndDocument('phone', 'create', $this->_params, __FUNCTION__, __FILE__);
+ $result = $this->callAPIAndDocument('Phone', 'create', $this->_params, __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$this->assertNotNull($result['values'][$result['id']]['id']);
* the LocationType default
*
* @param int $version
+ *
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
public function testCreatePhoneDefaultLocation($version) {
$this->_apiversion = $version;
/**
* @param int $version
+ *
* @dataProvider versionThreeAndFour
+ * @throws \CRM_Core_Exception
*/
public function testCreatePhonePrimaryHandlingChangeExisting($version) {
$this->_apiversion = $version;
$phone1 = $this->callAPISuccess('phone', 'create', $this->_params);
- $phone2 = $this->callAPISuccess('phone', 'create', $this->_params);
+ $this->callAPISuccess('phone', 'create', $this->_params);
$check = $this->callAPISuccess('phone', 'getcount', [
'is_primary' => 1,
'contact_id' => $this->_contactID,
]);
$this->assertEquals(1, $check);
+ $this->callAPISuccess('Phone', 'create', ['id' => $phone1['id'], 'is_primary' => TRUE]);
}
}