Index: image_title.install =================================================================== --- image_title.install (revision 418) +++ image_title.install (working copy) @@ -4,27 +4,78 @@ /** * Implementation of hook_install(). */ -function image_title_install() { - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - db_query("CREATE TABLE {image_title} ( - nid int unsigned NOT NULL default '0', - image varchar(225) default NULL, - status int(1) NOT NULL, - KEY imgtype (nid, image) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); +function image_title_install(){ + drupal_install_schema('image_title'); +} - break; - case 'pgsql': - // need support - break; - } +/** + * Implementation of hook_schema(). + */ +function image_title_schema(){ + $schema['image_title_node'] = array( + 'description' => t('Table for holding title images attached to nodes'), + 'fields' => array( + 'nid' => array( + 'description' => t('The primary identifier for a node'), + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'image' => array( + 'description' => t('The image attached to the title of the node'), + 'type' => 'varchar', + 'length' => 255, + 'default' => '', + ), + ), + 'primary key' => array('nid', 'image'), + ); + $schema['image_title_menu'] = array( + 'description' => t('Table for holding title images attached to hook_menu entries'), + 'fields' => array( + 'path' => array( + 'description' => t('The primary identifier for a page provided using hook_menu'), + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + ), + 'image' => array( + 'description' => t('The image attached to the title of the hook_menu page'), + 'type' => 'varchar', + 'length' => 255, + 'default' => '', + ), + ), + 'primary key' => array('path'), + ); + return $schema; } + /** * Implementation of hook_uninstall(). */ function image_title_uninstall() { - db_query('DROP TABLE {image_title}'); -} \ No newline at end of file + drupal_uninstall_schema('image_title'); +} + + +/** + * Update a site to Drupal 6! + */ +function image_title_update_6000() { + $schema = image_title_schema(); + $ret = array(); + if (db_table_exists('image_title')) { + //remove entries for nodes with no active title image + db_query('DELETE FROM {image_title} WHERE status = 0'); + //drop the status field - no longer required + db_drop_field($ret, 'image_title', 'status'); + //rename the table to reflect the specific purpose + db_rename_table($ret, 'image_title', 'image_title_node'); + } + //create new table for handling hook_menu pages with title images + db_create_table($ret, 'image_title_menu', $schema['image_title_menu']); + return $ret; +} +