salesagility / SuiteCRM

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

llegal string offset '' in Forms.php on line 176 #9164

Open sweettbug3 opened 3 years ago

sweettbug3 commented 3 years ago

This issue is pretty much identical to #7869, but is found in modules/Import/Forms.php.

Issue

When importing into a module with options set to an empty string. I get a warning in my logs.

I checked and this is because $fieldlist[$name]['options'] is sometimes set to a string instead of an array.

Expected Behavior

No PHP warnings in the logs.

Actual Behavior

I get an illegal offset warning:

PHP Warning:  Illegal string offset '' in /bitnami/suitecrm/modules/Import/Forms.php on line 179, referer: http://localhost/index.php
PHP Warning:  Cannot assign an empty string to a string offset in /bitnami/suitecrm/modules/Import/Forms.php on line 179, referer: http://<webapp-url>/index.php

Possible Fix

Same fix as for #7869

--- modules/Import/Forms.php.orig   2021-04-28 15:30:19.000000000 -0600
+++ modules/Import/Forms.php    2021-06-02 09:28:05.000000000 -0600
@@ -172,7 +172,7 @@
             $fieldlist[$name]['options'] = $mod_strings[$fieldlist[$name]['options']];
         }
         // Bug 22730: make sure all enums have the ability to select blank as the default value.
-        if (!isset($fieldlist[$name]['options'][''])) {
+        if (isset($fieldlist[$name]['options']) && is_array($fieldlist[$name]['options']) && !isset($fieldlist[$name]['options'][''])) {
             $fieldlist[$name]['options'][''] = '';
         }
     }

Steps to Reproduce

  1. Add a custom enum field via studio
  2. unset enum options string, or set a custom vardef to options => '' or options => 'app_list_string_that_doesnt_exist'
  3. import a csv for the variable in question
  4. check the logs

Context

Creates a lot of annoying log messages.

Your Environment

holdusback commented 4 months ago

So I've setup my environment in PHP8.2 from 7.4 and I had sort of the same issue as you, blank screen while step 3 of importing a CSV. I had this error in my phplog : Uncaught TypeError: Cannot access offset of type string on string in /modules/Import/Forms.php:179 So Im not able to import a CSV file in PHP8.

If I go back to PHP 7.4 the process run smoothly, but in PHP8.2 not. (Assume that in php7 it was only throwing a warning ?)

I've put your fix and it fix the issue, I still need to check if the import go well, but changing that if() statement made the tricks for me.

Im on latest Suitecrm7 version : SuiteCRM 7.14.4

Importing a CSV file in opportunity module with some custom fields.