updated user_import
This commit is contained in:
parent
3a55dcea49
commit
fb0666538c
@ -84,6 +84,37 @@ function field_user_import_default_field_processor($user_fields, $field_name, $v
|
|||||||
return $field;
|
return $field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function field_user_import_taxonomy_field_processor($user_fields, $field_name, $values) {
|
||||||
|
|
||||||
|
$field = $user_fields->$field_name;
|
||||||
|
|
||||||
|
for ($i = 0; $i < count($values); $i++) {
|
||||||
|
if (empty($values[$i])) {
|
||||||
|
continue; // Do not save empty fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get taxonomy term ID before saving if term already exists
|
||||||
|
$field_info = field_info_field($field_name);
|
||||||
|
$vocabulary = $field_info['settings']['allowed_values'][0]['vocabulary'];
|
||||||
|
$tid = taxonomy_get_term_by_name($values[$i], $vocabulary);
|
||||||
|
|
||||||
|
if (empty($tid)) {
|
||||||
|
// Create a new taxonomy term
|
||||||
|
$field[LANGUAGE_NONE][$i]['tid'] = 'autocreate';
|
||||||
|
$field[LANGUAGE_NONE][$i]['vid'] = taxonomy_vocabulary_machine_name_load($vocabulary)->vid;
|
||||||
|
$field[LANGUAGE_NONE][$i]['name'] = $values[$i];
|
||||||
|
$field[LANGUAGE_NONE][$i]['description'] = '';
|
||||||
|
$field[LANGUAGE_NONE][$i]['format'] = 'plain_text';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$field[LANGUAGE_NONE][$i]['tid'] = array_shift($tid)->tid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $field;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function field_user_import_supported_fields($output = 'all') {
|
function field_user_import_supported_fields($output = 'all') {
|
||||||
static $supported = array();
|
static $supported = array();
|
||||||
|
|
||||||
@ -142,7 +173,7 @@ function field_user_import_supported_fields($output = 'all') {
|
|||||||
|
|
||||||
$supported['taxonomy_term_reference'] = array(
|
$supported['taxonomy_term_reference'] = array(
|
||||||
'validate' => 'field_user_import_default_field_validator',
|
'validate' => 'field_user_import_default_field_validator',
|
||||||
'save' => 'field_user_import_default_field_processor',
|
'save' => 'field_user_import_taxonomy_field_processor',
|
||||||
);
|
);
|
||||||
|
|
||||||
/** Unsupported for the moment **/
|
/** Unsupported for the moment **/
|
||||||
|
@ -99,35 +99,6 @@ function _user_import_send_email($account, $password, $profile, $subject, $body,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of hook_mail().
|
|
||||||
*/
|
|
||||||
function user_import_mail($key, &$message, $params) {
|
|
||||||
|
|
||||||
switch ($key) {
|
|
||||||
case 'welcome':
|
|
||||||
$message['subject'] = (empty($params['subject'])) ? _user_mail_text('register_admin_created_subject', $message['language'], $params) : strtr($params['subject'], $params);
|
|
||||||
$body = (empty($params['body'])) ? _user_mail_text('register_admin_created_body', $message['language'], $params) : strtr($params['body'], $params);
|
|
||||||
|
|
||||||
if ($params['email_format'] == 1) {
|
|
||||||
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8';
|
|
||||||
|
|
||||||
$body_head = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />';
|
|
||||||
|
|
||||||
if (!empty($params['css'])) $body_head .= '<style type="text/css">' . check_plain($params['css']) . '</style>';
|
|
||||||
$message['body'][] = $body_head . '</head><body>' . $body . '</body></html>';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$message['body'][] = $body;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _user_import_edit_settings_fields(&$form, $import, $collapsed) {
|
function _user_import_edit_settings_fields(&$form, $import, $collapsed) {
|
||||||
|
|
||||||
$form['optional'] = array(
|
$form['optional'] = array(
|
||||||
|
@ -11,9 +11,9 @@ files[] = user_import.test
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
; Information added by Drupal.org packaging script on 2015-04-01
|
; Information added by Drupal.org packaging script on 2016-03-06
|
||||||
version = "7.x-2.3"
|
version = "7.x-3.2"
|
||||||
core = "7.x"
|
core = "7.x"
|
||||||
project = "user_import"
|
project = "user_import"
|
||||||
datestamp = "1427908388"
|
datestamp = "1457261641"
|
||||||
|
|
||||||
|
@ -146,6 +146,34 @@ function user_import_schema() {
|
|||||||
return $schema;
|
return $schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of hook_install().
|
||||||
|
*/
|
||||||
|
function user_import_install() {
|
||||||
|
|
||||||
|
// Add a new mail system for HTML emails.
|
||||||
|
$mail_system = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
|
||||||
|
$mail_system['user_import'] = 'UserImportMailSystem';
|
||||||
|
variable_set('mail_system', $mail_system);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of hook_uninstall().
|
||||||
|
*/
|
||||||
|
function user_import_uninstall() {
|
||||||
|
variable_del('user_import_settings');
|
||||||
|
variable_del('user_import_max');
|
||||||
|
variable_del('user_import_line_max');
|
||||||
|
variable_del('user_export_checked_usernames');
|
||||||
|
variable_del('user_import_profile_date_format');
|
||||||
|
|
||||||
|
//
|
||||||
|
$mail_system = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
|
||||||
|
unset($mail_system['user_import']);
|
||||||
|
variable_set('mail_system', $mail_system);
|
||||||
|
}
|
||||||
|
|
||||||
function user_import_update_1() {
|
function user_import_update_1() {
|
||||||
$ret = array();
|
$ret = array();
|
||||||
_system_update_utf8(array('user_import', 'user_import_errors'));
|
_system_update_utf8(array('user_import', 'user_import_errors'));
|
||||||
@ -249,15 +277,13 @@ function user_import_update_7200(&$sandbox) {
|
|||||||
db_add_field('user_import', 'auto_import_directory', $field);
|
db_add_field('user_import', 'auto_import_directory', $field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of hook_uninstall().
|
* Add a new mail system for HTML emails.
|
||||||
*/
|
*/
|
||||||
function user_import_uninstall() {
|
function user_import_update_7201() {
|
||||||
variable_del('user_import_settings');
|
$ret = array();
|
||||||
variable_del('user_import_max');
|
$mail_system = variable_get('mail_system', array('default-system' => 'DefaultMailSystem'));
|
||||||
variable_del('user_import_line_max');
|
$mail_system['user_import'] = 'UserImportMailSystem';
|
||||||
variable_del('user_export_checked_usernames');
|
variable_set('mail_system', $mail_system);
|
||||||
variable_del('user_import_profile_date_format');
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Update options for existing users
|
// Update options for existing users
|
||||||
define ('UPDATE_NONE', 0);
|
define('UPDATE_NONE', 0);
|
||||||
define ('UPDATE_REPLACE', 1);
|
define('UPDATE_REPLACE', 1);
|
||||||
define ('UPDATE_ADD', 2);
|
define('UPDATE_ADD', 2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* - - - - - - - - HOOKS - - - - - - - -
|
* - - - - - - - - HOOKS - - - - - - - -
|
||||||
@ -50,7 +50,7 @@ function user_import_theme() {
|
|||||||
function user_import_permission() {
|
function user_import_permission() {
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'import users' => array(
|
'import users' => array(
|
||||||
'title' => t('Import users'),
|
'title' => t('Import users'),
|
||||||
'description' => t('Import users.'),
|
'description' => t('Import users.'),
|
||||||
),
|
),
|
||||||
@ -65,7 +65,7 @@ function user_import_permission() {
|
|||||||
* Implementation of hook_menu().
|
* Implementation of hook_menu().
|
||||||
*/
|
*/
|
||||||
function user_import_menu() {
|
function user_import_menu() {
|
||||||
$items['admin/people/user_import'] = array(
|
$items['admin/people/user_import'] = array(
|
||||||
'title' => 'Import',
|
'title' => 'Import',
|
||||||
'description' => 'Import or update users from a comma separated file (csv).',
|
'description' => 'Import or update users from a comma separated file (csv).',
|
||||||
'page callback' => 'user_import_list',
|
'page callback' => 'user_import_list',
|
||||||
@ -73,14 +73,14 @@ function user_import_menu() {
|
|||||||
'type' => MENU_LOCAL_TASK,
|
'type' => MENU_LOCAL_TASK,
|
||||||
'file' => 'user_import.admin.inc',
|
'file' => 'user_import.admin.inc',
|
||||||
);
|
);
|
||||||
$items['admin/people/user_import/list'] = array(
|
$items['admin/people/user_import/list'] = array(
|
||||||
'title' => 'List Imports',
|
'title' => 'List Imports',
|
||||||
'access arguments' => array('import users'),
|
'access arguments' => array('import users'),
|
||||||
'weight' => -10,
|
'weight' => -10,
|
||||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||||
'file' => 'user_import.admin.inc',
|
'file' => 'user_import.admin.inc',
|
||||||
);
|
);
|
||||||
$items['admin/people/user_import/add'] = array(
|
$items['admin/people/user_import/add'] = array(
|
||||||
'title' => 'New Import',
|
'title' => 'New Import',
|
||||||
'page callback' => 'user_import_preferences',
|
'page callback' => 'user_import_preferences',
|
||||||
'access arguments' => array('import users'),
|
'access arguments' => array('import users'),
|
||||||
@ -88,31 +88,31 @@ function user_import_menu() {
|
|||||||
'type' => MENU_LOCAL_TASK,
|
'type' => MENU_LOCAL_TASK,
|
||||||
'file' => 'user_import.admin.inc',
|
'file' => 'user_import.admin.inc',
|
||||||
);
|
);
|
||||||
$items['admin/people/user_import/continue/%'] = array(
|
$items['admin/people/user_import/continue/%'] = array(
|
||||||
'title' => 'Continue',
|
'title' => 'Continue',
|
||||||
'page callback' => 'drupal_get_form',
|
'page callback' => 'drupal_get_form',
|
||||||
'page arguments' => array('user_import_confirm_continue', 4),
|
'page arguments' => array('user_import_confirm_continue', 4),
|
||||||
'access arguments' => array('import users'),
|
'access arguments' => array('import users'),
|
||||||
'type' => MENU_CALLBACK,
|
'type' => MENU_CALLBACK,
|
||||||
'file' => 'user_import.admin.inc',
|
'file' => 'user_import.admin.inc',
|
||||||
);
|
);
|
||||||
$items['admin/people/user_import/import/%'] = array(
|
$items['admin/people/user_import/import/%'] = array(
|
||||||
'title' => 'Import',
|
'title' => 'Import',
|
||||||
'page callback' => 'drupal_get_form',
|
'page callback' => 'drupal_get_form',
|
||||||
'page arguments' => array('user_import_confirm_import', 4),
|
'page arguments' => array('user_import_confirm_import', 4),
|
||||||
'access arguments' => array('import users'),
|
'access arguments' => array('import users'),
|
||||||
'type' => MENU_CALLBACK,
|
'type' => MENU_CALLBACK,
|
||||||
'file' => 'user_import.admin.inc',
|
'file' => 'user_import.admin.inc',
|
||||||
);
|
);
|
||||||
$items['admin/people/user_import/delete/%'] = array(
|
$items['admin/people/user_import/delete/%'] = array(
|
||||||
'title' => 'Delete Import',
|
'title' => 'Delete Import',
|
||||||
'page callback' => 'drupal_get_form',
|
'page callback' => 'drupal_get_form',
|
||||||
'page arguments' => array('user_import_confirm_delete', 4),
|
'page arguments' => array('user_import_confirm_delete', 4),
|
||||||
'access arguments' => array('import users'),
|
'access arguments' => array('import users'),
|
||||||
'type' => MENU_CALLBACK,
|
'type' => MENU_CALLBACK,
|
||||||
'file' => 'user_import.admin.inc',
|
'file' => 'user_import.admin.inc',
|
||||||
);
|
);
|
||||||
$items['admin/people/user_import/configure'] = array(
|
$items['admin/people/user_import/configure'] = array(
|
||||||
'title' => 'Configure',
|
'title' => 'Configure',
|
||||||
'page callback' => 'drupal_get_form',
|
'page callback' => 'drupal_get_form',
|
||||||
'page arguments' => array('user_import_configure_form'),
|
'page arguments' => array('user_import_configure_form'),
|
||||||
@ -120,10 +120,10 @@ function user_import_menu() {
|
|||||||
'type' => MENU_LOCAL_TASK,
|
'type' => MENU_LOCAL_TASK,
|
||||||
'file' => 'user_import.admin.inc',
|
'file' => 'user_import.admin.inc',
|
||||||
);
|
);
|
||||||
$items['admin/people/user_import/errors/%'] = array(
|
$items['admin/people/user_import/errors/%'] = array(
|
||||||
'title' => 'Import Errors',
|
'title' => 'Import Errors',
|
||||||
'page callback' => 'user_import_limited_errors',
|
'page callback' => 'user_import_limited_errors',
|
||||||
'page arguments' => array(4),
|
'page arguments' => array(4),
|
||||||
'type' => MENU_CALLBACK,
|
'type' => MENU_CALLBACK,
|
||||||
'access arguments' => array('limited user import'),
|
'access arguments' => array('limited user import'),
|
||||||
);
|
);
|
||||||
@ -182,20 +182,20 @@ function user_import_trigger_imports() {
|
|||||||
foreach ($imports as $import) {
|
foreach ($imports as $import) {
|
||||||
// Check for file in the uploads directory of this template.
|
// Check for file in the uploads directory of this template.
|
||||||
$directory = 'private://user_import/uploads/' . $import->auto_import_directory;
|
$directory = 'private://user_import/uploads/' . $import->auto_import_directory;
|
||||||
$files = file_scan_directory($directory, '/.*$/');
|
$files = file_scan_directory($directory, '/.*$/');
|
||||||
|
|
||||||
foreach ($files as $import_file) {
|
foreach ($files as $import_file) {
|
||||||
// Move file to processing directory.
|
// Move file to processing directory.
|
||||||
$filename_new = $import_file->filename . '-' . rand(1000000, 2000000);
|
$filename_new = $import_file->filename . '-' . rand(1000000, 2000000);
|
||||||
$import_file_new = file_unmanaged_move($import_file->uri, 'private://user_import/processing/' . $filename_new);
|
$import_file_new = file_unmanaged_move($import_file->uri, 'private://user_import/processing/' . $filename_new);
|
||||||
|
|
||||||
// Create import.
|
// Create import.
|
||||||
|
|
||||||
// Get template.
|
// Get template.
|
||||||
$settings = _user_import_settings_select($import->import_id);
|
$settings = _user_import_settings_select($import->import_id);
|
||||||
$import_id = '';
|
$import_id = '';
|
||||||
$name = '';
|
$name = '';
|
||||||
$pointer = 0;
|
$pointer = 0;
|
||||||
$processed = 0;
|
$processed = 0;
|
||||||
$valid = 0;
|
$valid = 0;
|
||||||
$field_match = isset($settings['field_match']) ? serialize($settings['field_match']) : '';
|
$field_match = isset($settings['field_match']) ? serialize($settings['field_match']) : '';
|
||||||
@ -203,12 +203,12 @@ function user_import_trigger_imports() {
|
|||||||
$options = isset($settings['options']) ? serialize($settings['options']) : '';
|
$options = isset($settings['options']) ? serialize($settings['options']) : '';
|
||||||
$setting = 'import';
|
$setting = 'import';
|
||||||
|
|
||||||
$file->filename = $filename_new;
|
$file->filename = $filename_new;
|
||||||
$file->oldfilename = $import_file->filename;
|
$file->oldfilename = $import_file->filename;
|
||||||
$file->filepath = 'private://user_import/processing/' . $filename_new;
|
$file->filepath = 'private://user_import/processing/' . $filename_new;
|
||||||
|
|
||||||
$import_id = user_import_import_set($name, $file, $pointer, $processed, $valid, $field_match, $roles, $options, $setting, $import_id);
|
$import_id = user_import_import_set($name, $file, $pointer, $processed, $valid, $field_match, $roles, $options, $setting, $import_id);
|
||||||
$settings = _user_import_settings_select($import_id);
|
$settings = _user_import_settings_select($import_id);
|
||||||
_user_import_process($settings);
|
_user_import_process($settings);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -230,10 +230,10 @@ function user_import_trigger_imports() {
|
|||||||
if (!$imported) {
|
if (!$imported) {
|
||||||
|
|
||||||
$import_id = '';
|
$import_id = '';
|
||||||
$name = '';
|
$name = '';
|
||||||
$pointer = 0;
|
$pointer = 0;
|
||||||
$processed = 0;
|
$processed = 0;
|
||||||
$valid = 0;
|
$valid = 0;
|
||||||
|
|
||||||
|
|
||||||
$field_match = isset($settings['field_match']) ? serialize($settings['field_match']) : '';
|
$field_match = isset($settings['field_match']) ? serialize($settings['field_match']) : '';
|
||||||
@ -241,12 +241,12 @@ function user_import_trigger_imports() {
|
|||||||
$options = isset($settings['options']) ? serialize($settings['options']) : '';
|
$options = isset($settings['options']) ? serialize($settings['options']) : '';
|
||||||
$setting = 'import';
|
$setting = 'import';
|
||||||
|
|
||||||
$file->filename = $filename;
|
$file->filename = $filename;
|
||||||
$file->oldfilename = $filename;
|
$file->oldfilename = $filename;
|
||||||
$file->filepath = drupal_get_path('module', 'user_import') . '/' . $filename;
|
$file->filepath = drupal_get_path('module', 'user_import') . '/' . $filename;
|
||||||
|
|
||||||
$import_id = user_import_import_set($name, $file, $pointer, $processed, $valid, $field_match, $roles, $options, $setting, $import_id);
|
$import_id = user_import_import_set($name, $file, $pointer, $processed, $valid, $field_match, $roles, $options, $setting, $import_id);
|
||||||
$settings = _user_import_settings_select($import_id);
|
$settings = _user_import_settings_select($import_id);
|
||||||
_user_import_process($settings);
|
_user_import_process($settings);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -280,10 +280,10 @@ function user_import_limited_errors($import_id = NULL, $template_id = NULL) {
|
|||||||
drupal_goto('admin/people/user_import/' . $template_id);
|
drupal_goto('admin/people/user_import/' . $template_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pager_id = 1;
|
$pager_id = 1;
|
||||||
$max = 25;
|
$max = 25;
|
||||||
$import = _user_import_settings_select($import_id);
|
$import = _user_import_settings_select($import_id);
|
||||||
$output = '';
|
$output = '';
|
||||||
$file_lines = array();
|
$file_lines = array();
|
||||||
|
|
||||||
$total = db_query('SELECT count(data) FROM {user_import_errors} WHERE import_id = :import_id', array(':import_id' => $import_id))->fetchField();
|
$total = db_query('SELECT count(data) FROM {user_import_errors} WHERE import_id = :import_id', array(':import_id' => $import_id))->fetchField();
|
||||||
@ -313,10 +313,17 @@ function user_import_limited_errors($import_id = NULL, $template_id = NULL) {
|
|||||||
$result = $query->execute();
|
$result = $query->execute();
|
||||||
|
|
||||||
foreach ($result as $line) {
|
foreach ($result as $line) {
|
||||||
$file_lines[] = array('data' => unserialize($line->data), 'errors' => unserialize($line->errors));
|
$file_lines[] = array(
|
||||||
|
'data' => unserialize($line->data),
|
||||||
|
'errors' => unserialize($line->errors)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$output .= theme('user_import_errors_display', array('import' => $import, 'file_lines' => $file_lines, 'total' => $total));
|
$output .= theme('user_import_errors_display', array(
|
||||||
|
'import' => $import,
|
||||||
|
'file_lines' => $file_lines,
|
||||||
|
'total' => $total
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$output .= l(t('Return'), "admin/people/user_import");
|
$output .= l(t('Return'), "admin/people/user_import");
|
||||||
@ -344,13 +351,22 @@ function theme_user_import_list() {
|
|||||||
$output = '';
|
$output = '';
|
||||||
$imports = _user_import_settings_select();
|
$imports = _user_import_settings_select();
|
||||||
|
|
||||||
if (!$imports) return ' ';
|
if (!$imports) {
|
||||||
|
return ' ';
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($imports as $import) {
|
foreach ($imports as $import) {
|
||||||
|
|
||||||
// header labels
|
// header labels
|
||||||
$import_label = ($import['setting'] == 'tested' || $import['setting'] == 'test') ? t('importable') : t('imported');
|
$import_label = ($import['setting'] == 'tested' || $import['setting'] == 'test') ? t('importable') : t('imported');
|
||||||
$header = array(t('file'), t('started'), t('processed'), $import_label, t('errors'), t('status'));
|
$header = array(
|
||||||
|
t('file'),
|
||||||
|
t('started'),
|
||||||
|
t('processed'),
|
||||||
|
$import_label,
|
||||||
|
t('errors'),
|
||||||
|
t('status')
|
||||||
|
);
|
||||||
|
|
||||||
// info row
|
// info row
|
||||||
$errors = db_query('SELECT COUNT(import_id) FROM {user_import_errors} WHERE import_id = :import_id', array(':import_id' => $import['import_id']))->fetchField();
|
$errors = db_query('SELECT COUNT(import_id) FROM {user_import_errors} WHERE import_id = :import_id', array(':import_id' => $import['import_id']))->fetchField();
|
||||||
@ -373,8 +389,12 @@ function theme_user_import_list() {
|
|||||||
$import_link = l(t('Import'), 'admin/people/user_import/import/' . $import['import_id']);
|
$import_link = l(t('Import'), 'admin/people/user_import/import/' . $import['import_id']);
|
||||||
|
|
||||||
$output .= $delete_link;
|
$output .= $delete_link;
|
||||||
if ($import['setting'] == 'tested' || $import['setting'] == 'test') $output .= ' | ' . $import_link;
|
if ($import['setting'] == 'tested' || $import['setting'] == 'test') {
|
||||||
if ($import['setting'] == 'test' || $import['setting'] == 'import') $output .= ' | ' . $continue_link;
|
$output .= ' | ' . $import_link;
|
||||||
|
}
|
||||||
|
if ($import['setting'] == 'test' || $import['setting'] == 'import') {
|
||||||
|
$output .= ' | ' . $continue_link;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
@ -385,7 +405,12 @@ function theme_user_import_edit($variables) {
|
|||||||
$output = '';
|
$output = '';
|
||||||
$rows = array();
|
$rows = array();
|
||||||
$form = $variables['form'];
|
$form = $variables['form'];
|
||||||
$header = array(t('CSV column'), t('Drupal fields'), t('Username'), t('Abbreviate'));
|
$header = array(
|
||||||
|
t('CSV column'),
|
||||||
|
t('Drupal fields'),
|
||||||
|
t('Username'),
|
||||||
|
t('Abbreviate')
|
||||||
|
);
|
||||||
|
|
||||||
foreach (element_children($form['field_match']) as $key) {
|
foreach (element_children($form['field_match']) as $key) {
|
||||||
|
|
||||||
@ -397,7 +422,10 @@ function theme_user_import_edit($variables) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$form['field_match']['#value'] = theme('table', array('header' => $header, 'rows' => $rows));
|
$form['field_match']['#value'] = theme('table', array(
|
||||||
|
'header' => $header,
|
||||||
|
'rows' => $rows
|
||||||
|
));
|
||||||
|
|
||||||
if (isset($form['remove'])) {
|
if (isset($form['remove'])) {
|
||||||
$output .= drupal_render($form['remove']);
|
$output .= drupal_render($form['remove']);
|
||||||
@ -443,7 +471,10 @@ function theme_user_import_errors_display($settings) {
|
|||||||
|
|
||||||
if (!empty($column_info['username'])) {
|
if (!empty($column_info['username'])) {
|
||||||
$header[$column_info['username']] = t('Name %sort', array('%sort' => $column_info['username']));
|
$header[$column_info['username']] = t('Name %sort', array('%sort' => $column_info['username']));
|
||||||
$row[$column_info['username']] = array("data" => $field_data[0], "align" => "left");
|
$row[$column_info['username']] = array(
|
||||||
|
"data" => $field_data[0],
|
||||||
|
"align" => "left"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($column_info['field_id'] == 'email') {
|
if ($column_info['field_id'] == 'email') {
|
||||||
@ -468,16 +499,18 @@ function theme_user_import_errors_display($settings) {
|
|||||||
|
|
||||||
// Output of table with the paging
|
// Output of table with the paging
|
||||||
$output .= theme('table',
|
$output .= theme('table',
|
||||||
array(
|
array(
|
||||||
"header" => $header,
|
"header" => $header,
|
||||||
"rows" => $rows,
|
"rows" => $rows,
|
||||||
"attributes" => array(),
|
"attributes" => array(),
|
||||||
"sticky" => FALSE, // Table header will be sticky
|
"sticky" => FALSE,
|
||||||
"caption" => '',
|
// Table header will be sticky
|
||||||
"colgroups" => array(),
|
"caption" => '',
|
||||||
"empty" => t("There are no errors.") // The message to be displayed if table is empty
|
"colgroups" => array(),
|
||||||
)
|
"empty" => t("There are no errors.")
|
||||||
) . theme("pager");
|
// The message to be displayed if table is empty
|
||||||
|
)
|
||||||
|
) . theme("pager");
|
||||||
|
|
||||||
//$output .= theme('table', array('header' => $header, 'rows' => $rows));
|
//$output .= theme('table', array('header' => $header, 'rows' => $rows));
|
||||||
return $output;
|
return $output;
|
||||||
@ -500,24 +533,35 @@ function theme_user_import_username_errors($errors) {
|
|||||||
|
|
||||||
function _user_import_settings_save($settings) {
|
function _user_import_settings_save($settings) {
|
||||||
// Database field defaults.
|
// Database field defaults.
|
||||||
$database_fields = array('import_id' => NULL,
|
$database_fields = array(
|
||||||
'name' => '',
|
'import_id' => NULL,
|
||||||
'auto_import_directory' => '',
|
'name' => '',
|
||||||
'filename' => '',
|
'auto_import_directory' => '',
|
||||||
'oldfilename' => '',
|
'filename' => '',
|
||||||
'filepath' => '',
|
'oldfilename' => '',
|
||||||
'started' => 0,
|
'filepath' => '',
|
||||||
'pointer' => 0,
|
'started' => 0,
|
||||||
'processed' => 0,
|
'pointer' => 0,
|
||||||
'valid' => 0,
|
'processed' => 0,
|
||||||
'field_match' => array(),
|
'valid' => 0,
|
||||||
'roles' => '',
|
'field_match' => array(),
|
||||||
'options' => array(),
|
'roles' => '',
|
||||||
'setting' => '',
|
'options' => array(),
|
||||||
|
'setting' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Form elements we never want to save in the options column.
|
// Form elements we never want to save in the options column.
|
||||||
$form_variables = array('form_id', 'form_token', 'form_build_id', 'cancel', 'import', 'submit', 'op', 0, 'return_path');
|
$form_variables = array(
|
||||||
|
'form_id',
|
||||||
|
'form_token',
|
||||||
|
'form_build_id',
|
||||||
|
'cancel',
|
||||||
|
'import',
|
||||||
|
'submit',
|
||||||
|
'op',
|
||||||
|
0,
|
||||||
|
'return_path'
|
||||||
|
);
|
||||||
$form_variables = array_flip($form_variables);
|
$form_variables = array_flip($form_variables);
|
||||||
|
|
||||||
// Remove settings we don't need in the options column.
|
// Remove settings we don't need in the options column.
|
||||||
@ -529,7 +573,7 @@ function _user_import_settings_save($settings) {
|
|||||||
$options['email_domain'] = trim($options['email_domain']);
|
$options['email_domain'] = trim($options['email_domain']);
|
||||||
|
|
||||||
if (substr($options['email_domain'], 0, 1) != '@') {
|
if (substr($options['email_domain'], 0, 1) != '@') {
|
||||||
$options['email_domain'] = '@'. $options['email_domain'];
|
$options['email_domain'] = '@' . $options['email_domain'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,7 +587,7 @@ function _user_import_settings_save($settings) {
|
|||||||
$settings['options']['email_domain'] = trim($settings['options']['email_domain']);
|
$settings['options']['email_domain'] = trim($settings['options']['email_domain']);
|
||||||
|
|
||||||
if (substr($settings['options']['email_domain'], 0, 1) != '@') {
|
if (substr($settings['options']['email_domain'], 0, 1) != '@') {
|
||||||
$settings['options']['email_domain'] = '@'. $settings['options']['email_domain'];
|
$settings['options']['email_domain'] = '@' . $settings['options']['email_domain'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,9 +596,9 @@ function _user_import_settings_save($settings) {
|
|||||||
$settings[$key] = isset($settings[$key]) ? $settings[$key] : $value;
|
$settings[$key] = isset($settings[$key]) ? $settings[$key] : $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default values.
|
// Set default values.
|
||||||
$import_id = isset($settings['import_id']) ? $settings['import_id'] : '';
|
$import_id = isset($settings['import_id']) ? $settings['import_id'] : '';
|
||||||
$name = isset($settings['name']) ? trim($settings['name']) : '';
|
$name = isset($settings['name']) ? trim($settings['name']) : '';
|
||||||
$pointer = isset($settings['pointer']) ? $settings['pointer'] : 0;
|
$pointer = isset($settings['pointer']) ? $settings['pointer'] : 0;
|
||||||
$processed = isset($settings['processed']) ? $settings['processed'] : 0;
|
$processed = isset($settings['processed']) ? $settings['processed'] : 0;
|
||||||
$valid = isset($settings['valid']) ? $settings['valid'] : 0;
|
$valid = isset($settings['valid']) ? $settings['valid'] : 0;
|
||||||
@ -571,7 +615,8 @@ function _user_import_settings_save($settings) {
|
|||||||
$auto_import_directory = '';
|
$auto_import_directory = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$file->filename = isset($settings['filename']) ? $settings['filename'] : '';
|
$file = new ArrayObject();
|
||||||
|
$file->filename = isset($settings['filename']) ? $settings['filename'] : '';
|
||||||
$file->oldfilename = isset($settings['oldfilename']) ? $settings['oldfilename'] : '';
|
$file->oldfilename = isset($settings['oldfilename']) ? $settings['oldfilename'] : '';
|
||||||
$file->filepath = isset($settings['filepath']) ? $settings['filepath'] : '';
|
$file->filepath = isset($settings['filepath']) ? $settings['filepath'] : '';
|
||||||
|
|
||||||
@ -587,19 +632,19 @@ function user_import_import_set($name = '', $file = '', $pointer = 0, $processed
|
|||||||
|
|
||||||
db_update('user_import')
|
db_update('user_import')
|
||||||
->fields(array(
|
->fields(array(
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'auto_import_directory' => $auto_import_directory,
|
'auto_import_directory' => $auto_import_directory,
|
||||||
'filename' => $file->filename,
|
'filename' => $file->filename,
|
||||||
'oldfilename' => $file->oldfilename,
|
'oldfilename' => $file->oldfilename,
|
||||||
'filepath' => $file->filepath,
|
'filepath' => $file->filepath,
|
||||||
'pointer' => $pointer,
|
'pointer' => $pointer,
|
||||||
'processed' => $processed,
|
'processed' => $processed,
|
||||||
'valid' => $valid,
|
'valid' => $valid,
|
||||||
'field_match' => $field_match,
|
'field_match' => $field_match,
|
||||||
'roles' => $roles,
|
'roles' => $roles,
|
||||||
'options' => $options,
|
'options' => $options,
|
||||||
'setting' => $setting
|
'setting' => $setting
|
||||||
))
|
))
|
||||||
->condition('import_id', $import_id)
|
->condition('import_id', $import_id)
|
||||||
->execute();
|
->execute();
|
||||||
}
|
}
|
||||||
@ -607,20 +652,20 @@ function user_import_import_set($name = '', $file = '', $pointer = 0, $processed
|
|||||||
|
|
||||||
$import_id = db_insert('user_import')
|
$import_id = db_insert('user_import')
|
||||||
->fields(array(
|
->fields(array(
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'auto_import_directory' => $auto_import_directory,
|
'auto_import_directory' => $auto_import_directory,
|
||||||
'filename' => $file->filename,
|
'filename' => $file->filename,
|
||||||
'oldfilename' => $file->oldfilename,
|
'oldfilename' => $file->oldfilename,
|
||||||
'filepath' => $file->filepath,
|
'filepath' => $file->filepath,
|
||||||
'started' => time(),
|
'started' => time(),
|
||||||
'pointer' => $pointer,
|
'pointer' => $pointer,
|
||||||
'processed' => $processed,
|
'processed' => $processed,
|
||||||
'valid' => $valid,
|
'valid' => $valid,
|
||||||
'field_match' => $field_match,
|
'field_match' => $field_match,
|
||||||
'roles' => $roles,
|
'roles' => $roles,
|
||||||
'options' => $options,
|
'options' => $options,
|
||||||
'setting' => $setting
|
'setting' => $setting
|
||||||
))
|
))
|
||||||
->execute();
|
->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,16 +678,22 @@ function user_import_import_set($name = '', $file = '', $pointer = 0, $processed
|
|||||||
function _user_import_settings_select($import_id = NULL, $template = FALSE) {
|
function _user_import_settings_select($import_id = NULL, $template = FALSE) {
|
||||||
$import = array();
|
$import = array();
|
||||||
|
|
||||||
if (!empty($import_id) && !is_numeric($import_id)) return;
|
if (!empty($import_id) && !is_numeric($import_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($import_id)) {
|
if (!empty($import_id)) {
|
||||||
$sql = 'SELECT * FROM {user_import} WHERE import_id = :import_id';
|
$sql = 'SELECT * FROM {user_import} WHERE import_id = :import_id';
|
||||||
if ($template) $sql .= " AND setting = 'template'";
|
if ($template) {
|
||||||
|
$sql .= " AND setting = 'template'";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$import = (array)db_query_range($sql, 0, 1, array(':import_id' => $import_id))->fetchObject();
|
$import = (array) db_query_range($sql, 0, 1, array(':import_id' => $import_id))->fetchObject();
|
||||||
|
|
||||||
if (empty($import)) return FALSE;
|
if (empty($import)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
$import['field_match'] = unserialize($import['field_match']);
|
$import['field_match'] = unserialize($import['field_match']);
|
||||||
$import['roles'] = unserialize($import['roles']);
|
$import['roles'] = unserialize($import['roles']);
|
||||||
@ -660,7 +711,7 @@ function _user_import_settings_select($import_id = NULL, $template = FALSE) {
|
|||||||
$result = db_query($query);
|
$result = db_query($query);
|
||||||
|
|
||||||
foreach ($result as $row_data) {
|
foreach ($result as $row_data) {
|
||||||
$row = (array)$row_data;
|
$row = (array) $row_data;
|
||||||
$row['field_match'] = unserialize($row['field_match']);
|
$row['field_match'] = unserialize($row['field_match']);
|
||||||
$row['roles'] = unserialize($row['roles']);
|
$row['roles'] = unserialize($row['roles']);
|
||||||
$row['options'] = unserialize($row['options']);
|
$row['options'] = unserialize($row['options']);
|
||||||
@ -678,7 +729,7 @@ function _user_import_settings_select($import_id = NULL, $template = FALSE) {
|
|||||||
|
|
||||||
function _user_import_settings_deletion($import_id) {
|
function _user_import_settings_deletion($import_id) {
|
||||||
|
|
||||||
$sql = 'SELECT auto_import_directory FROM {user_import} WHERE import_id = :import_id';
|
$sql = 'SELECT auto_import_directory FROM {user_import} WHERE import_id = :import_id';
|
||||||
$auto_import_directory = db_query_range($sql, 0, 1, array(':import_id' => $import_id))->fetchField();
|
$auto_import_directory = db_query_range($sql, 0, 1, array(':import_id' => $import_id))->fetchField();
|
||||||
|
|
||||||
if (!empty($auto_import_directory)) {
|
if (!empty($auto_import_directory)) {
|
||||||
@ -794,15 +845,19 @@ function _user_import_file_deletion($filepath, $filename, $old_filename, $ftp, $
|
|||||||
$file = new stdClass();
|
$file = new stdClass();
|
||||||
$file->uri = $filepath;
|
$file->uri = $filepath;
|
||||||
$file->filename = $filename;
|
$file->filename = $filename;
|
||||||
$file->fid = db_query("SELECT fid FROM {file_managed} WHERE uri = :filepath", array(':filepath' => $filepath))->fetchField();
|
$file->fid = db_query("SELECT fid FROM {file_managed} WHERE uri = :filepath", array(':filepath' => $filepath))->fetchField();;
|
||||||
;
|
|
||||||
$removed = file_delete($file);
|
$removed = file_delete($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$message) return;
|
if (!$message) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (empty($removed)) {
|
if (empty($removed)) {
|
||||||
drupal_set_message(t("File error: file '%old_filename' (%filename) could not be deleted.", array('%old_filename' => $oldfilename, '%filename' => $filename)), 'error');
|
drupal_set_message(t("File error: file '%old_filename' (%filename) could not be deleted.", array(
|
||||||
|
'%old_filename' => $oldfilename,
|
||||||
|
'%filename' => $filename
|
||||||
|
)), 'error');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drupal_set_message(t("File '%old_filename' was deleted.", array('%old_filename' => $old_filename)));
|
drupal_set_message(t("File '%old_filename' was deleted.", array('%old_filename' => $old_filename)));
|
||||||
@ -811,6 +866,91 @@ function _user_import_file_deletion($filepath, $filename, $old_filename, $ftp, $
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of hook_mail().
|
||||||
|
*/
|
||||||
|
function user_import_mail($key, &$message, $params) {
|
||||||
|
|
||||||
|
switch ($key) {
|
||||||
|
case 'welcome':
|
||||||
|
$message['subject'] = (empty($params['subject'])) ? _user_mail_text('register_admin_created_subject', $message['language'], $params) : strtr($params['subject'], $params);
|
||||||
|
$body = (empty($params['body'])) ? _user_mail_text('register_admin_created_body', $message['language'], $params) : strtr($params['body'], $params);
|
||||||
|
|
||||||
|
if ($params['email_format'] == 1) {
|
||||||
|
$message['headers']['Content-Type'] = 'text/html; charset=UTF-8';
|
||||||
|
|
||||||
|
$body_head = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />';
|
||||||
|
|
||||||
|
if (!empty($params['css'])) {
|
||||||
|
$body_head .= '<style type="text/css">' . check_plain($params['css']) . '</style>';
|
||||||
|
}
|
||||||
|
$message['body'][] = $body_head . '</head><body>' . $body . '</body></html>';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$message['body'][] = $body;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify the drupal mail system to send HTML emails.
|
||||||
|
*
|
||||||
|
* See http://drupal.org/node/900794.
|
||||||
|
*/
|
||||||
|
class UserImportMailSystem implements MailSystemInterface {
|
||||||
|
/**
|
||||||
|
* Concatenate and wrap the e-mail body.
|
||||||
|
*
|
||||||
|
* @param $message
|
||||||
|
* A message array, as described in hook_mail_alter().
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The formatted $message.
|
||||||
|
*/
|
||||||
|
public function format(array $message) {
|
||||||
|
$message['body'] = implode("\n\n", $message['body']);
|
||||||
|
return $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send an e-mail message, using Drupal variables and default settings.
|
||||||
|
*
|
||||||
|
* @see <a href="http://php.net/manual/en/function.mail.php
|
||||||
|
* " title="http://php.net/manual/en/function.mail.php
|
||||||
|
* " rel="nofollow">http://php.net/manual/en/function.mail.php
|
||||||
|
* </a> * @see drupal_mail()
|
||||||
|
*
|
||||||
|
* @param $message
|
||||||
|
* A message array, as described in hook_mail_alter().
|
||||||
|
* @return
|
||||||
|
* TRUE if the mail was successfully accepted, otherwise FALSE.
|
||||||
|
*/
|
||||||
|
public function mail(array $message) {
|
||||||
|
$mimeheaders = array();
|
||||||
|
foreach ($message['headers'] as $name => $value) {
|
||||||
|
$mimeheaders[] = $name . ': ' . mime_header_encode($value);
|
||||||
|
}
|
||||||
|
$line_endings = variable_get('mail_line_endings', MAIL_LINE_ENDINGS);
|
||||||
|
return mail(
|
||||||
|
$message['to'],
|
||||||
|
mime_header_encode($message['subject']),
|
||||||
|
// Note: e-mail uses CRLF for line-endings. PHP's API requires LF
|
||||||
|
// on Unix and CRLF on Windows. Drupal automatically guesses the
|
||||||
|
// line-ending format appropriate for your system. If you need to
|
||||||
|
// override this, adjust $conf['mail_line_endings'] in settings.php.
|
||||||
|
preg_replace('@\r?\n@', $line_endings, $message['body']),
|
||||||
|
// For headers, PHP's API suggests that we use CRLF normally,
|
||||||
|
// but some MTAs incorrectly replace LF with CRLF. See #234403.
|
||||||
|
join("\n", $mimeheaders)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user