0

i have a RULES event on "Cron maintenance tasks are performed" and a action is attached to it "execute custom php code"

<?php $old = '1 day'; $old = strtotime("now - $old"); $query=db_select('profile','pf') ->condition('pf.created',$old, '<') ->fields('pf',array('uid','pid','created')); $result=$query->execute(); foreach($result as $record){ $profile=profile2_load_by_user($record->uid); profile2_save($profile); } ?> 

Error :

Recoverable fatal error: Argument 1 passed to profile2_save() must be an instance of Profile, array given, called in /home/test/public_html/drupal_sedco_2/sites/all/modules/rules/modules/php.eval.inc(146) : eval()'d code on line 9 and defined in profile2_save() (line 292 of /home/test/public_html/drupal_sedco_2/sites/all/modules/profile2/profile2.module).

Any clues . Thanks

1 Answer 1

1

profile2_load_by_user returns either a single profile or an array of profiles keyed by profile type. profile2_save expects a single profile.

It looks like in your particular case array is returned, so you need to:

  1. Test what you got from profile2_load_by_user
  2. If it's a single profile, use profile2_save directly.
  3. If it's an array, either select the array element you need, or foreach over that array, calling profile2_save on each element.
1
  • Yes thanks for pointing , it was an array() ; Works now :) Commented Nov 5, 2013 at 12:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.