function user_revision_update_7002 in User Revision 7.2
Create revisions with user roles.
File
- ./
user_revision.install, line 262 - Install, update and uninstall functions for the user_revision module.
Code
function user_revision_update_7002() {
// Create the new revision role table.
if (!db_table_exists('user_revision_roles')) {
$user_role_revision_schema = drupal_get_schema_unprocessed('user_revision', 'user_revision_roles');
db_create_table('user_revision_roles', $user_role_revision_schema);
}
// Fetch all user revision records.
$data = db_select('user_revision', 'ur')
->fields('ur', array(
'uid',
'vid',
))
->orderBy('ur.uid')
->execute()
->fetchAll();
foreach ($data as $row) {
// Search each role for the user.
$roles = db_select('users_roles', 'ur')
->fields('ur', array(
'rid',
))
->condition('uid', $row->uid)
->execute()
->fetchAll();
if (!empty($roles)) {
foreach ($roles as $role) {
// Add roles to user_revision_roles table.
user_revision_add_role($row->uid, $row->vid, $role->rid);
}
}
}
}