Skip to content

Commit

Permalink
Update modules: features, webform_civicrm
Browse files Browse the repository at this point in the history
  • Loading branch information
herbdool committed Dec 7, 2020
1 parent 265eae9 commit 4f3129c
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,6 @@ function features_set_signature($module, $component, $signature = NULL, $message
* that were using a -dev branch after 7.x-2.11.
* Since #3162854, it is stored in a dedicated non-cache table.
*
* @param bool $reset
* TRUE, to reset the static cache.
*
* @return string
* One of 'table', 'cache' or 'type'.
* On a fully updated database, this value will be 'table'.
Expand All @@ -1044,11 +1041,8 @@ function features_set_signature($module, $component, $signature = NULL, $message
* @see \features_set_signature()
* @see \features_update_7202()
*/
function _features_get_signature_storage_type($reset = FALSE) {
static $type;
if ($reset) {
$type = NULL;
}
function _features_get_signature_storage_type() {
$type = &drupal_static(__FUNCTION__);
if ($type !== NULL) {
return $type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ test_dependencies[] = views

configure = admin/structure/features/settings

; Information added by Drupal.org packaging script on 2020-11-01
version = "7.x-2.12"
; Information added by Drupal.org packaging script on 2020-11-20
version = "7.x-2.13"
core = "7.x"
project = "features"
datestamp = "1604202294"
datestamp = "1605854056"
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ function features_schema() {
'module' => array(
'description' => 'Name of the feature module.',
'type' => 'varchar',
'length' => 255,
'length' => 64,
'not null' => TRUE,
),
'component' => array(
'description' => 'Name of the features component.',
'type' => 'varchar',
'length' => 255,
'length' => 128,
'not null' => TRUE,
),
'signature' => array(
Expand Down Expand Up @@ -76,6 +76,8 @@ function features_uninstall() {
variable_del('features_ignored_orphans');
variable_del('features_feature_locked');
variable_del('features_lock_mode');
variable_del('features_update_7202_fixed_tmp');
variable_del('features_update_7202_possibly_broken');

db_delete('variable')
->condition('name', 'features_admin_show_component_%', 'LIKE')
Expand Down Expand Up @@ -209,13 +211,13 @@ function features_update_7202() {
'module' => array(
'description' => 'Name of the feature module.',
'type' => 'varchar',
'length' => 255,
'length' => 64,
'not null' => TRUE,
),
'component' => array(
'description' => 'Name of the features component.',
'type' => 'varchar',
'length' => 255,
'length' => 128,
'not null' => TRUE,
),
'signature' => array(
Expand Down Expand Up @@ -246,18 +248,19 @@ function features_update_7202() {
db_create_table('features_signature', $schema);
}


// Load existing signatures.
if (db_table_exists('cache_features')) {
// The original version of the previous update has already run.
if (db_table_exists('cache_featurestate')) {
// The old version of features_update_7201() has run in the past, and a
// cache table was created to replace the 'features_codecache' variable.
$cache = cache_get('features_codecache', 'cache_featurestate');
$signaturess = !empty($cache->data)
? $cache->data
: array();
$message = __FUNCTION__ . '() - from cache storage';
}
else {
// The update is from an earlier version of features.
// The current (inactive) version of features_update_7201() has run, and the
// 'features_codecache' variable still exists.
$signaturess = variable_get('features_codecache', array());
$message = __FUNCTION__ . '() - from variable storage';
}
Expand Down Expand Up @@ -297,10 +300,57 @@ function features_update_7202() {
// On failure, allow the exception to trickle up.
$insert->execute();

// Set a temporary marker variable for subsequent updates.
// This variable was not set in an older version of this update.
variable_set('features_update_7202_fixed_tmp', TRUE);

// Delete the old table and variable if the data migration was successful.
variable_del('features_codecache');

if (db_table_exists('cache_featurestate')) {
db_drop_table('cache_featurestate');
}

// Reset the static cache that determines the storage type.
drupal_static_reset('_features_get_signature_storage_type');
}

/**
* Reduce varchar lengths in 'features_signature' table. See #3181858.
*/
function features_update_7203() {
// The following operations are only needed for sites that previously ran an
// older version of features_update_7202(). Trying to check this would
// probably be more copmlex, so we run it anyway.
db_change_field('features_signature', 'module', 'module', array(
'description' => 'Name of the feature module.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
));
db_change_field('features_signature', 'component', 'component', array(
'description' => 'Name of the features component.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
));
}

/**
* Set a marker variable, if the site could be affected by undesired reverts.
*/
function features_update_7204() {
if (variable_get('features_update_7202_fixed_tmp')) {
// The fixed version of features_update_7202() did run.
// Delete the temporary marker variable.
variable_del('features_update_7202_fixed_tmp');
}
else {
// Either the old broken version of features_update_7202() ran, or features
// was newly installed in a version where 7202 or 7203 was the latest
// update.
// Set a marker variable, indicating that some overridden features
// components might have been accidentally reverted. See #3183346.
variable_set('features_update_7202_possibly_broken', TRUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ features[user_permission][] = create features_test content
features[views_view][] = features_test
hidden = 1

; Information added by Drupal.org packaging script on 2020-11-01
version = "7.x-2.12"
; Information added by Drupal.org packaging script on 2020-11-20
version = "7.x-2.13"
core = "7.x"
project = "features"
datestamp = "1604202294"
datestamp = "1605854056"
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,6 @@ function _webform_render_civicrm_contact($component, $value = NULL, $filter = TR
function wf_crm_fill_contact_value($node, $component, &$element, $ids = NULL) {
$cid = wf_crm_aval($element, '#default_value', '');
if ($element['#type'] == 'hidden') {
// User may not change this value for hidden fields
$element['#value'] = $cid;
if (!$component['extra']['show_hidden_contact']) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class wf_crm_admin_help {
'<li>' . t('Select a specific rule to customize how matching is performed.') . '</li>' .
'<li>' . t('Or select "- None -" to always create a new contact.') . '</li>' .
'</ul><p>' .
t('Note: Matching rules are only used if the contact is not already selected via "Existing Contact" field.') .
t('Note: Matching rules are only used if the contact is not already selected via "Existing Contact" field.') . '</p><p>' .
t('Note: Contacts are created (using this matching rule) before any other entities are stored as Contacts need to exist before e.g. shared addresses can be processed.') . '</p><p>' .
t('Note: Ensure all fields that are configured in your matching rule are added and required on your Webform - else you may get unexpected results') .
'</p>';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ abstract class wf_crm_webform_base {
case 'case_roles':
$to = $component['extra']['default_relationship_to'];
$case = $component['extra']['default_for_case'];
if (empty($this->ent['contact'][$c]['id']) && $component['extra']['default_case_roles'] == 'case_client') {
// load case client of case (if passed in URL) as default contact
$this->findCaseClientForDefaultContact($c);
}
if (!empty($this->ent['contact'][$to]['id']) && !empty($this->ent['case'][$case]['id'])) {
$found = wf_crm_find_case_roles($this->ent['contact'][$to]['id'], $this->ent['case'][$case]['id'], $component['extra']['default_case_roles']);
unset($this->ent['contact'][$c]['reload']);
Expand Down Expand Up @@ -580,7 +576,9 @@ abstract class wf_crm_webform_base {
static $status_types;
static $membership_types;
if (!isset($membership_types)) {
$membership_types = array_keys(wf_crm_apivalues('membershipType', 'get', ['is_active' => 1, 'return' => 'id']));
$domain = wf_civicrm_api('domain', 'get', ['current_domain' => 1, 'return' => 'id']);
$domain = wf_crm_aval($domain, 'id', 1);
$membership_types = array_keys(wf_crm_apivalues('membershipType', 'get', ['is_active' => 1, 'domain_id' => $domain, 'return' => 'id']));
}
$existing = wf_crm_apivalues('membership', 'get', [
'contact_id' => $cid,
Expand Down Expand Up @@ -668,127 +666,6 @@ abstract class wf_crm_webform_base {
return $values;
}

/**
* Save custom data for an entity
*
* @param $entity
* Array of values
* @param $entity_id
* Numeric id of entity
* @param $entity_type
* Type of crm entity, e.g. "Contact"
* @param $known
* Is this a known record (as opposed to a contact matched via dedupe rules)?
* We only allow saving blank fields for known contacts.
* @param $contact_index
* Contact's index
*/
protected function saveCustomData($entity, $entity_id, $entity_type, $known = TRUE, $contact_index = 1) {
$existing = FALSE;
$params = ['entityID' => $entity_id];
$createMultiValues = [];

foreach ($entity as $table => $values) {
if (substr($table, 0, 2) == 'cg' && is_array($values)) {
if ($existing === FALSE) {
$existing = $this->getCustomData($entity_id, $entity_type, FALSE);
}
$existing += [$table => []];
$insert = 0;

foreach ($values as $valuesIndex => $custom) {
// Match to id of existing record (id will be 0 for non-multi-value custom sets, which is fine)
if ($id = each($existing[$table])) {
$suf = $id['key'];
}
// Create new record(s) using negative numbers
else {
$suf = --$insert;
}

$multivaluesCreateMode = NULL;

// Handle 'Create mode' for multivalues custom fields of Contact entity.
if ($entity_type === 'Contact') {
$createModeKey = 'civicrm_' . $contact_index . '_contact_' . $valuesIndex . '_' . $table . '_createmode';
$multivaluesCreateMode = isset($this->data['config']['create_mode'][$createModeKey]) ? (int) $this->data['config']['create_mode'][$createModeKey] : NULL;
}
$multiValueSuffix = '_' . $suf;

if ($multivaluesCreateMode === self::MULTIVALUE_FIELDSET_MODE_CREATE_ONLY) {
// Using 'Create only' mode we don't need custom value's suffix
// so the value can be added as new instead of updated.
$multiValueSuffix = '';
}

$customGroupParams = [];

foreach ($custom as $k => $v) {
// Only save if this is not blank or data already exists and record is known
if ($v !== '' || ($suf >= 0 && $known)) {
$customGroupParams[$k . $multiValueSuffix] = $v;
}
}

if ($multivaluesCreateMode === self::MULTIVALUE_FIELDSET_MODE_CREATE_ONLY) {
$createMultiValues[] = $customGroupParams;
}
else {
$params = array_merge($params, $customGroupParams);
}
}
}
}

if (count($params) > 1) {
// Update existing values.
$this->saveCustomValues($entity_id, $params);
}

if (!empty($createMultiValues)) {
// Add new values.
foreach ($createMultiValues as $multiValuesSet) {
$this->saveCustomValues($entity_id, array_merge($multiValuesSet, ['entityID' => $entity_id]), TRUE);
}
}
}

/**
* Saves a set of custom values for specific entity Id.
*
* @param int $entity_id
* @param array $params
* @param bool $skipEmpty
*/
protected function saveCustomValues($entity_id, array $params, $skipEmpty = FALSE) {
if ($skipEmpty) {
// Remove empty values from $params array. Useful to not save empty values
// with 'Create only' mode.
foreach ($params as $key => $value) {
$checkValue = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, '', $value);
if (empty($checkValue)) {
unset($params[$key]);
}
}
}

$result = CRM_Core_BAO_CustomValueTable::setValues($params);

// Prevent wholesale failure by saving each param individually if there was an error while trying to save them all at once
if (!empty($result['is_error'])) {
$bt = debug_backtrace();
array_shift($params);
foreach ($params as $k => $v) {
$single_param = ['entityID' => $entity_id, $k => $v];
$result = CRM_Core_BAO_CustomValueTable::setValues($single_param);
if (!empty($result['is_error'])) {
$file = explode('/', $bt[0]['file']);
watchdog('webform_civicrm', 'The CiviCRM "CustomValueTable::setValues" function returned the error: "%msg" when called by line !line of !file with the following parameters: "!params"', ['%msg' => $result['error_message'], '!line' => $bt[0]['line'], '!file' => array_pop($file), '!params' => print_r($single_param, TRUE)], WATCHDOG_ERROR);
}
}
}
}

/**
* @param string $fid
* @param mixed $default
Expand Down
Loading

0 comments on commit 4f3129c

Please sign in to comment.