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

[REF] clarify variable (very minor change with good test cover) #14724

Merged
merged 1 commit into from
Jul 4, 2019
Merged
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
17 changes: 8 additions & 9 deletions CRM/Core/BAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,8 @@ public static function dataToHtml() {
*/
public static function create($params) {
$transaction = new CRM_Core_Transaction();
$op = empty($params['id']) ? 'create' : 'edit';
$origParams = array_merge([], $params);
$params = self::prepareCreate($params, $op);
$params = self::prepareCreate($params);

$customField = new CRM_Core_DAO_CustomField();
$customField->copyValues($params);
Expand All @@ -166,13 +165,14 @@ public static function create($params) {

$triggerRebuild = CRM_Utils_Array::value('triggerRebuild', $params, TRUE);
//create/drop the index when we toggle the is_searchable flag
if ($op == 'edit') {
$op = empty($params['id']) ? 'add' : 'modify';
if ($op == 'modify') {
$indexExist = FALSE;
//as during create if field is_searchable we had created index.
if (!empty($params['id'])) {
$indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable');
}
self::createField($customField, 'modify', $indexExist, $triggerRebuild);
self::createField($customField, $op, $indexExist, $triggerRebuild);
}
else {
if (!isset($origParams['column_name'])) {
Expand All @@ -183,13 +183,13 @@ public static function create($params) {
// make sure all values are present in the object
$customField->find(TRUE);

self::createField($customField, 'add', FALSE, $triggerRebuild);
self::createField($customField, $op, FALSE, $triggerRebuild);
}

// complete transaction
$transaction->commit();

CRM_Utils_Hook::post($op, 'CustomField', $customField->id, $customField);
CRM_Utils_Hook::post(($op === 'add' ? 'create' : 'edit'), 'CustomField', $customField->id, $customField);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use same concept here?
empty($params['id']) ? 'create' : 'edit';

Since hook_pre() allows once to change the $params and its possible that one can set $params['id'](very rare case though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pradpnayak I thought about your comment here but in other BAO the op is determined before calling the 'pre' hook & retained for the post hook so that would be inconsistent with other BAO. I am going to add some code comments but to a subsequent PR as they need rebasing after the merges that have been done so far


CRM_Utils_System::flushCache();

Expand Down Expand Up @@ -1915,12 +1915,11 @@ protected static function createOptionValue(&$params, $value, CRM_Core_DAO_Optio
* This could be called by a single create or a batchCreate.
*
* @param array $params
* @param string $op
*
* @return array
*/
protected static function prepareCreate($params, $op) {

protected static function prepareCreate($params) {
$op = empty($params['id']) ? 'create' : 'edit';
CRM_Utils_Hook::pre($op, 'CustomField', CRM_Utils_Array::value('id', $params), $params);
if ($op === 'create') {
CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
Expand Down