CRM-9050 Core functions calling API functions directly (which is unsupported)

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.1.0
    • Fix Version/s: 4.1.0
    • Component/s: None
    • Labels:
      None

      Description

      I just did a grep of functions that call api functions directly from outside of the api folder & found an alarming number in trunk. In fact there are 72 in the CRM folder. API functions are to be called using the api wrapper civicrm_api();

      Somehow the v2 functions got 'migrated' in an unsupported way

      e.g. ForwardMailing.php calls

      $result = civicrm_api3_mailing_event_forward( $params );

      • should be civicrm_api('mailing_event','forward', $params);

      AND
      if ( civicrm_api3_error( $contact ) )

      should be civicrm_error()

      There are a few functions that maybe need to move to BAO in order for us to be able to enforce no external functions directly calling the api.

      $dao = _civicrm_api3_load_DAO($objectName);

      I'm probably more bothered by things like

      $formatError = _civicrm_api3_contribute_formatted_param( $paramValues, $formatted, true);

      If formatting needs to be done it should be handled /supported within the api function – civicrm_api('contribution', 'create', $params) — or by the calling function but not by directly calling an api util function (I actually thought I'd removed _civicrm_api3_contribute_formatted_param but I guess I hadn't yet - pretty sure I'd been hacking away at the other function on in the contribute file which mostly duplicates it and is called from the api).

      I realise the press it to get 4.1 out but I think it would be better to ship with core calling api v2 than to switch to apiv3 without doing it in a way that is consistent with the effort we put into establishing api3. Can we do it slowly & properly rather than in a mad rush that implements v3 in name only?

        Attachments

          Activity

          [CRM-9050] Core functions calling API functions directly (which is unsupported)
          Kurund Jalmi added a comment -

          Eileen,
          I think decision to migrate to v3 api was taken long time back and most of the code is already migrated to v3. I don't think now we should revert all that work. For last part I have filed separate issue: http://issues.civicrm.org/jira/browse/CRM-9073

          Rajan P Mayekar added a comment -

          Hi Eileen,

          Like civicrm_error, instead of using civicrm_api3_duplicate() I am not able to call civicrm_duplicate() without including file api/v2/utils.v2.php.
          Shall I need to include this file api/v2/utils.v2.php every where I use civicrm_duplicate() ?

          Eileen McNaughton added a comment -

          I took a look and civicrm_api3_duplicate seems to be only used in conjunction with civicrm_api3_check_contact_dedupe. Neither are called by API code

          The only function in the API which calls either of these functions is _civicrm_api3_contribute_formatted_param - which is also only called by the import parsers.

          I think all 3 functions are not really part of the api & should be moved into the import parser code somewhere or a utils file that supports the parser code.

          $error = civicrm_api3_check_contact_dedupe( $params );
          if ( civicrm_api3_duplicate( $error ) ) {

          Rohan S. Chavan added a comment -

          Tested in r37316

            People

            • Assignee:
              Rohan S. Chavan
              Reporter:
              Eileen McNaughton

              Dates

              • Created:
                Updated:
                Resolved: