function services_api_key_auth_update_7001 in Services API Key Authentication 7
Convert user IDs to usernames for configuration portability.
File
- ./
services_api_key_auth.install, line 18 - Install, update, and uninstall functions for Services API Key Authentication.
Code
function services_api_key_auth_update_7001() {
// Load Services to easily modify endpoints.
module_load_include('module', 'services');
// Iterate though each one.
foreach (services_endpoint_load_all() as $endpoint) {
// Ignore endpoints using other authentication types.
if (isset($endpoint->authentication['services_api_key_auth']['user'])) {
// Load the user from its ID.
$userId =& $endpoint->authentication['services_api_key_auth']['user'];
$user = user_load($userId);
// Silently fail if the user can't be loaded from the ID.
if ($user) {
// Get the username from the ID and save it instead.
$userName = format_username($user);
$userId = $userName;
services_endpoint_save($endpoint);
}
}
}
}