I'm using LDAP integration to provide LDAP auth for my drupal website and have a module that automatically generates a content profile for every new drupal account that looks like this:

function wand_account_user($op, &$edit, &$account, $category = NULL) {

  // Create a content profile whenever user is created (via LDAP)
  if ($op == 'insert') {
    $node = new StdClass();
    $node->type = 'profile';
    $node->title = $account->name;
    $node->created = time();
    $node->changed = $node->created;
    $node->uid = $account->uid;
    watchdog('Created Profile for user' . $account->uid, 'Created a Profile node for user ' . $account->uid . ' via wand_account.module');
    node_save($node);
  }

}

However when I go to edit this content profile either by logging into the user and altering the profile, or editing it through the admin user list after it has been created I get the following error in drupal: "This content has been modified by another user, changes cannot be saved.". If I edit the profile from the content list in the admin panel in drupal it works fine also. Any ideas?

Comments

mdeltito’s picture

I believe I had the same issue, though I'm not certain as it was quite some time ago. Looking at the code I wrote for this functionality, I did some shuffling of the $user variable which may be of interest:

...
		case 'insert':
			$uid = $account->uid;
		
			global $user;
			$admin = $user;
			$user = user_load(array('uid' => $uid));
			
			// create a node from the start since we need it for the initial check
			$node = new stdClass;
			$node->type = 'profile';
			
			// this should be impossible, but just to be safe
			if( !content_profile_profile_exists($node, $uid) ) {
				// create, validate, and save the node
				$node->title = $account->name;
				$node->uid = $uid;
				$node->promote = 0;
				
				$saved = false;
				if( $node = node_submit($node) ){
					if($node->validated) {
						node_save($node);
						//$saved = true;
						drupal_set_message('Profile node automatically created for "' . $account->name . '"');
					}
				}
				
			}
			$user = $admin;
			break;	
	}