civicrm / org.civicrm.civicase

CiviCase Extension
Other
9 stars 35 forks source link

Compatibility with MySQL 8 #142

Open pbarmak opened 1 year ago

pbarmak commented 1 year ago

I don't know if this extension is maintained anymore, it would be nice to get status on it. I just tried installing it on a Drupal 9 install with MySQL 8 and get the following error thrown. I'm guessing because the word "grouping" is a system keyword in MySQL 8 and needs backticks around it? I'm not sure where the SQL statement is being built to test out my theory. This may be an issue with API v3 or event the call to setvalue (which I understand is deprecated). I'm guessing CiviCase has not been updated in a long time.

$Fatal Error Details = array:3 [
  "message" => "Error in call to OptionValue_setvalue : DB Error: syntax error"
  "code" => null
  "exception" => CRM_Core_Exception {#4944
    #message: "Error in call to OptionValue_setvalue : DB Error: syntax error"
    #code: 0
    #file: "/var/www/civicrm/vendor/civicrm/civicrm-core/api/api.php"
    #line: 135
    #cause: null
    -_trace: null
    -errorData: array:8 [
      "error_code" => "syntax error"
      "sql" => """
        SELECT  id, grouping  \n
         FROM   `civicrm_option_value`   \n
         \n
         WHERE (  `civicrm_option_value`.`id` = 18 )  \n
         \n
         \n
         \n
         [nativecode=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 'FROM   `civicrm_option_value`   \n
         \n
         WHERE (  `civicrm_option_value`.`id` = 18 )' at line 2]
        """
      "tip" => "add debug=1 to your API call to have more info about the error"
      "is_error" => 1
      "error_message" => "Error in call to OptionValue_setvalue : DB Error: syntax error"
      "debug_information" => """
        SELECT  id, grouping  \n
         FROM   `civicrm_option_value`   \n
         \n
         WHERE (  `civicrm_option_value`.`id` = 18 )  \n
         \n
         \n
         \n
         [nativecode=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 'FROM   `civicrm_option_value`   \n
         \n
         WHERE (  `civicrm_option_value`.`id` = 18 )' at line 2]
        """
      "entity" => "Extension"
      "action" => "install"
    ]
    trace: {
      /var/www/civicrm/vendor/civicrm/civicrm-core/api/api.php:135 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Admin/Form/Extensions.php:187 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Core/Form.php:573 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Core/StateMachine.php:144 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Core/QuickForm/Action/Next.php:43 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-packages/HTML/QuickForm/Controller.php:203 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-packages/HTML/QuickForm/Page.php:103 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Core/Controller.php:355 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Core/Page/Basic.php:334 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Core/Page/Basic.php:140 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Admin/Page/Extensions.php:105 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:319 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:69 { …}
      /var/www/civicrm/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php:36 { …}
      /var/www/civicrm/web/modules/contrib/civicrm/src/Civicrm.php:88 {
        Drupal\civicrm\Civicrm->invoke($args)
        › ob_start();
        › $content = \CRM_Core_Invoke::invoke($args);
        › $output = ob_get_clean();
      }
      /var/www/civicrm/web/modules/contrib/civicrm/src/Controller/CivicrmController.php:80 { …}
      Drupal\civicrm\Controller\CivicrmController->main() {}
demeritcowboy commented 1 year ago

My guess is this is coming from https://github.com/civicrm/org.civicrm.civicase/blob/b49c4fa89c6769c3f57f4229c39032915bd60af3/CRM/Civicase/Upgrader.php#L126 but is actually a core issue where it doesn't backtick the field name (as you've guessed).

Just adding backticks at that line 126 might be a quick fix but the right fix is probably in core, either somewhere in here https://github.com/civicrm/civicrm-core/blob/256615ed864ef113de36d1f986090f388d5ef5ba/api/v3/Generic/Setvalue.php#L27 or probably better lower down in CRM_Core_DAO::setFieldValue.