Skip to content
Snippets Groups Projects
Commit e1286267 authored by Brandon Bergren's avatar Brandon Bergren
Browse files

schema api-ification

parent 90ef6bff
No related branches found
No related tags found
No related merge requests found
<?php <?php
// $Id$ // $Id$
/**
* @file
* gmap_taxonomy install routines.
*/
/** /**
* Implementation of hook_install(). * Implementation of hook_install().
*/ */
function gmap_taxonomy_install() { function gmap_taxonomy_install() {
switch ($GLOBALS['db_type']) { drupal_install_schema('gmap_taxonomy');
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {gmap_taxonomy_term} (
tid int(10) unsigned NOT NULL default '0',
marker varchar(32),
PRIMARY KEY tid(tid)
) /*!40100 DEFAULT CHARACTER SET utf8 */");
db_query("CREATE TABLE {gmap_taxonomy_node} (
nid int(10) unsigned NOT NULL default '0',
vid int(10) unsigned NOT NULL default '0',
tid int(10) unsigned NOT NULL default '0',
marker varchar(32),
PRIMARY KEY vid(vid),
INDEX nid(nid)
) /*!40100 DEFAULT CHARACTER SET utf8 */");
break;
case 'pgsql':
//@@@
break;
}
} }
/** /**
* Implementation of hook_uninstall(). * Implementation of hook_uninstall().
*/ */
function gmap_taxonomy_uninstall() { function gmap_taxonomy_uninstall() {
db_query('DROP TABLE {gmap_taxonomy_node}'); drupal_uninstall_schema('gmap_taxonomy');
db_query('DROP TABLE {gmap_taxonomy_term}'); }
/**
* Implementation of hook_schema().
*/
function gmap_taxonomy_schema() {
$schema['gmap_taxonomy_term'] = array(
'fields' => array(
'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'marker' => array('type' => 'varchar', 'length' => 32),
),
'primary key' => array('tid'),
);
$schema['gmap_taxonomy_node'] = array(
'fields' => array(
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
'marker' => array('type' => 'varchar', 'length' => 32),
),
'primary key' => array('vid'),
'indexes' => array(
'nid' => array('nid'),
),
);
return $schema;
} }
/** /**
...@@ -43,17 +55,12 @@ function gmap_taxonomy_uninstall() { ...@@ -43,17 +55,12 @@ function gmap_taxonomy_uninstall() {
function gmap_taxonomy_update_5001() { function gmap_taxonomy_update_5001() {
$ret = array(); $ret = array();
// Add the new column. // Add the new column.
switch ($GLOBALS['db_type']) { // @@@ AFTER vid...
case 'mysql': db_add_field($ret, 'gmap_taxonomy_node', 'tid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {gmap_taxonomy_node} ADD tid int(10) unsigned NOT NULL default '0' AFTER vid"); // Useful for repopulating in bulk... Copy to hook_enable()?
$ret[] = update_sql('TRUNCATE {gmap_taxonomy_node}'); $ret[] = update_sql('DELETE FROM {gmap_taxonomy_node}');
// Useful for repopulating in bulk... Copy to hook_enable()? $ret[] = update_sql("INSERT INTO {gmap_taxonomy_node} (nid, vid, tid, marker) (SELECT n.nid, n.vid, t.tid, g.marker FROM {node_revisions} n INNER JOIN {term_node} t ON n.nid = t.nid INNER JOIN {gmap_taxonomy_term} g ON t.tid = g.tid GROUP BY n.vid ORDER BY NULL)");
$ret[] = update_sql("INSERT INTO {gmap_taxonomy_node} (nid, vid, tid, marker) (SELECT n.nid, n.vid, t.tid, g.marker FROM {node_revisions} n INNER JOIN {term_node} t ON n.nid = t.nid INNER JOIN {gmap_taxonomy_term} g ON t.tid = g.tid GROUP BY n.vid ORDER BY NULL)");
break;
case 'pgsql':
// This update will never be needed for pgsql, as it predates pgsql support.
break;
}
return $ret; return $ret;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment