Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mantis test users creation script
#!/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
You can’t perform that action at this time.