Skip to content

Instantly share code, notes, and snippets.

@dregad
Created May 23, 2016 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dregad/758fcb135bbf3a05f26ca676804a21e9 to your computer and use it in GitHub Desktop.
Save dregad/758fcb135bbf3a05f26ca676804a21e9 to your computer and use it in GitHub Desktop.
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