= 0), eid int NOT NULL default '0' CHECK (eid >= 0), type varchar(6) NOT NULL default '', name varchar(255) default NULL, street varchar(255) default NULL, additional varchar(255) default NULL, city varchar(255) default NULL, province varchar(16) default NULL, postal_code varchar(16) default NULL, country char(2) default NULL, latitude decimal(10,6) default NULL, longitude decimal(10,6) default NULL, source smallint default '0', is_primary smallint default '0', PRIMARY KEY (lid) )"); db_query("CREATE TABLE {zipcodes} ( zip varchar(16) NOT NULL default '0', city varchar(30) NOT NULL default '', state varchar(30) NOT NULL default '', latitude decimal(10,6) NOT NULL default '0.000000', longitude decimal(10,6) NOT NULL default '0.000000', timezone smallint NOT NULL default '0', dst smallint NOT NULL default '0', country char(2) default '', PRIMARY KEY (country, zip) )"); db_query("CREATE INDEX {zipcodes}_pc_idx ON {zipcodes} (country, zip)"); db_query("CREATE INDEX {zipcodes}_zip_idx ON {zipcodes} (zip)"); db_query("CREATE INDEX {zipcodes}_latitude_idx ON {zipcodes} (latitude)"); db_query("CREATE INDEX {zipcodes}_longitude_idx ON {zipcodes} (longitude)"); db_query("CREATE INDEX {zipcodes}_country_idx ON {zipcodes} (country)"); $success = TRUE; break; default: break; } // End case if ($success) { drupal_set_message(t('Location module installed tables successfully. If you would also like a database of zip codes, please manually import the appropriate zipcode.XX.YYYY file(s) in the %module directory.', array('%module' => drupal_get_path('module', 'location') . '/database'))); } else { drupal_set_message(t('The installation of Location module was unsuccessful.'), 'error'); } } function location_update_1() { return _system_update_utf8(array('location', 'zipcodes')); } function location_update_2() { $configured_countries = variable_get('location_configured_countries', array()); if ($configured_countries['us']) { $configured_countries['us'] = 'us'; variable_set('location_configured_countries', $configured_countries); } } function location_update_3() { $ret = array(); switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': $ret[] = update_sql("ALTER TABLE {location} CHANGE oid eid int unsigned NOT NULL default '0'"); break; } drupal_set_message("The schema for location module has been updated. The update is such that you may want to re-resave any views you have that may include locations."); views_invalidate_cache(); return $ret; } /*************************************************************** PostgreSQL must be supported in all updates after this comment ***************************************************************/ function location_update_4() { $ret = array(); switch ($GLOBALS['db_type']) { case 'mysql': case 'mysqli': $ret[] = update_sql("ALTER TABLE {location} ADD COLUMN lid int(10) unsigned NOT NULL default '0' AFTER eid"); $result = db_query("SELECT eid, type FROM {location}"); $next_id = 0; while ($row = db_fetch_object($result)) { $next_id++; db_query("UPDATE {location} SET lid = %d WHERE eid = %d AND type = '%s'", $next_id, $row->eid, $row->type); } $ret[] = update_sql("ALTER TABLE {location} DROP PRIMARY KEY"); $ret[] = update_sql("ALTER TABLE {location} ADD PRIMARY KEY (lid)"); db_query("INSERT INTO {sequences} (name, id) VALUES ('{location}_lid', %d)", $next_id); $ret[] = update_sql("ALTER TABLE {location} ADD COLUMN is_primary tinyint NOT NULL default '0'"); $ret[] = update_sql("UPDATE {location} SET is_primary = 1 WHERE type = 'user'"); break; case 'pgsql': // help me break; } foreach (node_get_types() as $type => $name) { $new_setting = variable_get('location_'. $type, 0) ? 1 : 0; variable_del('location_'. $type); variable_set('location_maxnum_'. $type, $new_setting); variable_set('location_defaultnum_'. $type, $new_setting); } return $ret; } // Poor PostgreSQL // I forgot all about you in the previous update function location_update_5() { $ret = array(); switch ($GLOBALS['db_type']) { case 'pgsql': $ret[] = update_sql("ALTER TABLE {location} DROP CONSTRAINT {location}_pkey"); $ret[] = update_sql("ALTER TABLE {location} RENAME TO {location}_old"); $ret[] = update_sql("CREATE TABLE {location} ( lid serial CHECK (lid >= 0), eid int NOT NULL default '0' CHECK (eid >= 0), type varchar(6) NOT NULL default '', name varchar(255) default NULL, street varchar(255) default NULL, additional varchar(255) default NULL, city varchar(255) default NULL, province varchar(16) default NULL, postal_code varchar(16) default NULL, country char(2) default NULL, latitude decimal(10,6) default NULL, longitude decimal(10,6) default NULL, source smallint default '0', is_primary smallint default '0', PRIMARY KEY (lid) )"); $ret[] = update_sql("INSERT INTO {location} (eid, type, name, street, additional, city, province, postal_code, country, latitude, longitude, source) SELECT eid, type, name, street, additional, city, province, postal_code, country, latitude, longitude, source FROM {location}_old"); $ret[] = update_sql("DROP TABLE {location}_old"); $ret[] = update_sql("UPDATE {location} SET is_primary = 1 WHERE type = 'user'"); break; } return $ret; }