CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • v3 conflicts
Pages: [1] 2

Author Topic: v3 conflicts  (Read 2176 times)

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
v3 conflicts
January 12, 2011, 10:54:40 am
Running through the tests I found a small number of api version conflicts that were in core rather than the test suite

Group BAO
There are 4 places in the group BAO that use the deprecated v2 function

        return civicrm_contact_search( $params );

Which loads api/v2/Contact.php which results in

Fatal error: Cannot redeclare civicrm_contact_create() (previously declared in C
:\utils\eclipseworkspace\api-civicrm\api\v3\Contact.php:61) in C:\utils\eclipsew
orkspace\api-civicrm\api\v2\Contact.php on line 70

Presumably it could be calling
CRM_Contact_BAO_Query::apiQuery
rather more directly

However, I don't know if it's worth looking at the apiquery function first while it's still very lightly used. (about 5 functions call it in all) It looks like it was designed to be called from all the GET apis but only 1 actually does - several others replicate the apiquery function. So, the Contribution_get query for example is basically a copy of apiquery. In particular I note:

-  $skipPermission = false is hardcoded when ideally it would be a $param (although blocked via REST)
- All this cruft below could sit in the apiquery rather than in every GET query - or in an API utils function

Quote
    $sort            = null;
    $offset          = 0;
    $rowCount        = 25;
    $smartGroupCache = false;
    foreach ( $params as $n => $v ) {
        if ( substr( $n, 0, 6 ) == 'return' ) {
            $returnProperties[ substr( $n, 7 ) ] = $v;
        } elseif ( in_array( $n, $otherVars ) ) {
            $$n = $v;
        } else {
            $inputParams[$n] = $v;
        }
    }

    if ( empty( $returnProperties ) ) {
        $returnProperties = null;
    }

    require_once 'CRM/Contact/BAO/Query.php';
    $newParams =& CRM_Contact_BAO_Query::convertFormValues( $inputParams );

Don't suppose anyone feels able to jump in & take a look & decide the best replacement - e.g in

Code: [Select]
    static function isContactInGroup( $contactID, $groupID ) {
        require_once 'CRM/Utils/Rule.php';
        if ( ! CRM_Utils_Rule::positiveInteger( $contactID ) ||
             ! CRM_Utils_Rule::positiveInteger( $groupID ) ) {
            return false;
        }

        $params = array( 'group'      => array( $groupID => 1 ),
                         'contact_id' => $contactID,
                         'return.contact_id' => 1 );
        require_once 'api/v2/Contact.php';
        $contacts = civicrm_contact_search( $params );

        if ( ! empty( $contacts ) ) {
            return true;
        }
        return false;
    }
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: v3 conflicts
January 12, 2011, 11:46:49 am
Basically I think the CRM_Contact_BAO_Query ::apiquery function should be used by all (or most) of these functions and may need some tweaking first.

Currently use (deprecated) api/v2/civicrm_contact_search

CRM_Case_BAO_Case::getGlobalContacts
CRM_Contact_BAO_Group::CRM_Contact_BAO_Group
CRM_Contact_BAO_Group::getMember
CRM_Contact_BAO_GroupContact::isContactInGroup
CRM_Contact_BAO_GroupContactCache::add
CRM_Mailing_Event_BAO_Forward::forward

Currently use apiquery

api/vx/Contact::civicrm_contact_get
CRM_Contact_BAO_Contact::getHierContactDetails
CRM_Contact_Form_Task_Label::postProcess
CRM_Mailing_BAO_Mailing::getDetails

Aspires to use apiquery

UpdateGreeting.php - comment "UpdateGreeting.php"

Seem to replicate apiquery somewhat -not sure if they would be better being more like membership_contact_get

api/vx/Contribution::civicrm_contribution_get (/search)
api/vx/Participant::civicrm_participant_get (/search)
- note these are a bit funky on the left joins  if you aspire to pass in 'contribution_id' to participant_get or vice versa http://forum.civicrm.org/index.php/topic,16081.msg68699.html#msg68699

« Last Edit: January 12, 2011, 12:53:44 pm by Eileen »
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: v3 conflicts
January 17, 2011, 09:09:22 am
Ok, I reviewed these places and agree that they need to be switched to CRM_Contact_BAO_Query::apiQuery() (and then – or along the way as needed – it should be made more useful by encapsulating all the things replicated outside it).

