salesagility / SuiteCRM-Core

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

Contact last touch point select SQL has a column (emails.date_sent_received) on a wrong table (notes) instead of emails. #555

Open gmcodentech opened 1 month ago

gmcodentech commented 1 month ago

Issue

There is a fatal error reported in the log file from the 8.7 version. The error is not displayed on the UI but reported in the log file. Error:

SubpanelCustomQueryPort: Error executing custom query Query Failed: SELECT  emails.`date_sent_received`   FROM notes   LEFT JOIN  contacts contacts ON notes.contact_id=contacts.id AND contacts.deleted=0
 AND contacts.deleted=0  LEFT JOIN  users jt1 ON notes.assigned_user_id=jt1.id AND jt1.deleted=0
 AND jt1.deleted=0 INNER JOIN  contacts notes_rel ON notes.contact_id=notes_rel.id AND notes_rel.deleted=0
  where ( notes.contact_id='257653c8-87fa-11ef-8040-78726430b17c') AND notes.deleted=0   ORDER BY  emails.`date_sent_received` DESC LIMIT 1: MySQL error 1054: Unknown column 'emails.date_sent_received' in 'field list'

It looks the indexes are changed and so this might be breaking the query for subpanels in Contacts module. Path: Core\core\modules\Contacts\Statistics\ContactLastTouchPoint.php $queries[4] & $queries[5]

There are indexes difference in this file in 8.6.2 and 8.7. The $queries list has different indexes 8.7 and 8.6.2 in ContactLastTouchPoint.php but the order of subpanels in subpaneldefs.php in two versions is not different. Changing the indexes of $queries in ContactLastTouchPoint in 8.7 similar to 8.6.2 fixed the issue in my suite8.7 installation. changed the above indexes as $queries[5] & $queries[6] in 8.7 in the same file.

I am not sure if this is the correct fix, or I am missing something.

Possible Fix

Reverting the indexes $queries array order $queries[4] & $queries[5] by $queries[5] & $queries[6] reectively. in Core\core\modules\Contacts\Statistics\ContactLastTouchPoint.php

Steps to Reproduce the Issue

1. Log into the suite 8.7
2. Click on 'Contacts' module menu
3. Open a contact detail view
4. Check for the error in suitecrm.log file
...

Context

No response

Version

8.7

What browser are you currently using?

Chrome

Browser Version

No response

Environment Information

MariaDB, PHP 8.2

Operating System and Version

Windows