function avatar_selection_update_6003 in Avatar Selection 7
Same name and namespace in other branches
- 6 avatar_selection.install \avatar_selection_update_6003()
Create "avatar_selection_roles" and "avatar_selection_og" tables, and add "aid" column to avatar_selection table.
File
- ./
avatar_selection.install, line 202 - The Avatar Selection module install file.
Code
function avatar_selection_update_6003() {
$ret = array();
$schema['avatar_selection_roles'] = array(
'fields' => array(
'aid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Avatar identifier.',
),
'rid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Role identifier.',
),
),
);
$schema['avatar_selection_og'] = array(
'fields' => array(
'aid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Avatar identifier.',
),
'ogid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Organic group identifier.',
),
),
);
db_create_table('avatar_selection_roles', $schema['avatar_selection_roles']);
db_create_table('avatar_selection_og', $schema['avatar_selection_og']);
db_drop_primary_key('avatar_selection');
db_drop_unique_key('avatar_selection', 'avatar');
db_add_field('avatar_selection', 'aid', array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
), array(
'primary key' => array(
'aid',
),
));
db_add_unique_key('avatar_selection', 'avatar', array(
'avatar',
));
$result = db_query("SELECT aid, access, og_access FROM {avatar_selection}");
while ($avatar = db_fetch_object($result)) {
$avs_access = preg_split('/\\s*,\\s*/', $avatar->access);
$og_access = preg_split('/\\s*,\\s*/', $avatar->og_access);
if (count($avs_access) > 0) {
foreach ($avs_access as $access) {
if (!empty($access)) {
db_insert('avatar_selection_roles')
->fields(array(
'aid' => $avatar->aid,
'rid' => $access,
))
->execute();
}
}
}
if (count($og_access) > 0) {
foreach ($og_access as $access) {
if (!empty($access)) {
db_insert('avatar_selection_og')
->fields(array(
'aid' => $avatar->aid,
'ogid' => $access,
))
->execute();
}
}
}
}
db_drop_field('avatar_selection', 'access');
db_drop_field('avatar_selection', 'og_access');
return t('Created "avatar_selection_roles" and "avatar_selection_og" tables, and added "aid" column to avatar_selection table.');
}