Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AOR Reports main grouping by custom fields results in FATAL error #4973

Closed
mugge6 opened this issue Jan 18, 2018 · 5 comments

Comments

@mugge6
Copy link
Contributor

commented Jan 18, 2018

Issue

If you will create an AOR Report with a custom field and set the "Main Group" dropdown to this filed, then it will result in a FATAL error:
Fatal error: Uncaught Error: Cannot use string offset as an array in /var/www/html/modules/AOR_Reports/AOR_Report.php on line 1245

This report cannot edited anymore.

Expected Behavior

Main group selection by any custom field should work.

Actual Behavior

PHP error will be displayed in a modal popup:

[18-Jan-2018 08:59:17 Europe/Berlin] PHP Fatal error:  Uncaught Error: Cannot use string offset as an array in /var/www/html/modules/AOR_Reports/AOR_Report.php:1245
Stack trace:
#0 /var/www/html/modules/AOR_Reports/AOR_Report.php(469): AOR_Report->build_report_query_join('cases_cstm', 'cases_cstm', 'cases', Object(aCase), 'custom', '')
#1 /var/www/html/modules/AOR_Reports/AOR_Report.php(343): AOR_Report->build_group_report(0, true, Array, 'c9d102c7-b36d-3...')
#2 /var/www/html/modules/AOR_Reports/views/view.detail.php(74): AOR_Report->buildMultiGroupReport(0, true)
#3 /var/www/html/include/MVC/View/SugarView.php(197): AOR_ReportsViewDetail->preDisplay()
#4 /var/www/html/include/MVC/Controller/SugarController.php(432): SugarView->process()
#5 /var/www/html/include/MVC/Controller/SugarController.php(375): SugarController->processView()
#6 /var/www/html/include/MVC/SugarApplication.php(105): SugarController->execute()
#7 /var/www/html/index.php(52): SugarApplication->execute()
#8 {main}
  thrown in /var/www/html/modules/AOR_Reports/AOR_Report.php on line 1245

Possible Fix

Problem is a mix with strings and arrays on modules/AOR_Reports/AOR_Reports.php.

On function build_group_report (line: 416) the $query variable will be initialized as string:
$query = '';

In the same function on line 468 ff this variable will be passed to the function build_report_query_join which expect an array on parameter 6:
$query_array = $this->build_report_query_join($table_alias . '_cstm', $table_alias . '_cstm', $table_alias, $field_module, 'custom', $query);

Possible fix (workaround) could be to pass an empty array if query is empty:

if(!is_array($query)) (
  $query = [];
)
$query_array = $this->build_report_query_join($table_alias . '_cstm', $table_alias . '_cstm',
                    $table_alias, $field_module, 'custom', $query);

But take care of the line 459. If there is a currency field in place then $query variable is already an array. This will cause some similar issues later on, because the $query variable will concatenated as string.

Steps to Reproduce

  1. Add a custom field on an existing module (Cases)
  2. Create a report with this custom field
  3. Select "Main Group" option to this custom field
  4. Save created report
  5. Error will shown

Context

From my point of view this bug has to fixed, because it looks like some similar issues will pop up regarding this mix of array and string operations.

Your Environment

  • SuiteCRM Version used: SuiteCRM 7.9.9
  • Environment name and version (e.g. MySQL, PHP 7): PHP 7.1.4

@mugge6 mugge6 changed the title AOR Reports group by custom fields results in FATAL error AOR Reports main grouping by custom fields results in FATAL error Jan 18, 2018

@PedroErnst

This comment has been minimized.

Copy link
Contributor

commented Jan 18, 2018

Thanks @mugge6 for reporting this.

It should be fixed with this.

daniel-samson added a commit that referenced this issue Jan 18, 2018
Merge pull request #4974 from PedroErnst/fix/4973-aor-report-query-array
Fix #4973 Pass query array instead of string to function expecting it
@pstevens71

This comment has been minimized.

Copy link

commented Jan 19, 2018

I can confirm I just tested it on 7.8.10 LTS and it does fix the issue of grouping by custom fields. Thanks!

@pstevens71

This comment has been minimized.

Copy link

commented Jan 19, 2018

On thing I noticed, not sure if related to this issue. If I group by text field or dropdown field it works fine, but if I group by an integer field value (ie: I have 25,50,75,100 in terms of a percent complete) it crashes out the server.
Fri Jan 19 15:08:38 2018 [2946][1][FATAL] Query Failed: SELECT opportunities_cstm.completion_c AS 'Completion_%' FROM opportunities LEFT JOIN opportunities_cstm opportunities_cstm ON opportunities.id = opportunities_cstm.id_c WHERE ( opportunities_cstm.completion_c IS NOT NULL AND ( opportunities_cstm.completion_c >= '25' AND (opportunities.sales_stage = 'Closed Won') AND DATE(opportunities.date_closed) <= Curdate() ) AND opportunities.deleted = 0 ) ORDER BY Completion_% ASC: MySQL error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ASC' at line 1

@PedroErnst

This comment has been minimized.

Copy link
Contributor

commented Feb 5, 2018

@pstevens71

I think the issue in this case is the percentage symbol '%'

Does your field have the % in its name? If so it might be more sensible to set the name to something like completion_percentage and only put the % symbol in the label.

This is just a guess on my side though.

@pstevens71

This comment has been minimized.

Copy link

commented Feb 5, 2018

Thanks @PedroErnst I'll try that see if it makes a difference. I ended up re-doing it anyway and changed it to a text field of "25%" and it worked ok after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.