Fatal error: Call to undefined function mongodb_session_user_insert() in /sites/all/modules/mongodb/mongodb_session/mongodb_session.inc on line 113

Drupal 7.22
my settings:

  include_once('./includes/cache.inc');

   # -- Configure Cache
   $conf['cache_backends'][] = 'sites/all/modules/mongodb/mongodb_cache/mongodb_cache.inc';
   $conf['cache_class_cache'] = 'DrupalMongoDBCache';
   $conf['cache_class_cache_bootstrap'] = 'DrupalMongoDBCache';
   $conf['cache_default_class'] = 'DrupalMongoDBCache';

   # -- Don't touch SQL if in Cache
   $conf['page_cache_without_database'] = TRUE;
   $conf['page_cache_invoke_hooks'] = FALSE;
   
   # Session Caching
   $conf['session_inc'] = 'sites/all/modules/mongodb/mongodb_session/mongodb_session.inc';
   $conf['cache_session'] = 'DrupalMongoDBCache';

   # Field Storage
   $conf['field_storage_default'] = 'mongodb_field_storage';
   
   # Message Queue 
   $conf['queue_default_class'] = 'MongoDBQueue';
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

protools’s picture

Issue summary: View changes

#

marcingy’s picture

This was caused by the following commit http://drupalcode.org/project/mongodb.git/commit/e68769e I am assuming the code in mongodb_session_user_update which the above calls (mongodb_session_user_insert) needs to be move into the inc file and be renamed appropriately.

MantasK’s picture

Status: Active » Needs review
FileSize
1.7 KB

I took code from stable version with small change:
I removed '_id' => (int) $account->uid, from '$set'
as it is not necessary and gives error (maybe I have newer MongoDB verison)

aslo in newest dev version there was syntax error

jyee’s picture

Rerolling #2 and updating to pass $edit by reference and $category per the api spec.

jyee’s picture

I had a few errors with the patch in #3. This should resolve them.

DyanneNova’s picture

Status: Needs review » Needs work

The patch in #4 needs an update hook for users. Other than that it works well.

jyee’s picture

Status: Needs work » Needs review
FileSize
4.15 KB

New patch with an update hook to update (load and save) user accounts.
Note: You may need to add the patch from https://drupal.org/node/1922578#comment-7926955 if you're using mongodb_field_storage, otherwise the update may not properly retain user roles.

cloudbull’s picture

I have this while applying #6

is that the dev updated ?

git apply -v mongodb_session_user_update-1961728-6.patch 
Checking patch mongodb_session/mongodb_session.inc...
warning: mongodb_session/mongodb_session.inc has type 100755, expected 100644
Checking patch mongodb_session/mongodb_session.install...
Checking patch mongodb_session/mongodb_session.module...
warning: mongodb_session/mongodb_session.module has type 100755, expected 100644
error: while searching for:
      'login' => (int) $account->login,
    ),
  );
  mongodb_collection('fields_current', 'user')->update(array('_id' => (int) $account->uid), $save, array('w' => 0);
}

function _mongodb_session_get_roles($account) {

error: patch failed: mongodb_session/mongodb_session.module:23
error: mongodb_session/mongodb_session.module: patch does not apply
cloudbull’s picture

Issue summary: View changes

2

marcingy’s picture

Issue summary: View changes
Status: Needs review » Needs work

This does not need an update hook as people login in sessions will migrate naturally to mongo. The joys of schemaless db :)

jyee’s picture

Status: Needs work » Needs review

Actually, it does need the update hook because when a user logs in, the only thing being updated is the login, not the entire user document. See: http://drupalcode.org/project/mongodb.git/blob/79ee6b5:/mongodb_session/...

There's a bug with the existing code where user roles are not being saved in mongo. Without the update hook, those users login but do not have the correct permissions. The update hook corrects those user documents so that they follow the same structure/schema as created by mongodb_session_user_update()

marcingy’s picture

Status: Needs review » Needs work

