跳转到主要内容
lazybighead 提交于 29 June 2015

【适用场景】1、批量修改node 类型 字段的数值   2、新增node 字段,批量填充该字段建立以前node节点该字段的默认数值。

【具体步骤】1、安装drush   2、编写php脚本文件名 xxxx.php,放置在网站根目录下  3、执行 drush  scr  xxxx.php

【xxxx.php脚本】

<?php
$query=new EntityFieldQuery ;
$query->entityCondition('entity_type','node')
         ->entityCondition('bundle','xy_info')
        ->propertyCondition('status',1)
        ->addMetaData('account',user_load(1));
$reault=$query->execute();
$nid_arr=array_keys(($result['node']));
foreach($nid_arr as $nid){
      $node=node_load($nid);
      $share=$node->field_data_field_bzr['und'][0]['value'];
       if($share) $node->field_data_field_zhuangtai['und'][0]['value']=1;
       field_attach_presave('node',$node);
      field_attach_update('node',$node);
      entity_get_controller('node')->resetCache(array($node->nid));
}

【声明】上述代码由phpartisan提供指导完成最后,感谢phpartisan等各位drupal 大神的悉心指导,让我们一起见证drupal在中国的成长。

Drupal 版本