CRM-19552 Case API may throw SQL errors when case_id not provided

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.7
    • Fix Version/s: 4.7.14
    • Component/s: None
    • Labels:
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code

      Description

      Should Case API work when passed an id (instead of case_id) parameter?

      CiviCRM Entity calls it this way from CiviCRMEntityController->save() and passes in only an ID.

      I thought this was CiviCRM API standard but Case API doesn't like it. Raised by Gemma.

      Anyway easy patch to wrap it so it doesn't blow up - maybe this is or isn't The Way. IDK.

        Attachments

        1. update_with_id_param.png
          74 kB
          Jitendra Purohit
        2. updated_with_case_id_param.png
          70 kB
          Jitendra Purohit

          Activity

          [CRM-19552] Case API may throw SQL errors when case_id not provided
          Jitendra Purohit added a comment -

          I wasn't able to reproduce this on my local or dmaster. Case gets correctly updated with `id` or `case_id`. See Screenshot Attached.

          Are you able to re-create this on dmaster or I'm missing anything ?

          Thanks.

          Chris Burgess added a comment -

          Gemma found this when using Drupal + Views Bulk Ops + some other modules to update a Case somehow.

          Specific issue was when CRM_Case_BAO_Case::mergeCases() was called with the second parameter unset.

          Will discuss with Gemma on Monday (Peter Davis does Gemma have an a/c on JIRA?) and see if we can make a test that reproduces this (& doesn't require setting up VBO, Views, and whatever custom data would be required).

          Oct 21 14:45:57  [info] $backTrace = #0 /srv/www/example/example.org/sites/all/modules/civicrm/CRM/Core/Error.php(935): CRM_Core_Error
          ::backtrace("backTrace", TRUE)
          #1 [internal function](): CRM_Core_Error::exceptionHandler(Object(DB_Error))
          #2 /srv/www/example/example.org/sites/all/modules/civicrm/packages/PEAR.php(931): call_user_func((Array:2), Object(DB_Error))
          #3 /srv/www/example/example.org/sites/all/modules/civicrm/packages/DB.php(976): PEAR_Error->PEAR_Error("DB Error: syntax error", -2, 16, (Array:2), "INSERT INTO civicrm_value_angel_tree_gift_case_data_6 (entity_id, notes_26, p...")
          #4 /srv/www/example/example.org/sites/all/modules/civicrm/packages/PEAR.php(564): DB_Error->DB_Error(-2, 16, (Array:2), "INSERT INTO civicrm_value_angel_tree_gift_case_data_6 (entity_id, notes_26, p...")
          #5 /srv/www/example/example.org/sites/all/modules/civicrm/packages/DB/common.php(1905): PEAR->raiseError(NULL, -2, NULL, NULL, "INSERT INTO civicrm_value_angel_tree_gift_case_data_6 (entity_id, notes_26, p...", "DB_Error", TRUE)
          #6 /srv/www/example/example.org/sites/all/modules/civicrm/packages/DB/mysql.php(895): DB_common->raiseError(-2, NULL, NULL, NULL, "1064 ** You have an error in your SQL syntax; check the manual that correspon...")
          #7 /srv/www/example/example.org/sites/all/modules/civicrm/packages/DB/mysql.php(328): DB_mysql->mysqlRaiseError()
          #8 /srv/www/example/example.org/sites/all/modules/civicrm/packages/DB/common.php(1216): DB_mysql->simpleQuery("INSERT INTO civicrm_value_angel_tree_gift_case_data_6 (entity_id, notes_26, p...")
          #9 /srv/www/example/example.org/sites/all/modules/civicrm/packages/DB/DataObject.php(2438): DB_common->query("INSERT INTO civicrm_value_angel_tree_gift_case_data_6 (entity_id, notes_26, p...")
          #10 /srv/www/example/example.org/sites/all/modules/civicrm/packages/DB/DataObject.php(1627): DB_DataObject->_query("INSERT INTO civicrm_value_angel_tree_gift_case_data_6 (entity_id, notes_26, p...")
          #11 /srv/www/example/example.org/sites/all/modules/civicrm/CRM/Core/DAO.php(344): DB_DataObject->query("INSERT INTO civicrm_value_angel_tree_gift_case_data_6 (entity_id, notes_26, p...")
          #12 /srv/www/example/example.org/sites/all/modules/civicrm/CRM/Core/DAO.php(1265): CRM_Core_DAO->query("INSERT INTO civicrm_value_angel_tree_gift_case_data_6 (entity_id, notes_26, p...", TRUE)
          #13 /srv/www/example/example.org/sites/all/modules/civicrm/CRM/Case/BAO/Case.php(2141): CRM_Core_DAO::executeQuery("INSERT INTO civicrm_value_angel_tree_gift_case_data_6 (entity_id, notes_26, p...")
          #14 /srv/www/example/example.org/sites/all/modules/civicrm/api/v3/Case.php(345): CRM_Case_BAO_Case::mergeCases((Array:1), NULL, "33946", NULL, TRUE)
          #15 /srv/www/example/example.org/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php(89): civicrm_api3_case_update((Array:18))
          #16 /srv/www/example/example.org/sites/all/modules/civicrm/Civi/API/Kernel.php(96): Civi\API\Provider\MagicFunctionProvider->invoke((Array:9))
          #17 /srv/www/example/example.org/sites/all/modules/civicrm/api/api.php(23): Civi\API\Kernel->run("case", "update", (Array:18), NULL)
          #18 /srv/www/example/example.org/sites/all/modules/civicrm_entity/civicrm_entity_controller.inc(149): civicrm_api("case", "update", (Array:18))
          #19 /srv/www/example/example.org/sites/all/modules/entity/includes/entity.inc(333): CivicrmEntityController->save(Object(CivicrmEntity))
          #20 /srv/www/example/example.org/sites/all/modules/entity/entity.module(287): Entity->save()
          #21 /srv/www/example/example.org/sites/all/modules/views_bulk_operations/plugins/operation_types/action.class.php(262): entity_save("civicrm_case", Object(CivicrmEntity))
          #22 /srv/www/example/example.org/sites/all/modules/views_bulk_operations/views_bulk_operations.module(1103): ViewsBulkOperationsAction->execute(Object(CivicrmEntity), (Array:2))
          #23 /srv/www/example/example.org/sites/all/modules/views_bulk_operations/views_bulk_operations.module(1012): views_bulk_operations_queue_item_process((Array:3), (Array:0))
          #24 [internal function](): views_bulk_operations_active_queue_process("views_bulk_operations_active_queue_602", Object(ViewsBulkOperationsAction), 1, (Array:4))
          #25 /srv/www/example/example.org/includes/batch.inc(284): call_user_func_array("views_bulk_operations_active_queue_process", (Array:4))
          #26 /srv/www/example/example.org/includes/batch.inc(161): _batch_process()
          #27 /srv/www/example/example.org/includes/batch.inc(80): _batch_do()
          #28 /srv/www/example/example.org/modules/system/system.admin.inc(2384): _batch_page()
          #29 [internal function](): system_batch_page()
          #30 /srv/www/example/example.org/includes/menu.inc(527): call_user_func_array("system_batch_page", (Array:0))
          #31 /srv/www/example/example.org/index.php(21): menu_execute_active_handler()
          #32 {main}
          
          Eileen McNaughton added a comment -

          To be honest I would have thought the wrapper should already handle this (per Jitendra comment) - however, I merged it as it seems safe enough if there is a gap

            People

            • Assignee:
              Chris Burgess
              Reporter:
              Chris Burgess

              Dates

              • Created:
                Updated:
                Resolved: