cck field prevents node creation with drupal_execute

c_boehm - May 8, 2007 - 15:05
Project:Content Construction Kit (CCK)
Version:5.x-1.7
Component:General
Category:bug report
Priority:critical
Assigned:Unassigned
Status:duplicate
Description

When adding a user, the new user doesn't get a usernode automatically created. Since it is not possible to create usernodes manually, the user simply has no usernode.
I have no clue why, because old users have usernodes, but new ones don't have. I'm using drupal 5.1.
I tried updating to 5.x-1.x-dev. but it didn't help.

#1

jp.stacey - May 11, 2007 - 13:59

I have the same problem with 5.x-1.2: when I first activated the module all (two) existing users got usernodes; since then no new users have usernodes.

It might be related, but we're also getting three errors in the logs, for each access of an existing usernode on the front-end:

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 '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE in /var/www/drupal/includes/database.mysql.inc on line 172.

implode() [<a href='function.implode'>function.implode>/a>]: Bad arguments. in /var/www/drupal/modules/node/node.module on line 508.

Invalid argument supplied for foreach() in /var/www/drupal/modules/node/node.module on line 504.

As we're relying on usernodes to create content then this is pretty urgent for us. Any way of at least disabling the warning that you can't create usernodes manually?

#2

jp.stacey - May 11, 2007 - 18:10

Hi,

I've had a look round in usernode.module, and the "form" it creates for submission via drupal_execute() looks a bit weird:

<?php
function usernode_form(&$node) {
 
$form['title'] = array(
   
'#type' => 'hidden',
   
'#value' => $node->title,
  );

 
// temporarily store a newly registering user's user object,
  // so that usernode_submit() can set the user's actual uid on node creation.
 
if ($node->user) {
   
$form['user'] = array(
     
'#type' => 'value',
     
'#value' => $node->user,
    );
  }

  return
$form;
}

/* ... */

function usernode_create_node($user) {

 
$node = array(
   
'type' => USERNODE_CONTENT_TYPE,
   
'title' => check_plain($user->name),
   
'user' => $user,
  );

 
$values = array();

 
// workaround to disable drupal message "Your usernode has been created"
 
$messages = drupal_get_messages();

 
// create the usernode
 
drupal_execute(USERNODE_CONTENT_TYPE .'_node_form', $values, $node);

 
// write back the old messages
 
$_SESSION['messages'] = $messages;
}
?>

That first function creates a form for use by the form API which has the user object as some sub-object where the form-field specifiers typically go; the second function calls drupal_execute (which sources a form from the first function) with an empty $values array. So drupal_execute puts an empty #post array into the form before sending it off for processing.