I’ll tackle this one-by-one this week; logging is my priority, but I should find time every day to move this forward, so this should be fixed by the end of the week.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: v3 conflicts
January 17, 2011, 12:59:08 pm
Thanks Piotr
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: v3 conflicts
January 17, 2011, 07:04:57 pm
Looks like another big source of conflicts is in
Code: [Select]
class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity
blah blah blah

    static function addActivity( &$activity, $activityType = 'Membership Signup', $targetContactID = null )
   
blah blah blah
      require_once 'api/v2/Activity.php';
        if ( is_a( civicrm_activity_create( $activityParams ), 'CRM_Core_Error' ) ) {
            CRM_Core_Error::fatal("Failed creating Activity for $component of id {$activity->id}");
            return false;
        }
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: v3 conflicts
January 18, 2011, 07:05:54 am

What about

1) we only use
      require_once 'api/api.php';
        if ( is_a( civicrm_api ( 'activity', 'create', $activityParams ), 'CRM_Core_Error' ) ) {

2) and add a  $activityParams['version']=3 so we are sure we use the api v3

Quote from: Eileen on January 17, 2011, 07:04:57 pm
Looks like another big source of conflicts is in
Code: [Select]
class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity
blah blah blah

    static function addActivity( &$activity, $activityType = 'Membership Signup', $targetContactID = null )
   
blah blah blah
      require_once 'api/v2/Activity.php';
        if ( is_a( civicrm_activity_create( $activityParams ), 'CRM_Core_Error' ) ) {
            CRM_Core_Error::fatal("Failed creating Activity for $component of id {$activity->id}");
            return false;
        }
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: v3 conflicts
January 18, 2011, 12:11:44 pm
Hmm - but the one I was pointing to is in the BAO - I think the BAO shouldn't call the api as a rule
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: v3 conflicts
January 18, 2011, 12:18:35 pm
well, having civi using the api seems to be a better position than the thing at the edge that none in the core uses...

ie. dogfooding and all that jazz.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: v3 conflicts
January 18, 2011, 01:12:11 pm
OK, I just thought there was some inherent threat of conflict there with the api calling the BAO calling the api

But the main problem is that we have a v2 api & a v3 api calling the same BAO function (and also it being called outside the api ) and it needs to work in all cases.

In this case the function is called by another BAO function and I think there might be another in the tree so we'd need to pass 'version' right through from the participant_create that creates the participant to the activity_create that creates the relevant activity
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: v3 conflicts
January 31, 2011, 07:28:11 am
Ok, I finally replaced all civicrm_contact_search() calls in core with the counterpart CRM_Contact_BAO_Query::apiQuery() calls (r32119).

CRM_Mailing_Event_BAO_Forward::forward() still calls civicrm_contact_search_count(), and I can also get rid of that one (it’s the only core place that calls it); would this be a good idea? (Note that this method also calls other API functions anyway.)

Going forward – the following core files most probably make API 2 calls:

Code: [Select]
$ rgrep -c require.*api.v2 CRM | grep -v 0$
CRM/Mailing/Form/Upload.php:1
CRM/Mailing/Form/ForwardMailing.php:1
CRM/Mailing/BAO/Mailing.php:1
CRM/Mailing/BAO/Job.php:1
CRM/Mailing/Event/BAO/Subscribe.php:1
CRM/Mailing/Event/BAO/Forward.php:1
CRM/Activity/Form/Task/Batch.php:1
CRM/Activity/BAO/Activity.php:1
CRM/Activity/Import/Parser/Activity.php:2
CRM/Campaign/Form/Petition/Signature.php:2
CRM/Campaign/BAO/Petition.php:4
CRM/Core/BAO/MessageTemplates.php:2
CRM/Profile/Selector/Listings.php:1
CRM/Pledge/BAO/Pledge.php:1
CRM/Contribute/Page/UserDashboard.php:1
CRM/Contribute/Import/Parser/Contribution.php:1
CRM/Case/Form/Activity/ChangeCaseStartDate.php:1
CRM/Contact/Form/Task/PDFLetterCommon.php:1
CRM/Contact/Form/Merge.php:2
CRM/Import/Parser/Contact.php:2
CRM/Dedupe/Merger.php:1
CRM/Bridge/OG/Utils.php:2
CRM/Bridge/OG/Drupal.php:2
CRM/Bridge/OG/CiviCRM.php:1
CRM/Event/BAO/Participant.php:1
CRM/Event/Import/Parser/Participant.php:1
CRM/Utils/Mail/Incoming.php:2
CRM/Utils/SoapServer.php:3
CRM/Report/Form/Contribute/HouseholdSummary.php:1
CRM/Report/Form/Contribute/OrganizationSummary.php:1
CRM/Member/Import/Parser/Membership.php:1

