Thanks. Those suggestions are certainly helpful and I will try it out tonight (thanks for the security tip Moshe). I think you are right that permissions might be the problem.<br><br>Does anyone else know what permissions cron is run under? It would be nice if it ran under user 1 permissions, but I don&#39;t think this is the case as this same problem is happening when my module runs under cron. Can I use David&#39;s method of switching users in cron? That seems counter-intuitive to me because I wouldn&#39;t think there would be a user object for me to manipulate.<br>
<br>Neil Goodman<br><br><div class="gmail_quote">On Feb 5, 2008 9:05 AM, Moshe Weitzman &lt;<a href="mailto:weitzman@tejasa.com">weitzman@tejasa.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
This is quite a dangerous operation. If you don&#39;t change back to the<br>original uid, whomever calls this page gets to be uid=1 on the next<br>request. There are many reasons why a page might not complete so you<br>have to defend against it. Thanksfully, core now makes this easy. Just<br>
add a call to session_save_session(FALSE) before the user_load().<br>After you are done with your save operations, call<br>session_save_session(TRUE).<br><div><div></div><div class="Wj3C7c"><br>On Feb 5, 2008 9:33 AM, David Metzler &lt;<a href="mailto:metzlerd@metzlerd.com">metzlerd@metzlerd.com</a>&gt; wrote:<br>
&gt;<br>&gt; Here&#39;s an example from my CAS module.<br>&gt;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; // Become user 1 to be able to save profile information<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$admin = array(&#39;uid&#39;=&gt; 1);<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$user = user_load($admin);<br>
&gt;<br>&gt; If you&#39;re operating as a normal user you&#39;ll want to save away the value of<br>&gt; the current user, become admin , do your save stuff, then become the normal<br>&gt; user again. Something like:<br>&gt;<br>
&gt; &nbsp; &nbsp;global $user;<br>&gt; &nbsp; &nbsp;$temp_user = $user;<br>&gt; &nbsp; &nbsp;$admin= array(&#39;uid&#39; =&gt; 1);<br>&gt; &nbsp; &nbsp;$user = user_load($admin);<br>&gt;<br>&gt; &nbsp; &nbsp;... do some save stuff<br>&gt;<br>&gt; &nbsp; &nbsp;$user = user_load($temp_user);<br>
&gt;<br>&gt;<br>&gt; This of course should only be used when you&#39;re trying to circumvent<br>&gt; permissions checked by user_save() (do you have permissions to modify user<br>&gt; roles for example).<br>&gt;<br>&gt; I thought there used to be code in cron.php to do this, but I think I may<br>
&gt; just be remembering wrong. Perhaps someone else on the dev list could answer<br>&gt; the question of who the cron user executes as.<br>&gt;<br>&gt; As I said, not 100% sure this is your problem, but I do know you&#39;ll have<br>
&gt; problems having generic users sync up their roles unless you do this<br>&gt; permissions escalation.<br>&gt;<br>&gt;<br>&gt;<br>&gt; On Feb 5, 2008, at 5:46 AM, Neil Goodman wrote:<br>&gt; No, how do I go about transitioning to user 1 for the save operations?<br>
&gt;<br>&gt; Right now I just call the function and I assume the permissions would be of<br>&gt; whoever is using the module at the time. How do permissions get determined<br>&gt; with things like hook_cron()?<br>&gt;<br>
&gt; Neil Goodman<br>&gt;<br>&gt; On Feb 4, 2008 10:44 PM, David Metzler &lt;<a href="mailto:metzlerd@metzlerd.com">metzlerd@metzlerd.com</a>&gt; wrote:<br>&gt; &gt;<br>&gt; &gt; Last time I ran into something close to this it was because of<br>
&gt; permissions. &nbsp;Are you transitioning to user 1 for the save operations?<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; Might be completely off base.... but that&#39;s my experience.<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>
&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt;<br>&gt; &gt; On Feb 4, 2008, at 5:34 PM, Neil Goodman wrote:<br>&gt; &gt;<br>&gt; &gt; Hello,<br>&gt; &gt;<br>&gt; &gt; I&#39;m currently trying to solve a bug report for my module<br>
&gt; (<a href="http://drupal.org/node/217639" target="_blank">http://drupal.org/node/217639</a>). rallycivic keeps getting a &quot;__clone method<br>&gt; called on non-object&quot; &nbsp;when he runs a function in my module. My module runs<br>
&gt; through a CiviCRM database and pulls out certain CiviCRM contacts that have<br>&gt; membership status. The goal is to get this status synchronized to a Drupal<br>&gt; role. There is a static method in the CiviCRM API called<br>
&gt; CRM_Core_BAO_UFMatch::getUFId(). This method will take a CiviCRM contact id<br>&gt; and return its corresponding Drupal uid. I then take this list of uids and<br>&gt; pass it to the user_multiple_role_edit() function. This function uses the<br>
&gt; user_save() function to apply role changes. I think that one of rallcivic&#39;s<br>&gt; uids is causing an issue with this function. From reading the user_save()<br>&gt; function&#39;s code I can see that it tries to create a new user if the uid<br>
&gt; doesn&#39;t exist. For some reason I think it is trying to do this on a valid<br>&gt; uid, which throws a duplicate error that rallycivic has found in watchdog:<br>&gt; &gt;<br>&gt; &gt; &quot;Location<br>&gt; <a href="http://chelmsfordmc.co.uk/admin/settings/civimember_roles/manual_sync" target="_blank">http://chelmsfordmc.co.uk/admin/settings/civimember_roles/manual_sync</a><br>
&gt; &gt; Referrer<br>&gt; <a href="http://chelmsfordmc.co.uk/admin/settings/civimember_roles/manual_sync" target="_blank">http://chelmsfordmc.co.uk/admin/settings/civimember_roles/manual_sync</a><br>&gt; &gt; Message Duplicate entry &#39;&#39; for key 2 query: INSERT INTO users (uid,<br>
&gt; created, access) VALUES (404, 1202163268, 1202163268) in<br>&gt; /home/chelmsf/public_html/includes/database.mysql.inc on line 172.&quot;<br>&gt; &gt;<br>&gt; &gt; Then the drupal_clone() function is called on a bogus object and throws<br>
&gt; the clone method error. At least, that is what I think is happening.<br>&gt; &gt;<br>&gt; &gt; Has anyone ran into a situation similar to this before?<br>&gt; &gt;<br>&gt; &gt; Neil Goodman<br>&gt; &gt;<br>&gt; &gt;<br>
&gt;<br>&gt;<br>&gt;<br></div></div></blockquote></div><br>