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 (Moderator: Donald Lobo) »
  • CRM_Utils_SmartGroup Problem
Pages: [1]

Author Topic: CRM_Utils_SmartGroup Problem  (Read 1501 times)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
CRM_Utils_SmartGroup Problem
January 27, 2009, 05:23:55 am
I have a site with Drupal 5 and CiviCRM "2.0.4 Drupal PHP5" which we can't upgrade right now due to some edits made to the CiviCRM core code. The edits were just made to templates and a few "final processing" files to change a bit of the output.

There is a problem I am seeing now, however, with the method SmartGroupContacts of CRM_Utils_SmartGroup. I run this code

Code: [Select]
civicrm_initialize(TRUE);
require_once 'CRM/Utils/SmartGroup.php';
$_smartgroup = new CRM_Utils_SmartGroup( $params );
$contact_list = $_smartgroup->SmartGroupContacts(17);
foreach($contact_list as $id) {
  print "{$id['contact_id']}\n";
}

in my Drupal module and it outputs 2325 lines. But when I access the URL civicrm/group/search?reset=1&force=1&context=smog&gid=17 it says " Contact 1 - 50 of 4217 ". In CRM/Utils/SmartGroup.php I see this code:

Code: [Select]
function SmartGroupContacts($gid)
{
$grpparams = array( 'group' => array($gid => 1),'contact_id' => $contactid,
       'return.contactId' => 1);
$inputParams      = array( );
$returnProperties = array( );
$otherVars = array( 'sort', 'offset', 'rowCount' );
$sort     = null;
$offset   = 0;
$rowCount = 0; // this means NO limit
foreach ( $grpparams as $n => $v ) {
    if ( substr( $n, 0, 7 ) == '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 );
list( $contacts, $options ) = CRM_Contact_BAO_Query::apiQuery( $newParams,
                                                               $returnProperties,
                                                               null,
                                                               $sort,
                                                               $offset,
                                                               $rowCount );
return $contacts;
}

which I believe should be returning all members of a smart group, due to the line "$rowCount = 0;". I am only getting 2325 out of my 4217 group members, however.

Am I making a mistake somewhere with this?

Thank you.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CRM_Utils_SmartGroup Problem
January 27, 2009, 06:34:19 am

any specific reason you have:

'contact_id' => $contactid,

as part of your grpparams. I dont think thats the cause though

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: CRM_Utils_SmartGroup Problem
January 27, 2009, 06:55:03 am
Oh, my. I made that file so long ago I didn't even realize that the entire file is custom code. :)

Anyway that was just due to a copy and paste from the "isContactInSmartGroup" function. I attached the entire file--it's only these two methods. I removed that "'contact_id' => $contactid," from SmartGroupContacts so that line is:

Code: [Select]
$grpparams = array( 'group' => array($gid => 1),
       'return.contactId' => 1);

and I still get 2325 lines in the output.

PS: This post was edited because the previous version was INCORRECT (the part about zeroes). The above is now correct.
« Last Edit: January 27, 2009, 07:07:49 am by hershel »
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CRM_Utils_SmartGroup Problem
January 27, 2009, 09:26:23 am

your best bet would be to enable mysql query logging, and see how the queries are different for the two cases. That might give you a clue with regard to the differences

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Re: CRM_Utils_SmartGroup Problem
January 27, 2009, 11:27:05 am
I have determined that the problem was actually a Drupal permissions issue. I am running this as a cron (and using wget to test a test version of it) and so I set the active user to a certain special "cron user" to give him certain permissions. Since we upgraded to Drupal 5.15 it appears that my code to do that needed to be adjusted. This is my guess anyhow, because I am 100% certain that when I wrote the cron code initially it was working fine.

I fixed the user code and it seems to work now.

Thank you for your assistance.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • CRM_Utils_SmartGroup Problem

This forum was archived on 2017-11-26.