function role_export_generate_id in Role Export 7
Same name and namespace in other branches
- 6 role_export.module \role_export_generate_id()
Generates a numeric id from a machine name.
2 calls to role_export_generate_id()
- role_export_user_role_insert in ./
role_export.module - Implements hook_user_role_insert().
- role_export_user_role_update in ./
role_export.module - Implements hook_user_role_update().
File
- ./
role_export.module, line 200 - Role Export's primary module file.
Code
function role_export_generate_id($mname) {
$hash = md5($mname);
// Use the last 7 hex digits from the hash. We cannot use 8 hex digits (32
// bit) because PHP does not support unsigned integers. The size of an
// integer is platform dependent (PHP_INT_SIZE) and can be only 32 bit. So we
// only have a range of 31 bit available for positive integers. We just use 7
// hex digits (28 bit here) for simplicity, which should also be good enough.
$shorter = substr($hash, -7);
$number = hexdec($shorter);
return (int) $number;
}