salesagility / SuiteCRM

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
4.46k stars 2.08k forks source link

Elasticsearch search fails to give an Result #7742

Open crmwolf opened 5 years ago

crmwolf commented 5 years ago

Issue The Elasticsearch Engine does not provide any Searchresults within CRM Global Search (Elastic search Engine in vendor/bin/robo gives expected result)

Expected Behavior A Result based on the Input into the Search input field should appear

Actual Behavior Nothing appears on the Search Results Page and this Error Appears

PHP Catchable fatal error: Object of class Link2 could not be converted to string in /crm/lib/Search/SearchResults.php on line 213

Possible Fix Changed:

protected function getLink($label, $module, $record, $action) { global $sugar_config; $link = "<a href=\"{$sugar_config['site_url']}/index.php?action={$action}&module={$module}&record={$record}&offset=1\">{$label}"; return $link; }

to

protected function getLink($label, $module, $record, $action) { global $sugar_config; if(!is_string($record)){ return ""; } $link = "<a href=\"{$sugar_config['site_url']}/index.php?action={$action}&module={$module}&record={$record}&offset=1\">{$label}"; return $link; }

Just a Workaround here.

Steps to Reproduce

  1. Installing SuiteCRM 7.11.6
  2. Installing ElasticSearch
  3. Enabling ElasticSearch in CRM and generating an Index
  4. Searching for something within the Global Field

Your Environment

Mac-Rae commented 5 years ago

Confirmed in 7.11.8

schapsl commented 5 years ago

Hi... I had this bug too... I think everything is fine, until the method $obj->load_relationship() is called in lib\Search\SearchResults::getHitsAsBeans().

Before that, certain links with 3 fields in the object $obj in question are fine.

After the call to SugarBean::load_relationship(), the field <Link_name>_ida contains the the Link2 object, as well. I think this is the actual problem later on,

SugarBean::load_relationship() calls SugarBean::get_linked_fields() returns an array which contains the _ida fields. Then SugarBean::load_relationship($rel_name) is called with the _ida field name as the parameter and this will overwrite the ID in the _ida with a Link2 object, which feels wrong.

My personal workaround was to overwrite the method get_linked_fields in my custom beans, so as not to not return _ida fields. But that would not help here. I suggest checking in the foreach loop in SugarBean::load_relationship() to see if the current element is an _ida field.

I could try to send a pull request.

Hope that helps. Lars

tsummerer commented 5 years ago

You're absolutely right about the three fields and the ida field being filled with incorrect data.

Part of the problem is that if a Relationship is created via studio the id field is (IMO) incorrectly set as a link type when it should be an id type.

A relationship should consist of a link field to define the relationship, an id field to hold the id, and a relate field to display the name. A studio relationship creates two link fields and one relate. This flaw causes trouble in the API too.

So the other workaround is to go and update your relevant vardefs and change the _ida fields to id type

tsitle commented 4 years ago

I believe that the PR #8513 should also fix this issue.