Drupal node_save 失败但没有给出错误
我正在构建一个批量导入器模块,该模块将从一个数据库获取数据并在 drupal 中创建节点。创建节点对象的代码是这样的:
$node = new stdClass();
$node->type = 'jobs';
$node->uid = 1;
$node->status = $row->J_Approved;
$node->title = $row->J_Title;
$node->comment = 0;
$node->revision = 1;
$node->promote = 0;
$node->sticky = 0;
$node->created = $row->J_DateTime_Mod;
$node->field_description = $row->J_Body;
$node->field_email = $row->J_MI_Email;
$node->field_jobs_fax = $row->J_MI_Phone;
$node->field_aia_firm = $row->J_AIA;
$node->field_name = $row->J_Sub_Name;
$node->field_phone = $row->J_Sub_Phone;
$node->field_jobs_email = $row->J_Sub_Email;
$node = node_submit($node);
node_save($node);
上面的输出在我的调试窗口 http://screencast.com/ t/R5PhWZWraIR8 当我运行它时,它不会创建节点,但正如您从截屏视频中看到的那样,它将 $node->validates 设置为 1,所以我假设它是有效的。我花了大约 5 个小时尝试调试这个,但仍然无法弄清楚。任何帮助将不胜感激...
I'm building a batch importer module that will take data from one database and create the nodes in drupal. The code to create the node object is this:
$node = new stdClass();
$node->type = 'jobs';
$node->uid = 1;
$node->status = $row->J_Approved;
$node->title = $row->J_Title;
$node->comment = 0;
$node->revision = 1;
$node->promote = 0;
$node->sticky = 0;
$node->created = $row->J_DateTime_Mod;
$node->field_description = $row->J_Body;
$node->field_email = $row->J_MI_Email;
$node->field_jobs_fax = $row->J_MI_Phone;
$node->field_aia_firm = $row->J_AIA;
$node->field_name = $row->J_Sub_Name;
$node->field_phone = $row->J_Sub_Phone;
$node->field_jobs_email = $row->J_Sub_Email;
$node = node_submit($node);
node_save($node);
And the above outputs this in my debug window http://screencast.com/t/R5PhWZWraIR8
When I run this, it doesn't create the node, but as you can see from the screencast, it sets $node->validates to 1, so im assuming it is valid. I've spent around 5 hours trying to debug this and still can't figure it out. Any help would be appreciated...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Drupal 6 示例:
node_load() 不返回任何内容,因此不进行检查。
您可以使用以下命令进行检查:
其中 3d arg 将在加载节点之前重置缓存。昂贵,但这是我知道的唯一方法。
然后,您必须相互检查 node->[vars],如果它们全部匹配,则返回 TRUE。
我相信http://www.learn -drupal.in/cck/how-to-create-a-drupal-node-programmatically.html 以及上面的 node_save 代码示例。
Drupal 6 example:
node_load() doesn't return anything, so it doesn't check.
You can check it with:
Where the 3d arg will reset the cache before loading the node. Expensive, but that's the only way I know.
You would then have to check the node->[vars] against each other, and return TRUE if they all match.
I credit http://www.learn-drupal.in/cck/how-to-create-a-drupal-node-programmatically.html with the node_save code example above.