Drupal node_save 失败但没有给出错误

发布于 2024-11-18 09:12:44 字数 979 浏览 0 评论 0原文

我正在构建一个批量导入器模块,该模块将从一个数据库获取数据并在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绾颜 2024-11-25 09:12:44

Drupal 6 示例:

<?php
$node = new stdClass(); //Create instance of class stdClass which will create node for you.
$node->type = 'library'; //Name of the content type
$node->field_book_no[0][value] = 22;//Book number CCK Field
$node->field_book_name[0][value] = "Drupal"; //Book name  CCK Field
$node->field_book_author[0][value]='Sachin'; //Author name -  CCK field
$node->field_year[0][value]='2011'; //Publication year - CCK field
$node->uid = 1; // user id, 1 is created by admin
$node->status = 1;//1 is published, 0 is unpublished
$node->promote = 0;//1 is promote to home page, 0 is not to promote on home page
node_save($node); // Save this node
?>

node_load() 不返回任何内容,因此不进行检查。

您可以使用以下命令进行检查:

$new_node = node_load($node->nid, NULL, TRUE);

其中 3d arg 将在加载节点之前重置缓存。昂贵,但这是我知道的唯一方法。

然后,您必须相互检查 node->[vars],如果它们全部匹配,则返回 TRUE。

我相信http://www.learn -drupal.in/cck/how-to-create-a-drupal-node-programmatically.html 以及上面的 node_save 代码示例。

Drupal 6 example:

<?php
$node = new stdClass(); //Create instance of class stdClass which will create node for you.
$node->type = 'library'; //Name of the content type
$node->field_book_no[0][value] = 22;//Book number CCK Field
$node->field_book_name[0][value] = "Drupal"; //Book name  CCK Field
$node->field_book_author[0][value]='Sachin'; //Author name -  CCK field
$node->field_year[0][value]='2011'; //Publication year - CCK field
$node->uid = 1; // user id, 1 is created by admin
$node->status = 1;//1 is published, 0 is unpublished
$node->promote = 0;//1 is promote to home page, 0 is not to promote on home page
node_save($node); // Save this node
?>

node_load() doesn't return anything, so it doesn't check.

You can check it with:

$new_node = node_load($node->nid, NULL, TRUE);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文