<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Arial; font-size: 10pt; color: #000000'>On <span class="Object" id="OBJ_PREFIX_DWT499"><span class="Object" id="OBJ_PREFIX_DWT502">Fri</span></span>, <span class="Object" id="OBJ_PREFIX_DWT500"><span class="Object" id="OBJ_PREFIX_DWT503">Oct 31, 2008</span></span> at 12:27 AM, David Metzler <<span class="Object" id="OBJ_PREFIX_DWT501"><span class="Object" id="OBJ_PREFIX_DWT504">metzlerd@metzlerd.com</span></span>>wrote:<br><br>> It sounds like you're suggesting that $perm, a static variable within<br>> user_access() is being modified without user_access being called, but within<br>> a single page load. That doesn't seem possible in PHP, unless there is a<br>> PHP bug. Static variables are supposed to be local in scope to the<br>> functions that create them. To prove beyond a shadow of doubt, put a $debug<br>> statement in at the very beginning of the function user_access and another<br>> at the very end of the function. (just before the return). If what you're<br><br>This is exactly what I'm suggesting. I put debug statements in user_access, node_content_access, and my OGUR function so that I would see every time they were accessed, and what was in them.<br><br>To briefly summarize, I have a role "GroupAdmin" which is dynamically added to the $user object. It contains the "create story content" permission.<br><br>I issue the command to clear the $perm cache: <strong>user_access('ClearCache', NULL, TRUE)<br><span style="font-weight: bold;"><span style="font-weight: bold;"></span></span></strong><br>This is followed by a module_invoke command (which, in turn will again call user_access):<br><strong>module_invoke('node_content', 'access', 'create', 'story', $user)</strong><br><p><br></p><p>The problem is that the $perm variable in the second user_access call should contain the values from the first user_access call, and it doesn't. It is still set, as it should be, but the variables are different. Here are the results of my debugging:<br></p><p><br></p><p>I noticed that even when my hook_init() clears the $perm variable:</p>
<ul><li><strong>user_access('', NULL, TRUE)</strong></li><li>ogur roles loaded into user object (hook_init)</li><li>user_access | string = </li><li>user_access | <strong>static $perm is NOT already set</strong></li><li>user_access | $perm set for uid 3 (test01)</li><li>user_access | string = | $perm values = 0,1,2,0,1,2,4,5,7,8,9,10,4,5,6,7,8,9,10,0,0,1,2,3,4</li><li>user_access | roles returned: (authenticated user,Devel,Group Member,Group Contributor,Group Admin)</li><li>user_access | permissions returned: (access comments,access
content,view uploaded files,view advanced help index,view advanced help
popup,view advanced help topic,post comments,post comments without
approval,search content,use advanced search,subscribe to
newsletters,view links in block,create page content,create story
content,delete own page content,delete own story content,edit own page
content,edit own story content,upload files,configure member
roles,access devel information,display source code,execute php
code,switch users,view devel_node_access information)</li></ul>
<p>The very next call to user_access does NOT contain the correct permissions:
</p>
<ul><li><strong>user_access('access content')</strong></li><li>user_access | string = <strong>access content</strong> | $perm values = 0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4 (<span style="font-style: italic;">note that all the permmissions from above are NOT here - the only ones missing are those granted by the dynamically assigned roles</span>)<br></li><li>user_access | <strong>static $perm is already set</strong></li><li>user_access | roles returned: (authenticated user,Devel,Group Member,Group Contributor,Group Admin)</li><li>user_access | permissions returned: (view advanced help index,view
advanced help popup,view advanced help topic,access comments,post
comments,post comments without approval,access content,search
content,use advanced search,subscribe to newsletters,view links in
block,access devel information,display source code,execute php
code,switch users,view devel_node_access information)</li></ul>
<p style="font-weight: bold;">Another test:</p><p><br></p><p>This is the page loaded:</p><p><br></p><p>http://mysite.com/node/ognodeadd?type=story&gids[]=24</p><p><br></p><p>User should be able to create story. This is what debug returns:</p>
<ul><li>ogur roles loaded into user object (ognodeadd)</li><li>ogur | ognodeadd roles returned: (authenticated user,Devel,Group Member,Group Contributor,<span style="font-weight: bold;">Group Admin</span>) <em>These are the correct roles for this user in this group.</em>
</li><li>ogur | module to call = node_content | type = <strong>story</strong></li><li>ogur | Preparing to call <strong>module_invoke</strong></li><li>ogur | Calling <strong>user_access('ClearCache', NULL, TRUE)</strong></li><li>user_access | string = <strong>ClearCache</strong></li><li>user_access | <strong>static $perm is NOT already set</strong></li><li>user_access | $perm set for uid 3 (test01)</li><li>user_access | string = <strong>ClearCache</strong> | $perm values = 0,1,2,0,1,2,4,5,7,8,9,10,4,5,6,7,8,9,10,0,0,1,2,3,4</li><li>user_access | roles returned: (authenticated user,Devel,Group Member,Group Contributor,Group Admin) <em>This is correct.</em>
</li><li>user_access | permissions returned: (access comments,access
content,view uploaded files,view advanced help index,view advanced help
popup,view advanced help topic,post comments,post comments without
approval,search content,use advanced search,subscribe to
newsletters,view links in block,<strong>create page content,create
story content,delete own page content,delete own story content,edit own
page content,edit own story content,upload files</strong>,configure
member roles,access devel information,display source code,execute php
code,switch users,view devel_node_access information)<br> <br><em>The
above are the permissions that $perm should have the next time
user_access is ran. It will run again when module_invoke() is called. Below is what comes back the very next time user_access is called.<br></em></li></ul>
<ul><li>ogur | Calling <strong>module_invoke('node_content', 'access', 'create', 'story', $user)</strong></li><li>node_content_access | type = story | op = create</li><li>node_content_access | roles returned: (authenticated user,Devel,Group Member,Group Contributor,Group Admin)</li><li>user_access | string = <strong>create story content</strong> | $perm values = 0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4</li><li>user_access | <strong>static $perm is already set</strong></li><li>user_access | roles returned: (authenticated user,Devel,Group Member,Group Contributor,<span style="font-weight: bold;">Group Admin</span>) <em>This is correct.</em></li><li>user_access | permissions returned: (view advanced help index,view
advanced help popup,view advanced help topic,access comments,post
comments,post comments without approval,access content,search
content,use advanced search,subscribe to newsletters,view links in
block,access devel information,display source code,execute php
code,switch users,view devel_node_access information)
<p><em>Note that the "Group Admin" role permissions are not included
here. They should be the same as from </em><em>from the ClearCache user_access command above.</em><em> It appears that the above permissions have been cached somewhere
else. <br></em>
</p></li><li>ogur | <strong>module_invoke</strong> called</li><li>ogur | ognodeadd roles returned: (authenticated user,Devel,Group Member,Group Contributor,Group Admin)</li><li>ogur | module_invoke access returns <strong>false</strong><br><em>Access should be <strong>true</strong> here.</em></li></ul>
<p>Installed devel module. There are four <strong>user_access</strong> SQL queries that appear on this page:<br></p>
<table class="sticky-enabled sticky-table" border="0">
<tbody>
<tr class="even">
<td>1.16</td>
<td>1</td>
<td><a href="http://api.drupal.org/api/6/function/user_access">user_access</a></td>
<td>SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8)</td>
</tr>
</tbody>
</table>
<table class="sticky-enabled sticky-table" border="0">
<tbody>
<tr class="odd">
<td>0.77</td>
<td class="marker">3</td>
<td><a href="http://api.drupal.org/api/6/function/user_access">user_access</a></td>
<td>SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8,3,4,7)</td>
</tr>
</tbody>
</table>
<table class="sticky-enabled sticky-table" border="0">
<tbody>
<tr class="odd">
<td>0.76</td>
<td class="marker">3</td>
<td><a href="http://api.drupal.org/api/6/function/user_access">user_access</a></td>
<td>SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8,3,4,7)</td>
</tr>
</tbody>
</table>
<table class="sticky-enabled sticky-table" border="0">
<tbody>
<tr class="odd">
<td>0.72</td>
<td class="marker">3</td>
<td><a href="http://api.drupal.org/api/6/function/user_access">user_access</a></td>
<td>SELECT p.perm FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (2,8,3,4,7)</td>
</tr>
</tbody>
</table>
<p> </p><br><br><br><br><br><br></div></body></html>