function avatar_selection_update_5 in Avatar Selection 5.2
File
- ./
avatar_selection.install, line 199 - The Avatar Selection module install file.
Code
function avatar_selection_update_5() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$ret[] = update_sql("CREATE TABLE IF NOT exists {avatar_selection_roles} (\n aid int(10) unsigned NOT NULL DEFAULT 0,\n rid int(10) NOT NULL\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
$ret[] = update_sql("CREATE TABLE IF NOT exists {avatar_selection_og} (\n aid int(10) unsigned NOT NULL DEFAULT 0,\n ogid int(10) NOT NULL\n ) /*!40100 DEFAULT CHARACTER SET utf8 */");
$ret[] = update_sql("ALTER TABLE {avatar_selection} DROP PRIMARY KEY");
$ret[] = update_sql("ALTER TABLE {avatar_selection} ADD COLUMN aid int(10) unsigned NOT NULL DEFAULT 0");
break;
case 'pgsql':
$ret[] = update_sql("CREATE TABLE {avatar_selection_roles} (\n aid integer NOT NULL DEFAULT 0,\n rid integer NOT NULL\n )");
$ret[] = update_sql("CREATE TABLE {avatar_selection_og} (\n aid integer NOT NULL DEFAULT 0,\n ogid integer NOT NULL\n )");
$ret[] = update_sql("ALTER TABLE {avatar_selection} ADD COLUMN aid integer NOT NULL DEFAULT 0");
$ret[] = update_sql("ALTER TABLE {avatar_selection} DROP CONSTRAINT {avatar_selection}_pkey");
break;
}
$aid = 0;
$result = db_query("SELECT avatar, 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);
$aid = $aid + 1;
$ret[] = update_sql("UPDATE {avatar_selection} SET aid = {$aid} WHERE avatar = '" . $avatar->avatar . "'");
if (count($avs_access) > 0) {
foreach ($avs_access as $access) {
if (!empty($access)) {
$ret[] = update_sql("INSERT INTO {avatar_selection_roles} (aid, rid) VALUES(" . $aid . ", " . $access . ")");
}
}
}
if (count($og_access) > 0) {
foreach ($og_access as $access) {
if (!empty($access)) {
$ret[] = update_sql("INSERT INTO {avatar_selection_og} (aid, ogid) VALUES(" . $aid . ", " . $access . ")");
}
}
}
}
$ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES('" . db_prefix_tables('{avatar_selection}_aid') . "', {$aid})");
$ret[] = update_sql("ALTER TABLE {avatar_selection} ADD PRIMARY KEY (aid)");
$ret[] = update_sql("ALTER TABLE {avatar_selection} DROP COLUMN access");
$ret[] = update_sql("ALTER TABLE {avatar_selection} DROP COLUMN og_access");
return $ret;
}