1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Drush commands for CAS.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_drush_command().
|
10
|
*/
|
11
|
function cas_drush_command() {
|
12
|
$items = array();
|
13
|
$items['cas-user-create'] = array(
|
14
|
'callback' => 'cas_drush_user_create',
|
15
|
'description' => dt('Create a CAS user account with the specified CAS username.'),
|
16
|
'arguments' => array(
|
17
|
'cas_name' => 'The CAS username of the account to add',
|
18
|
),
|
19
|
'required-arguments' => TRUE,
|
20
|
'examples' => array(
|
21
|
'drush cas-user-create newcasuser' => 'Create a new user with CAS username newcasuser',
|
22
|
),
|
23
|
);
|
24
|
return $items;
|
25
|
}
|
26
|
|
27
|
/**
|
28
|
* Implementats hook_drush_help().
|
29
|
*/
|
30
|
function cas_drush_help($section) {
|
31
|
switch ($section) {
|
32
|
case 'drush:cas-user-create':
|
33
|
return dt('Create a CAS user account with the specified CAS username.');
|
34
|
}
|
35
|
}
|
36
|
|
37
|
/**
|
38
|
* Creates a new CAS user account.
|
39
|
*/
|
40
|
function cas_drush_user_create($cas_name) {
|
41
|
// @todo: Handle additional options for setting other user attributes.
|
42
|
$account = cas_user_load_by_name($cas_name);
|
43
|
if ($account === FALSE) {
|
44
|
if (!drush_get_context('DRUSH_SIMULATE')) {
|
45
|
$options = array('invoke_cas_user_presave' => TRUE);
|
46
|
$new_user_object = cas_user_register($cas_name, $options);
|
47
|
if ($new_user_object !== FALSE) {
|
48
|
_drush_user_print_info($new_user_object->uid);
|
49
|
// return $new_user_object->uid;
|
50
|
}
|
51
|
else {
|
52
|
drush_set_error(dt('Could not create a new user account with CAS username @cas_name.', array('@cas_name' => $cas_name)));
|
53
|
}
|
54
|
}
|
55
|
}
|
56
|
else {
|
57
|
drush_set_error(dt('There is already a user account with CAS username @cas_name.', array('@cas_name' => $cas_name)));
|
58
|
}
|
59
|
}
|