PHP Drupal 7批量用户导入脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Drupal 7批量用户导入脚本相关的知识,希望对你有一定的参考价值。
#!/usr/bin/php
<?php
$users = "
first_name last_name\temail\tpassword\n
first_name last_name\temail\tpassword\n
first_name last_name\temail\tpassword\n
first_name last_name\temail\tpassword\n
first_name last_name\temail\tpassword\n
";
define('DRUPAL_ROOT', getcwd());
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['QUERY_STRING'] = '';
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
include_once DRUPAL_ROOT . '/includes/password.inc';
include_once DRUPAL_ROOT . './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$users = explode("\n", $users);
foreach ($users as $user)
{
if (empty($user))
{
continue;
}
$user = explode("\t", $user);
if (count($user) != 3)
{
continue;
}
$old = user_load_by_mail($user[1]);
if (!empty($old) && $old->uid)
{
continue;
}
$obj = new stdClass();
$obj->name = trim($user[0]);
$obj->pass = user_hash_password(trim($user[2]));
$obj->mail = trim($user[1]);
$obj->theme = 'garland';
$obj->status = 1;
$obj->roles = array(
2 => 'authenticated user',
// here is the role list
// [ROLE_ID] => '[ROLE_NAME]'
);
user_save($obj);
}
echo 'Done';
以上是关于PHP Drupal 7批量用户导入脚本的主要内容,如果未能解决你的问题,请参考以下文章
批量导入csv到drupal数据库
Drupal 7 添加 PHP 到视图过滤器
如何在drupal 7中根据分类术语搜索用户列表?
如何在 Drupal 7 中获取当前登录用户的角色?
php 提示:将功能配置导入drupal
Drupal 7与PHP 7的兼容性