function shib_auth_update_6400 in Shibboleth Authentication 6.4
Implementation of hook_update().
Hook to update module from older revisions
Return value
an array with the executed SQL commands
File
- ./
shib_auth.install, line 90 - This is the install file of the Shibboleth authentication module for Drupal system
Code
function shib_auth_update_6400() {
// NON-DESTRUCTIVE PART OF THE UPDATE -- LET IT RUN MULTIPLE TIMES
$ret = array();
$schema = shib_auth_schema();
if (!_shib_auth_db_table_exists('shib_auth')) {
db_create_table($ret, 'shib_auth', $schema['shib_auth']);
}
else {
db_add_field($ret, 'shib_auth', 'sticky', array(
'type' => 'int',
'size' => 'tiny',
'not null' => FALSE,
'default' => 0,
));
}
if (!_shib_auth_db_table_exists('shib_authmap')) {
db_create_table($ret, 'shib_authmap', $schema['shib_authmap']);
}
/* Hack to determine if we're already running version 4.x
(the 'shib_auth_version' was not set in versions before 4.x) */
if (variable_get('shib_auth_version', NULL)) {
//ABORT
return $ret;
}
/* shib_auth module version */
variable_set('shib_auth_version', "4.0");
//DESTRUCTIVE PART OF THE UPDATE -- this must not be run multiple times
variable_set('shib_auth_full_logout_url', variable_get('shib_auth_handler_protocol', 'https') . '://' . $_SERVER['HTTP_HOST'] . variable_get('shib_auth_handler_url', '/Shibboleth.sso') . '/Logout');
variable_set('shib_auth_full_handler_url', variable_get('shib_auth_handler_protocol', 'https') . '://' . $_SERVER['HTTP_HOST'] . variable_get('shib_auth_handler_url', '/Shibboleth.sso') . variable_get('shib_auth_wayf_uri', '/DS'));
variable_set('shib_auth_enable_custom_mail', variable_get('shib_auth_mail_shib_only', FALSE));
variable_del('shib_auth_mail_shib_only');
variable_set('shib_auth_email_variable', variable_get('shib_auth_username_email', 'HTTP_MAIL'));
variable_del('shib_auth_username_email');
variable_set('shib_auth_logout_url', variable_get('shib_logout_url', $_SERVER['HTTP_HOST']));
variable_del('shib_logout_url');
variable_set('shib_auth_link_text', variable_get('auth_link_text', 'Shibboleth Login'));
variable_del('auth_link_text');
//copy the elements of authmap to the database shib_auth module uses, and left idp field empty
$entries = db_query("SELECT * FROM {authmap} WHERE module='shib_auth'");
while ($entry = db_fetch_array($entries)) {
if ($entry['uid'] > 1) {
$ret[] = update_sql("INSERT INTO {shib_authmap} (uid, targeted_id, created) VALUES ('" . $entry['uid'] . "',\n '" . $entry['authname'] . "',\n '" . date("Y-m-d H:i:s") . "')");
}
}
//update shib elements to
$entries = db_query("SELECT * FROM {shib_auth}");
while ($entry = db_fetch_array($entries)) {
$old_role = unserialize(urldecode($entry['role']));
if ($old_role) {
$new_role = serialize(array_keys($old_role));
db_query("UPDATE {shib_auth} SET role='%s' WHERE id=%d", $new_role, $entry['id']);
}
}
return $ret;
}