Newer
Older
Dries Buytaert
committed
<?php
Angie Byron
committed
/**
* @file
Jennifer Hodgdon
committed
* Install, update, and uninstall functions for the Forum module.
Angie Byron
committed
*/
Dries Buytaert
committed
* Implements hook_install().
Dries Buytaert
committed
function forum_install() {
Dries Buytaert
committed
// Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module.
module_set_weight('forum', 1);
Dries Buytaert
committed
// Forum topics are published by default, but do not have any other default
// options set (for example, they are not promoted to the front page).
Dries Buytaert
committed
// @todo Convert to default module configuration, once Node module's content
// types are converted.
Dries Buytaert
committed
variable_set('node_options_forum', array('status'));
Dries Buytaert
committed
}
Dries Buytaert
committed
/**
* Implements hook_enable().
*/
Dries Buytaert
committed
function forum_enable() {
Angie Byron
committed
// Create the forum vocabulary if it does not exist.
Dries Buytaert
committed
// @todo Change Forum module so forum.settings can contain the vocabulary's
// machine name.
$config = config('forum.settings');
// If the module was disabled only, the current config may contain a valid
// vocabulary ID already.
$vocabulary = taxonomy_vocabulary_load($config->get('vocabulary'));
Angie Byron
committed
if (!$vocabulary) {
Dries Buytaert
committed
// If the module was installed and uninstalled previously, the vocabulary
// with machine name 'forums' might still exist.
$vocabulary = taxonomy_vocabulary_load('forums');
Dries Buytaert
committed
if (!$vocabulary) {
// Otherwise, installing from scratch; create the vocabulary.
$vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => t('Forums'),
'vid' => 'forums',
Dries Buytaert
committed
'langcode' => language_default()->langcode,
'description' => t('Forum navigation vocabulary'),
'hierarchy' => 1,
'module' => 'forum',
'weight' => -10,
));
taxonomy_vocabulary_save($vocabulary);
}
$config->set('vocabulary', $vocabulary->id())->save();
Angie Byron
committed
}
Alex Pott
committed
// Create the 'taxonomy_forums' field if it doesn't already exist. If forum
// is being enabled at the same time as taxonomy after both modules have been
// enabled, the field might exist but still be marked inactive.
if (!field_read_field('taxonomy_forums', array('include_inactive' => TRUE))) {
Angie Byron
committed
$field = array(
'field_name' => 'taxonomy_forums',
Angie Byron
committed
'type' => 'taxonomy_term_reference',
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->id(),
Angie Byron
committed
'parent' => 0,
),
),
),
);
field_create_field($field);
Dries Buytaert
committed
Dries Buytaert
committed
// Create a default forum so forum posts can be created.
$term = entity_create('taxonomy_term', array(
Dries Buytaert
committed
'name' => t('General discussion'),
'langcode' => language_default()->langcode,
Dries Buytaert
committed
'description' => '',
'parent' => array(0),
'vid' => $vocabulary->id(),
));
Dries Buytaert
committed
taxonomy_term_save($term);
Angie Byron
committed
// Create the instance on the bundle.
$instance = array(
'field_name' => 'taxonomy_forums',
Angie Byron
committed
'entity_type' => 'node',
'label' => $vocabulary->name,
'bundle' => 'forum',
'required' => TRUE,
'widget' => array(
'type' => 'options_select',
),
Angie Byron
committed
);
field_create_instance($instance);
// Assign display settings for the 'default' and 'teaser' view modes.
entity_get_display('node', 'forum', 'default')
->setComponent('taxonomy_forums', array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
))
->save();
entity_get_display('node', 'forum', 'teaser')
->setComponent('taxonomy_forums', array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
))
->save();
Angie Byron
committed
}
// Ensure the forum node type is available.
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['forum']);
}
Dries Buytaert
committed
* Implements hook_uninstall().
*/
function forum_uninstall() {
// Load the dependent Taxonomy module, in case it has been disabled.
drupal_load('module', 'taxonomy');
Dries Buytaert
committed
variable_del('node_options_forum');
Angie Byron
committed
field_delete_field('taxonomy_forums');
// Purge field data now to allow taxonomy module to be uninstalled
// if this is the only field remaining.
field_purge_batch(10);
Dries Buytaert
committed
/**
Dries Buytaert
committed
* Implements hook_schema().
Dries Buytaert
committed
*/
function forum_schema() {
$schema['forum'] = array(
Dries Buytaert
committed
'description' => 'Stores the relationship of nodes to forum terms.',
Dries Buytaert
committed
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
Dries Buytaert
committed
'description' => 'The {node}.nid of the node.',
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
Dries Buytaert
committed
'description' => 'Primary Key: The {node}.vid of the node.',
),
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
Dries Buytaert
committed
'description' => 'The {taxonomy_term_data}.tid of the forum term assigned to the node.',
Dries Buytaert
committed
),
'indexes' => array(
Dries Buytaert
committed
'forum_topic' => array('nid', 'tid'),
'tid' => array('tid'),
Dries Buytaert
committed
),
'primary key' => array('vid'),
'foreign keys' => array(
Dries Buytaert
committed
'forum_node' => array(
'table' => 'node',
'columns' => array(
'nid' => 'nid',
'vid' => 'vid',
),
),
Dries Buytaert
committed
);
Angie Byron
committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
$schema['forum_index'] = array(
'description' => 'Maintains denormalized information about node/term relationships.',
'fields' => array(
'nid' => array(
'description' => 'The {node}.nid this record tracks.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'title' => array(
'description' => 'The title of this node, always treated as non-markup plain text.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'tid' => array(
'description' => 'The term ID.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'sticky' => array(
'description' => 'Boolean indicating whether the node is sticky.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'size' => 'tiny',
),
'created' => array(
'description' => 'The Unix timestamp when the node was created.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default'=> 0,
),
'last_comment_timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
),
'comment_count' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The total number of comments on this node.',
),
),
'indexes' => array(
'forum_topics' => array('nid', 'tid', 'sticky', 'last_comment_timestamp'),
'created' => array('created'),
'last_comment_timestamp' => array('last_comment_timestamp'),
Angie Byron
committed
),
'foreign keys' => array(
Dries Buytaert
committed
'tracked_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'term' => array(
'table' => 'taxonomy_term_data',
'columns' => array(
'tid' => 'tid',
),
),
Angie Byron
committed
),
);
Dries Buytaert
committed
return $schema;
}
/**
* Implements hook_update_last_removed().
*/
function forum_update_last_removed() {
}
Dries Buytaert
committed
/**
* Moves forum settings from variable to config.
*
* @ingroup config_upgrade
*/
function forum_update_8000() {
update_variables_to_config('forum.settings', array(
'forum_hot_topic' => 'topics.hot_threshold',
'forum_per_page' => 'topics.page_limit',
'forum_order' => 'topics.order',
'forum_nav_vocabulary' => 'vocabulary',
'forum_containers' => 'containers',
'forum_block_num_active' => 'block.active.limit',
'forum_block_num_new' => 'block.new.limit',
));
}