Skip to content

Commit

Permalink
Replace use of field_name_map by field_defs for compatibility wit…
Browse files Browse the repository at this point in the history
…h Sugar 7.9.0.0
  • Loading branch information
Rémi Sauvat committed Jun 7, 2017
1 parent ba87ad6 commit d461377
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.2.8
----
* Replace use of `field_name_map` by `field_defs` for compatibility with Sugar 7.9.0.0

1.2.7
----
* Fix parameter quoting in `Bean::searchBeans`
Expand Down
24 changes: 12 additions & 12 deletions src/Bean.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public function searchBeans($module, array $searchFields, $deleted = 0, $limit =
$sugarBean = $this->getBean($module);
foreach ($searchFields as $searchField => $externalValue) {
// Check the the fields are defined correctly
if (!isset($sugarBean->field_name_map[$searchField])) {
if (!isset($sugarBean->field_defs[$searchField])) {
$msg = "{$searchField} ($externalValue) not in Sugar for module $module, can't search on it";
throw new \RuntimeException($msg);
}
Expand Down Expand Up @@ -455,7 +455,7 @@ public function updateBeanFields(\SugarBean $sugarBean, array $fields)
foreach ($fields as $field => $value) {
// It does not exist in Sugar
if (!array_key_exists($field, $moduleFields) && !array_key_exists($field, $moduleRels)
&& !array_key_exists($field, $sugarBean->field_name_map)
&& !array_key_exists($field, $sugarBean->field_defs)
) {
$this->getLogger()->error($this->logPrefix . "$field doesn't seem to exist in Sugar");
}
Expand Down Expand Up @@ -627,13 +627,13 @@ public function getModuleFields($module, $lang = 'fr_FR', $getUnusedDbFields = f
);
foreach ($sugarBean->column_fields as $fieldName) {
// No information about that field: ERROR
if (!array_key_exists($fieldName, $sugarBean->field_name_map)) {
throw new \RuntimeException("I am not able to find the field $field in field_name_map");
if (!array_key_exists($fieldName, $sugarBean->field_defs)) {
throw new \RuntimeException("I am not able to find the field $field in field_defs");
}
if ($sugarBean->field_name_map[$fieldName]['type'] == 'relate'
|| $sugarBean->field_name_map[$fieldName]['type'] == 'link'
|| (array_key_exists('source', $sugarBean->field_name_map[$fieldName])
&& $sugarBean->field_name_map[$fieldName]['source'] == 'non-db')
if ($sugarBean->field_defs[$fieldName]['type'] == 'relate'
|| $sugarBean->field_defs[$fieldName]['type'] == 'link'
|| (array_key_exists('source', $sugarBean->field_defs[$fieldName])
&& $sugarBean->field_defs[$fieldName]['source'] == 'non-db')
) {
unset($tableFields[$fieldName]);
continue;
Expand All @@ -653,17 +653,17 @@ public function getModuleFields($module, $lang = 'fr_FR', $getUnusedDbFields = f
$moduleInfoFields[$fieldName][$sugarAttribute] = '';

// No attribute of that type ?
if (!array_key_exists($sugarAttribute, $sugarBean->field_name_map[$fieldName])) {
if (!array_key_exists($sugarAttribute, $sugarBean->field_defs[$fieldName])) {
continue;
}

// specific case of label
if ($sugarAttribute === 'vname') {
$label = translate($sugarBean->field_name_map[$fieldName][$sugarAttribute], $module);
$label = translate($sugarBean->field_defs[$fieldName][$sugarAttribute], $module);
$moduleInfoFields[$fieldName][$sugarAttribute] = $label;
// Specific case of Lists (dropdown)
} elseif ($sugarAttribute === 'options') {
$optionsName = $sugarBean->field_name_map[$fieldName][$sugarAttribute];
$optionsName = $sugarBean->field_defs[$fieldName][$sugarAttribute];
$moduleInfoFields[$fieldName][$sugarAttribute] = $optionsName;
if (array_key_exists($optionsName, $listStrings)) {
$moduleInfoFields[$fieldName]['options_list'] = array();
Expand All @@ -675,7 +675,7 @@ public function getModuleFields($module, $lang = 'fr_FR', $getUnusedDbFields = f
}
} else {
$moduleInfoFields[$fieldName][$sugarAttribute] = $sugarBean
->field_name_map[$fieldName][$sugarAttribute];
->field_defs[$fieldName][$sugarAttribute];
}
}
}
Expand Down

0 comments on commit d461377

Please sign in to comment.