Created
May 23, 2016 20:44
-
-
Save dregad/758fcb135bbf3a05f26ca676804a21e9 to your computer and use it in GitHub Desktop.
Mantis test users creation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
define( 'MANTIS_CORE', 'core.php' ); | |
if( !file_exists( MANTIS_CORE ) ) { | |
echo "ERROR: Mantis Core not found in current directory. Run the script from Mantis Home.\n"; | |
die(1); | |
} | |
require_once( MANTIS_CORE ); | |
readline( | |
"Ready to create test users in $g_db_type database '" | |
. ( $g_database_name ? $g_database_name : $g_db_username ) | |
. "' (ctrl-c to abort)\n" | |
); | |
$t_users = array( | |
array( 'tadm', 'Test Administrator', ADMINISTRATOR ), | |
array( 'tmgr', 'Test Manager', MANAGER ), | |
array( 'tdev', 'Test Developer', DEVELOPER ), | |
array( 'tupd', 'Test Updater', UPDATER ), | |
array( 'trep', 'Test Reporter', REPORTER ), | |
array( 'tvie', 'Test Viewer', VIEWER ), | |
); | |
foreach( $t_users as $t_user ) { | |
list($username, $realname, $access) = $t_user; | |
$email = "$username@localhost"; | |
$id = user_get_id_by_name( $username ); | |
if( $id === false ) { | |
echo "Creating $username ($realname)"; | |
user_create( $username, $username, $email, $access, false, true, $realname ); | |
} | |
else { | |
echo "Updating $username ($realname)"; | |
user_set_fields( $id, array( | |
'realname'=>$realname, | |
'email'=>$email, | |
'enabled'=>true, | |
'access_level'=>$access, | |
) ); | |
user_set_password( $id, $username ); | |
} | |
echo php_sapi_name() == 'cli' ? "\n" : '<br />'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment