I have a dev install of Drupal 7 RC1 with Simple Access HEAD installed. There's some test content I created before enabling Simple Acess. I haven't changed any settings in Simple Access, just left it as the defaults.

When I try to edit a page created by a non-admin user, using that same user, it gives me this error:

Fatal error: Call to a member function condition() on a non-object in /d7/sites/all/modules/simple_access/simple_access.module on line 657

Nothing else is displayed, just the error.

How can I fix this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jerrac’s picture

I forgot to mention that I can edit things just fine as an admin.

ctpmp’s picture

I'm seeing this also trying to add content as a non-admin. The problematic code is:

$result = db_select('simple_access_groups', 'g')
        ->fields('g', array('gid'))
        ->innerJoin('simple_access_roles', 'r', 'g.gid = r.gid')
        ->condition('rid', $roles, 'IN')
        ->groupBy('gid')
        ->execute();

The innerJoin method does not return an object that can be chained like this.
http://api.drupal.org/api/drupal/includes--database--select.inc/function...

Changing to this seems to work

$result = db_select('simple_access_groups', 'g')
        ->fields('g', array('gid'));
$result->innerJoin('simple_access_roles', 'r', 'g.gid = r.gid');
$result->condition('rid', $roles, 'IN');
$result->groupBy('gid');
$result = $result->execute();
Joe90’s picture

Is the workaround by ctpmp above considered as the fix? If so it's not doing it for me? I am using Simple Access and forum Access on Drupal 7

I have the need for private forums and private blogs. No non-admin users can create a blog entry or forum post and get the error page as above:

[code]Fatal error: Call to a member function condition() on a non-object in /d7/sites/all/modules/simple_access/simple_access.module on line 657[/code]

Admin can create blog and forum posts OK (though strangely non of the boxes are ticked to do this in permissions for Admin!)

Tried ctpmp's fix but the errors persisted, complaining about last line in the fix.

Please help / advise.

idealworldweb’s picture

ctpmp's fix is working for me, as I had the same problem on non-admin members with the correct permissions to edit pages. Thanks

kscott22’s picture

I hate to mess with module code, but ctpmp's suggestion in #2 worked for me. Thanks!

anj’s picture

The fix in #2 worked for me too. Here it is in patch form.

andresp’s picture

this fix works for me too

drifter’s picture

Status: Active » Reviewed & tested by the community

The proposed patch works for me, thanks!

anj’s picture

Version: master » 7.x-2.0-beta1
Priority: Major » Critical

I just realised that this bug stops anyone from creating any content under D7. Upgrading to 'critical' and marking as 7.x-2.0-beta1 as I just re-tested against the patch against that release and it work as expected.

Anonymous’s picture

adding patch because current doens't work in my drush make installation

simon_w108’s picture

whoah! this is still broken in the main version?!?

ctpmp's fix does work, but the penultimate line is wrong. correction below:

$result = db_select('simple_access_groups', 'g')
        ->fields('g', array('gid'));
$result->innerJoin('simple_access_roles', 'r', 'g.gid = r.gid');
$result->condition('rid', $roles, 'IN');
$result->groupBy('g.gid');
$result = $result->execute();
azinck’s picture

#11 works. Trivial fix, let's get this committed!

kim.pepper’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
985 bytes

The problem is incorrect usage of ->innerJoin() It doesn't return a SelectQueryInterface

@see http://api.drupal.org/api/drupal/includes%21database%21select.inc/functi...

The following patch combines the fixes in #10 and #11

Jason Dean’s picture

#13 works for me - thanks! (phew)

dianacastillo’s picture

Can you put this into the latest module please? or is it already there?

dianacastillo’s picture

I get this when an editor tries to create content as well:
Fatal error: Call to a member function condition() on a non-object in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\simple_access\simple_access.module on line 637

dianacastillo’s picture

Status: Needs review » Needs work
dianacastillo’s picture

I'm confused, because in this patch you have something different than what is in the module now:

while ($group = $result->fetchAssoc(PDO::FETCH_ASSOC)) {
$groups[$group['gid']] = $group;
$groups[$group['gid']]['access'] = $default_access;
}

dianacastillo’s picture

I get these errors when I applied the patch

Notice: Undefined variable: roles in simple_access_group_select() (line 628 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\simple_access\simple_access.module).
Warning: Invalid argument supplied for foreach() in DatabaseCondition->compile() (line 1854 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\includes\database\query.inc).
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) GROUP BY g.gid' at line 2: SELECT g.gid AS gid FROM {simple_access_groups} g INNER JOIN {simple_access_roles} r ON g.gid = r.gid WHERE (rid IN ()) GROUP BY g.gid; Array ( ) in simple_access_group_select() (line 630 of C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\pn\sites\all\modules\simple_access\simple_access.module).

dianacastillo’s picture

When I give the editor permissions to "Administer Content " in the permissions page , this error goes away (without applying the patch which doesnt work for me)

Simon Georges’s picture

Closing #1916384: non admin cannot add content as a duplicate of this one.

Simon Georges’s picture

chertzog’s picture

Status: Needs work » Reviewed & tested by the community

#13 Works for me.

gordon’s picture

Status: Reviewed & tested by the community » Needs review

This still needs some work. I don't like how this fix has been done.

kim.pepper’s picture

@gordon Can you please elaborate? You don't like the syntax? or the approach?

I believe the error was due to incorrect usage of the api. Happy to discuss alternate approaches. :-)

Kim

gordon’s picture

I understand, I am going to have a look at this tomorrow and clean up the code. Basically I would prefer to chain as much as possible and them access the query to add the joins.

dianacastillo’s picture

this patch only created more problems for me.

gordon’s picture

Version: 7.x-2.0-beta1 » 7.x-2.x-dev
FileSize
889 bytes

I have done some tidy up on the patch so it is cleaner, but basically the same patch.

I am wondering if the innerJoin() issue should be raised as an issue, since it can't be chained.

gordon’s picture

I have committed this to dev.

@dianacastillo what were the problems which you were having with this patch?

gordon’s picture

Status: Needs review » Fixed
kim.pepper’s picture

groupBy() returns a SelectQuery object, so you could just put the join at the end of that chain.

http://api.drupal.org/api/drupal/includes%21database%21select.inc/functi...

K

dianacastillo’s picture

I posted the errors I got with this patch previously #19 http://drupal.org/node/991956#comment-7062164

gordon’s picture

I am not sure what the problem is there because $roles can never be uninitilised.

$user->roles is always populated with a value, and it can never be empty either.

If you are still getting this issue, please raise another issue.

dianacastillo’s picture

Hi, i have not tried the patch again because when I give the editor permissions to "Administer Content " in the permissions page , this error goes away . thanks

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 953ec4b on 7.x-2.x, 8.x-3.x by gordon:
    Issue #991956 by anj, TimLeytens, kim.pepper, gordon | jerrac: Fixed Non...