Skip to content

Commit

Permalink
WIP Delete unused upgrade code
Browse files Browse the repository at this point in the history
  • Loading branch information
mflandorfer committed Jul 11, 2024
1 parent 06c9d6e commit 98b138d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 181 deletions.
155 changes: 0 additions & 155 deletions CRM/Contract/CustomData.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,161 +47,6 @@ protected function log($level, $message) {
}
}

/**
* will take a JSON source file and synchronise the
* generic entity data with those specs
*/
public function syncEntities($source_file) {
$data = json_decode(file_get_contents($source_file), TRUE);
if (empty($data)) {
throw new Exception("syncEntities: Invalid specs");
}

foreach ($data['_entities'] as $entity_data) {
$this->translateStrings($entity_data);
$entity = $this->identifyEntity($data['entity'], $entity_data);

if (empty($entity)) {
// create OptionValue
$entity = $this->createEntity($data['entity'], $entity_data);
} elseif ($entity == 'FAILED') {
// Couldn't identify:
$this->log(CUSTOM_DATA_HELPER_LOG_ERROR, "Couldn't create/update {$data['entity']}: " . json_encode($entity_data));
} else {
// update OptionValue
$this->updateEntity($data['entity'], $entity_data, $entity);
}
}
}

/**
* will take a JSON source file and synchronise the
* OptionGroup/OptionValue data in the system with
* those specs
*/
public function syncOptionGroup($source_file) {
$data = json_decode(file_get_contents($source_file), TRUE);
if (empty($data)) {
throw new Exception("syncOptionGroup: Invalid specs");
}

// first: find or create option group
$this->translateStrings($data);
$optionGroup = $this->identifyEntity('OptionGroup', $data);
if (empty($optionGroup)) {
// create OptionGroup
$optionGroup = $this->createEntity('OptionGroup', $data);
} elseif ($optionGroup == 'FAILED') {
// Couldn't identify:
$this->log(CUSTOM_DATA_HELPER_LOG_ERROR, "Couldn't create/update OptionGroup: " . json_encode($data));
return;
} else {
// update OptionGroup
$this->updateEntity('OptionGroup', $data, $optionGroup, array('is_active'));
}

// now run the update for the OptionValues
foreach ($data['_values'] as $optionValueSpec) {
$this->translateStrings($optionValueSpec);
$optionValueSpec['option_group_id'] = $optionGroup['id'];
$optionValueSpec['_lookup'][] = 'option_group_id';
$optionValue = $this->identifyEntity('OptionValue', $optionValueSpec);

if (empty($optionValue)) {
// create OptionValue
$optionValue = $this->createEntity('OptionValue', $optionValueSpec);
} elseif ($optionValue == 'FAILED') {
// Couldn't identify:
$this->log(CUSTOM_DATA_HELPER_LOG_ERROR, "Couldn't create/update OptionValue: " . json_encode($optionValueSpec));
} else {
// update OptionValue
$this->updateEntity('OptionValue', $optionValueSpec, $optionValue, array('is_active'));
}
}
}