Ah my bad....however why not when you query mongo in the update hook check to see if $roles is present in the user object that is returned and if it is no need to run user save. And too be honest there is really no need to go through user_save instead just lift out the logic in hook_update and put it directly in the update function. On large data collections which mongo has normally the approach at the moment is not going to be performant. We have to remember any installs prior to the commit that removed this feature will have the data in place for roles and also anyone running dev version will very likely reverted the problematic commit as the code fatals currently so an update function for broken code seems pointless....

slashrsm’s picture

I agree with @marcingy about user_save(). It should be avoided if possible.

I am wondering... could we use upsert with that?

beefheartfan’s picture

Not sure if I'm posting this in the right spot, but the issue I'm experiencing is related to the code in this patch, so here goes...

I noticed that when users logged into my site, the Mongo Session module successfully saves their user roles in the field_current.user collection like so:

    "roles" : {
        "2" : "authenticated user",
        "3" : "administrator"
    }

However, if I update the edit the user (at user/xxxx/edit), the role names are dropped and it just saves the rids to Mongo, like this:

    "roles" : {
        "2" : "2",
        "3" : "3"
    }

I believe this has to do with the way the roles are updated in mongodb_session_user_update(). The $save array is being created using a Union like this:

      '$set' => (array) $account + array(
        '_bundle' => 'user',
        'roles' => $roles,
      ),

But because the $account array at this point only has the rids stored and the 'roles' key already exists, it does not apply the update to $roles that is obtained through _mongodb_session_get_roles();

I was able to get it to work by just updating the 'roles' key outside of the union like this, but there is probably a better way to do it so thats why I didn't just create an update to the earlier patch:

      '$set' => (array) $account + array(
        '_bundle' => 'user',
      ),
    );
	$save['$set']['roles'] = $roles;

If I have the Field Storage module turned on, I also needed to make a similar update the in mongodb_field_storage.module file....

Cracu’s picture

Same problem here...

Instead of:

    $save = array(
      '$set' => (array) $account + array(
        '_bundle' => 'user',
        'roles' => $roles,
      ),
    );

change with:

    $save = array(
      '$set' => array_merge((array) $account, array(
          '_bundle' => 'user',
          'roles' => $roles,
        ),
      ),
    );
Georgique’s picture

Status: Needs work » Needs review
FileSize
3.75 KB

Here is patch according last comments.

fgm’s picture

Status: Needs review » Needs work

This patch no longer applies: there is already a mongodb_session.install.

Anonymous’s picture

Status: Needs work » Reviewed & tested by the community

I just downloaded the latest dev, applied the patch cleanly, & sessions now work in Mongo without the fatal error. RTBC

Anonymous’s picture

Status: Reviewed & tested by the community » Needs work

I spoke too soon. Somehow it worked for me for about an hour after applying this patch, then all kinds of craziness, because indeed, the install file was borked.

majorrobot’s picture

I've rerolled the patch in #14 using the latest dev and tried it out (attached for reference).

However, I think we still need the patch the from #1922578: Field Storage module does not store user roles. Otherwise, new users will never have the correct roles stored. The issue is that hook_user_insert() is called before roles are saved in user_save().

Further complicating the issue is that hook_user_insert() may also be called before mongodb_field_storage_field_storage_write(). Which is what happened on my local machine. So, mongodb_session_user_update() may try to update a user record that does not exist yet.

With this in mind, I wonder if it makes sense to use the MongoDB Session module to save/update roles at all. Sites may use MongoDB Field Storage and choose not to use MongoDB Session. Plus, if we're dealing with a what's basically a field (and a highly important one, at that), Field Storage seems to be the place for this.

So, I suggest:

  1. Going with the patch from #1922578: Field Storage module does not store user roles.
  2. Remove the mongodb_session_user_insert() code in mongodb_session.inc,
  3. No longer using mongodb_session_user_update() and mongodb_session_user_insert() that were in #14 since they're not needed anymore.
  4. Then, we can move hook_update to mongodb_field_storage.install.

Including a patch that does all this.

It could be that I'm missing something here, so I'd be happy to hear others' take on this approach.

majorrobot’s picture

Status: Needs work » Needs review
nehapandya55’s picture

Hi,

I got same issue #14 works for me.

fgm’s picture

@majorrobot : no one answered your #18 patch, which is supposed to be complete. Do you think it should be merged ?