Is the general idea to move as many of them to API 3 as soon as possible, or just eventually? Are there any priorities?
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: v3 conflicts
January 31, 2011, 10:50:38 am
Hi,

This one here is the other one that is causing a problem

CRM/Activity/BAO/Activity.php:1596

But it needs to not call an api or there will be more version issues since both v2 & v3 api call this. Apart from those called by the api I'd wait - at least until Erik & Xavier catch up to write code over a warm beer on Friday!

e.g

Code: [Select]
   30.2834   33325912  12. api_v3_ContributionTest->testGetContribution() C:\uti
ls\eclipseworkspace\api-civicrm\tests\phpunit\api\v3\ContributionTest.php:0
   30.2835   33327168  13. civicrm_contribution_create() C:\utils\eclipseworkspa
ce\api-civicrm\tests\phpunit\api\v3\ContributionTest.php:94
   30.2884   33334096  14. CRM_Contribute_BAO_Contribution::create() C:\utils\ec
lipseworkspace\api-civicrm\api\v3\Contribution.php:80
   30.3009   33387568  15. CRM_Activity_BAO_Activity::addActivity() C:\utils\ecl
ipseworkspace\api-civicrm\CRM\Contribute\BAO\Contribution.php:280
   30.3550   33629896  16. require_once('C:\utils\eclipseworkspace\api-civicrm\a
pi\v2\Activity.php') C:\utils\eclipseworkspace\api-civicrm\CRM\Activity\BAO\Acti
vity.php:1596
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: v3 conflicts
January 31, 2011, 12:48:07 pm
Quote from: Eileen on January 31, 2011, 10:50:38 am
at least until Erik & Xavier catch up to write code over a warm beer on Friday!

That's one thing to joke about the poor blokes that drink that shit over there, but another one altogether to impose that on ourselves in Belgium.

We'll pass on the warm beers I'm afraid. Erik has threaten me of bringing me some kind of specialities from nl, that's scary enough.

X+
« Last Edit: February 02, 2011, 10:10:57 pm by xavier »
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Piotr Szotkowski

  • I live on this forum
  • *****
  • Posts: 1497
  • Karma: 57
Re: v3 conflicts
February 02, 2011, 08:27:29 am
Quote from: Eileen on January 31, 2011, 10:50:38 am
This one here is the other one that is causing a problem

CRM/Activity/BAO/Activity.php:1596

(Bluntly) fixed in r32170.
If you found the above helpful, please consider helping us in return – you can even steer CiviCRM’s future and help us extend CiviCRM in ways useful to you.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: v3 conflicts
February 02, 2011, 01:55:57 pm
yep - contribution test doesn't need to be skipped now! Will try the others - Yay
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: v3 conflicts
February 02, 2011, 06:47:49 pm
Another conflict - but in this case we were already undecided as to whether to bring the mailer api into 3 or leave it for now - unless someone who understands it steps up & tells us how it would best fit


Code: [Select]
space\api-civicrm\tests\phpunit\api\v3\MailerTest.php:483
  157.5291   43040392  14. CRM_Mailing_Event_BAO_Subscribe::subscribe() C:\utils
\eclipseworkspace\api-civicrm\api\v3\Mailer.php:199
  157.5291   43040392  14. CRM_Mailing_Event_BAO_Subscribe::subscribe() C:\utils
\eclipseworkspace\api-civicrm\api\v3\Mailer.php:199
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1] 2
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • v3 conflicts

This forum was archived on 2017-11-26.