My feeling is that this is wrong (the #post array ought to contain whatever you're pretending a user has submitted via a real-life web-form, so e.g. the user ID) but I'm not expert enough to fix it. Anyone who knows the Form API and can help, please do!

#3

cpelham - May 11, 2007 - 20:52

Usernode is so far making new usernodes for new users on my site, but it didn't make usernodes for all of the pre-existing users, only about 108 out of 160 or something. I can't tell what is the difference between the ones with usernodes and the ones without.

If someone could figure out a way to manually add a user mode for a user, then we could overcome this problem even if we couldn't fix this bug. Actually, it's easy enough to add a new user node--it just won't point to anyone. Where does the usernode keep track of which user it corresponds to? The usernode apppears to be empty and it contains no fields. So i guess it uses a hidden proprietary field of some kind. Perhaps, a new usernode could be created and then the id of the user it's supposed to point to could be added directly into the database. This is not a preferable way to administer it though!

#4

fago - May 12, 2007 - 10:50

@jp.stacey: They way drupal_execute is coded works correctly. It doesn't need any POST data as the form uses #value to set the fields - which will work in any case.
I can't help you much with your sql error - but looking at the line I suppose you have somewhere some code, that invokes node_load() with an empty parameter. Try disabling modules and you'll see which one it generates or track it down in the code....

So you two are facing similar but different problems, but ok.
Have you added further cck fields to the usernode content type? If so try deleting them.

@cpelham:
Strange, that usernode hasn't created all. You can disable and reenable the usernode module and it will check all users again, if there are usernodes - and create the missing ones.

#5

jp.stacey - May 14, 2007 - 09:30

@fago: OK, I'll trust your judgment on the form API! Thanks for responding so quickly.

Removing the CCK fields seems to work. However, that's not really a solution for us in the long term as the whole point of using usernode is that it gives us the ability to have rich content on a user by user basis, and we have some users that must be restricted to just editing their own usernode. Any decent workarounds you can think of, or does this result (removing CCK=win) give you any ideas of where the bug might be? It's weird that not everyone is having this problem!

(I've had a look at the bio and nodeprofile modules, but didn't get as far with them as with usernode. Am I right in thinking the nodeprofile module one of yours? How do I specify the relevant user when I create a new nodeprofile content node? It seems to only let me create one for myself; do I have to log in as each new user I create, to give them nodeprofile content? The site also just seems to present the default non-node user profile after the nodeprofile node has been created: any way of automatically redirecting?)

#6

fago - May 14, 2007 - 10:52
Title:No usernodes created» cck field prevents node creation with drupal_execute
Project:Usernode» Content Construction Kit (CCK)
Version:5.x-1.2» 5.x-1.x-dev
Component:Code» General

@nodeprofile: yes, I'm the author of nodeprofile. You can set the node author as usual when you are creating a nodeprofile - this will be the profile's user. With nodeprofile 1.1 nodeprofiles are displayed on the user page automatically too.

@the issue:
as removing CCK fields fixes the problem, it seems to be a cck bug.
usernode just invokes drupal_execute() to create the usernodes. I know that some people have already used usernode together with cck fields, so it might be caused by a special cck field.

#7

ica - November 14, 2007 - 14:50

I get the -similar errors with any node type i created on CCK -so it might not be only to do with usernodes (my error points to node.module)
possibly some other field bug that so far i could not find out and eliminate

-error i get is this

warning: Invalid argument supplied for foreach() in /home/modules/node/node.module on line 504.
warning: implode() [function.implode]: Bad arguments. in /home/site/modules/node/node.module on line 508.
user warning: 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 '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE in /home/site/includes/database.mysql.inc on line 172.

i'll post here if i get a breakthrouh, meantime i'll watch this post if someone else comes with a suggestion or fix

#8

vanvemden - September 12, 2007 - 04:36

I had exactly the same errors, I my case I figured out it was the relativity.module (on line 1278) $node = node_load($object->nid) which I temporary changed to $node = $object; :

function relativity_token_values($type, $object = NULL) {
  if ($type == 'node') {
    // I will load the node just to avoid problems with
    // module weights
    //  $node = node_load($object->nid);
    $node = $object;
....

I don't know if you were using the relativity module or one of the other modules was trying to load a node with an empty nid in the hook_token_values function, but I hope it helps to solve the problem.

Greetings,

Marco

#9

moshe weitzman - April 17, 2008 - 13:14
Status:active» active (needs more info)

#10

activelyOUT - June 2, 2008 - 20:34

Hi,

I do not have access to any cck fields when creating my nodeproifles and I get a change message when displaying the usernode:
"You have not created a Usernode yet. Go ahead and create one!"

Running:
drupal 5.7
usernode 5.x.1-3
cck 5.x.1-7

I am using logintoboggin "Set Immediate"
I have a pre-authenticated role defined (pre-auth).
logintoboggin sets me to this role and upon validation I am fully authenticated. Everything works fine when I am validated.
Things break when I am in this pre-auth role.

I use pageroute to walk through a profile setup process.
However, I cannot access any cck fields that are on any of the page.

And I get the following text message when i display the usernode page:
"You have not created a Usernode yet. Go ahead and create one!"

This is odd. has anyone run into this problem?

Chris

#11

Summit - July 12, 2008 - 18:01
Version:5.x-1.x-dev» 5.x-1.7

Subscribing, same situation, errorlog:

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 '' at line 1 query: SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE  in /public_html/includes/database.mysql.inc on line 172.
implode() [<a href='function.implode'>function.implode</a>]: Bad arguments. in /public_html/modules/node/node.module on line 565.
Invalid argument supplied for foreach() in /public_html/modules/node/node.module on line 561.

Please assist! Thanks a lot in advance!

greetings,
Martijn

#12

drew reece - July 27, 2008 - 13:51

@Summit

I think your problem is not necessarily related to this thread, it seems more like a recent issue that is also mentioned elsewhere…

http://drupal.org/node/142286
http://drupal.org/node/282305
http://drupal.org/node/283805

Drew

#13

KarenS - August 26, 2008 - 16:28
Status:active (needs more info)» duplicate

Probably related to the drupal_execute() problem at #128038: Critical failures using drupal_execute() on nodes with CCK fields.

 
 

Drupal is a registered trademark of Dries Buytaert.