/**
* will take a JSON source file and synchronise the
* CustomGroup/CustomField data in the system with
* those specs
*/
public function syncCustomGroup($source_file) {
$force_update = FALSE;
$data = json_decode(file_get_contents($source_file), TRUE);
if (empty($data)) {
throw new Exception("CRM_Utils_CustomData::syncCustomGroup: Invalid custom specs");
}

// if extends_entity_column_value, make sure it's sensible data
if (isset($data['extends_entity_column_value'])) {
$force_update = TRUE; // this doesn't get returned by the API, so differences couldn't be detected
if ($data['extends'] == 'Activity') {
$extends_list = array();
foreach ($data['extends_entity_column_value'] as $activity_type) {
if (!is_numeric($activity_type)) {
$activity_type = CRM_Core_PseudoConstant::getKey(
'CRM_Activity_BAO_Activity',
'activity_type_id',
$activity_type
);
}
if ($activity_type) {
$extends_list[] = $activity_type;
}
}
$data['extends_entity_column_value'] = $extends_list;
}

if (is_array($data['extends_entity_column_value'])) {
$data['extends_entity_column_value'] = CRM_Utils_Array::implodePadded($data['extends_entity_column_value']);
}
}


// first: find or create custom group
$this->translateStrings($data);
$customGroup = $this->identifyEntity('CustomGroup', $data);
if (empty($customGroup)) {
// create CustomGroup
$customGroup = $this->createEntity('CustomGroup', $data);
} elseif ($customGroup == 'FAILED') {
// Couldn't identify:
$this->log(CUSTOM_DATA_HELPER_LOG_ERROR, "Couldn't create/update CustomGroup: " . json_encode($data));
return;
} else {
// update CustomGroup
$this->updateEntity('CustomGroup', $data, $customGroup, array('extends', 'style', 'is_active', 'title', 'extends_entity_column_value'), $force_update);
}

// now run the update for the CustomFields
foreach ($data['_fields'] as $customFieldSpec) {
$this->translateStrings($customFieldSpec);
$customFieldSpec['custom_group_id'] = $customGroup['id'];
$customFieldSpec['_lookup'][] = 'custom_group_id';
if (!empty($customFieldSpec['option_group_id']) && !is_numeric($customFieldSpec['option_group_id'])) {
// look up custom group id
$optionGroup = $this->getEntityID('OptionGroup', array('name' => $customFieldSpec['option_group_id']));
if ($optionGroup == 'FAILED' || $optionGroup==NULL) {
$this->log(CUSTOM_DATA_HELPER_LOG_ERROR, "Couldn't create/update CustomField, bad option_group: {$customFieldSpec['option_group_id']}");
return;
}
$customFieldSpec['option_group_id'] = $optionGroup['id'];
}
$customField = $this->identifyEntity('CustomField', $customFieldSpec);
if (empty($customField)) {
// create CustomField
$customField = $this->createEntity('CustomField', $customFieldSpec);
} elseif ($customField == 'FAILED') {
// Couldn't identify:
$this->log(CUSTOM_DATA_HELPER_LOG_ERROR, "Couldn't create/update CustomField: " . json_encode($customFieldSpec));
} else {
// update CustomField
$this->updateEntity('CustomField', $customFieldSpec, $customField, array('in_selector', 'is_view', 'is_searchable', 'html_type', 'data_type', 'custom_group_id'));
}
}
}

/**
* return the ID of the given entity (if exists)
*/
Expand Down
26 changes: 0 additions & 26 deletions CRM/Contract/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public function install() {
}

public function enable() {
require_once 'CRM/Contract/CustomData.php';
$customData = new CRM_Contract_CustomData('de.systopia.contract');

// create sub-type 'Dialoger'
$dialoger_exists = civicrm_api3('ContactType', 'getcount', ['name' => 'Dialoger']);
if (!$dialoger_exists) {
Expand All @@ -41,18 +38,6 @@ public function postInstall() {
public function uninstall() {
}

/**
* Add custom field "defer_payment_start"
*
* @return TRUE on success
* @throws Exception
*/
public function upgrade_1360() {
$this->ctx->log->info('Applying update 1360');
$customData = new CRM_Contract_CustomData('de.systopia.contract');
return TRUE;
}

public function upgrade_1370() {
$this->ctx->log->info('Applying update 1370');
$this->executeSqlFile('sql/contract.sql');
Expand All @@ -66,12 +51,6 @@ public function upgrade_1390() {
return TRUE;
}

public function upgrade_1402() {
$this->ctx->log->info('Applying updates for 14xx');
$customData = new CRM_Contract_CustomData('de.systopia.contract');
return TRUE;
}

/**
* Convert scheduled legacy update activities by adding ch_payment_changes
*
Expand Down Expand Up @@ -118,9 +97,4 @@ public function upgrade_1500() {
return TRUE;
}

public function upgrade_1510() {
$this->ctx->log->info('Applying update 1510');
$customData = new CRM_Contract_CustomData('de.systopia.contract');
return TRUE;
}
}

0 comments on commit 98b138d

Please sign in to comment.