l($t('Administer > Site configuration > Relevant Content'), 'admin/settings/relevant_content') ))); } /** * Implementation of hook_uninstall(). */ function relevant_content_uninstall() { drupal_uninstall_schema('relevant_content'); variable_del('relevant_content'); } /** * Implementation of hook_schema(). */ function relevant_content_schema() { $schema['relevant_content_blocks'] = array( 'fields' => array( 'id' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'The id is used to uniquely identify this block', ), 'max_items' => array( 'type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'description' => 'The limit for how many items should be listed in this block', ), 'header_text' => array( 'type' => 'text', 'size' => 'big', 'not null' => TRUE, 'description' => 'The optional header text for the block', ), 'header_format' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'The input format to use for the header_text', ), 'token_settings' => array( 'type' => 'text', 'not null' => TRUE, 'description' => 'The optional token template for the output of the related node item', ), 'absolute_links' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), 'status' => array( 'type' => 'int', 'not null' => TRUE, 'default' => 0, ), ), 'primary key' => array('id'), ); $schema['relevant_content_blocks_types'] = array( 'fields' => array( 'id' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'The id to link the list of types through to the main block configuration', ), 'type' => array( 'type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => '', 'description' => 'The content type name', ), ), 'primary key' => array('id', 'type'), ); $schema['relevant_content_blocks_vocabs'] = array( 'fields' => array( 'id' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'The id to link the list of vocabularies types through to the main block configuration', ), 'vid' => array( 'type' => 'int', 'size' => 'normal', 'not null' => TRUE, 'default' => 0, 'description' => 'The numeric vocabulary id', ), ), 'primary key' => array('id', 'vid'), ); return $schema; } /** * Implementation of hook_update_n(). */ function relevant_content_update_6100() { $ret = array(); if (db_table_exists('relevant_content_blocks')) { $ret['#abort'] = array('success' => FALSE, 'query' => 'The Relevant Content Blocks table already exists - it should nto exist yet. Please uninstall and reinstall'); return $ret; } // Install the schema drupal_install_schema('relevant_content'); // Get the translation function $t = get_t(); // Get the settings $settings = variable_get('relevant_content', array()); // For each block, we need to insert it into our tables foreach ($settings as $delta => $block) { // Define a params array - keeps the db_query() line neater // NOTE: We are renaming "limit" to "max_items" $params = array( $delta, isset($block['limit']) ? $block['limit'] : '', isset($block['header_text']) ? $block['header_text'] : '', FILTER_FORMAT_DEFAULT, isset($block['token_settings']) ? $block['token_settings'] : '', ); // Insert the data db_query("INSERT INTO {relevant_content_blocks} (id, max_items, header_text, header_format, token_settings) VALUES('%s', %d, '%s', %d, '%s')", $params); // Add one row for each assigned type if (is_array($block['types'])) { foreach ($block['types'] as $type) { db_query("INSERT INTO {relevant_content_blocks_types} (id, type) VALUES('%s', '%s')", $delta, $type); } } // Add one row for each assigned vocab if (is_array($block['vocabs'])) { foreach ($block['vocabs'] as $vid) { db_query("INSERT INTO {relevant_content_blocks_vocabs} (id, vid) VALUES('%s', %d)", $delta, $vid); } } $ret[] = array('success' => TRUE, 'query' => $t('Converted block %name', array('%name' => $delta))); } // Variable cleanup variable_del('relevant_content'); // Return the $ret return $ret; }