进行node_save时cck图像消失
我保存一个带有图像的节点,该节点正在被服务填充。我用 drupal_write_record 写入图像,并且图片已经出现在节点中。但是当 - 在脚本末尾 - 我调用 node_save 时,图像再次消失。
我的代码:
$file_drupal_path= $filedata['location'];
$file = new stdClass();
$file->filename = $filedata['name'];
$file->filepath = $file_drupal_path;
$file->filemime = $filedata['mime'];
$file->filesize = filesize($file_drupal_path);
$file->filesource = $filedata['name'];
$file->uid = 1;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
$file->list = 1;
// fid is populated by drupal_write_record
drupal_write_record('files', $file);
$imageData = field_file_load($file->fid, TRUE);
return $imageData;
node_save也有未设置值的键。
function transport_service_save($node) {
$node = (object) ($node);
$node->promote = 1;
node_save(node_submit($node));
return print_r( $node , TRUE );
}
以及节点中 cck 图像字段中的
I save a node with images which is beeing filled by a service. I write the image with drupal_write_record and the pictures appear in the node already. But when - at the end of the script - I call a node_save the image disappears again.
My Code:
$file_drupal_path= $filedata['location'];
$file = new stdClass();
$file->filename = $filedata['name'];
$file->filepath = $file_drupal_path;
$file->filemime = $filedata['mime'];
$file->filesize = filesize($file_drupal_path);
$file->filesource = $filedata['name'];
$file->uid = 1;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
$file->list = 1;
// fid is populated by drupal_write_record
drupal_write_record('files', $file);
$imageData = field_file_load($file->fid, TRUE);
return $imageData;
and the node_save
function transport_service_save($node) {
$node = (object) ($node);
$node->promote = 1;
node_save(node_submit($node));
return print_r( $node , TRUE );
}
in the cck image field in the node there are keys with unset values as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
安德烈亚斯,
有完全相同的问题。
按照此处所述使用
drupal_execute()
立即解决了问题:来源:
http:// /www.drupalisms.com/gregory-go/blog/use-drupalexecute-instead-of-nodesave-to-save-a-node-programmatically
但是一个公平的警告:它对前几个人来说就像一个魅力回合,但现在我收到大量错误类型:
看不到发生了什么变化。我所做的只是多次调用保存的页面来测试它。
最后(希望如此!)编辑此回复。似乎需要包含包含node_form的node.module文件,因此
在代码中添加以下内容(如
hook_init()
)即可解决问题。在这里工作,现在我的节点保存了完整的图像。
Andreas,
Had the exact same problem.
Using
drupal_execute()
as described here fixed the problem immediately:Source:
http://www.drupalisms.com/gregory-go/blog/use-drupalexecute-instead-of-nodesave-to-save-a-node-programmatically
But a fair warning: it ran like a charm for the first few rounds, but now I get tonnes of errors type:
Can't see what changed. All I did was call the page that did the saving a few times to test it.
And a final (hopefully!) edit to this reply. It seems that including the node.module file that contains node_form is needed, so adding this:
in your code (like in
hook_init()
) will do the trick.Worked here, and now my nodes save with images intact.