On 3/22/2011 10:48 AM, Xavier Bestel wrote:
I need a custom field for my users. So I created a computed_field in everyone's content_profile, so far so good. Now the problem is when I want to recompute that field from another user's action, it seems it fails because of the permissions. Here's a part of the code:
foreach($comptes as $uid => $val) { $result = db_query("SELECT name from {users} where uid = '%d'", $uid); $user = drupal_unpack(db_fetch_object($result)); $profilnode = content_profile_load('profile', $uid); if($profilnode) node_save($profilnode); /* update the computed_field */ }
How can I bypass the permissions system to make node_save() work ? I'm using Drupal 6.
user_access caches perms, otherwise you would be able to temporarily add a role with 'administer nodes'. Instead, you'll need to swap out the global $user for uid 1 temporarily (and rename your local $user var). After you're done with the node_save, remember to swap the old $user back.
You might also be interested in the patch(es) in this issue: http://drupal.org/node/697856
Ted