On Cron run Open and save all Profile2 based user profiles i have a RULES event on "Cron maintenance tasks are performed" and a action is attached to it "execute custom php code"

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


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
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:


Test what you got from profile2_load_by_user
If it's a single profile, use profile2_save directly.
If it's an array, either select the array element you need, or foreach over that array, calling profile2_save on each element.