reviews.install in Reviews 7
Defines database schema for reviews and installs/uninstalls all necessary settings.
File
reviews.installView source
<?php
/**
* @file
* Defines database schema for reviews and installs/uninstalls all
* necessary settings.
*/
/**
* Implements hook_schema().
*/
function reviews_schema() {
$schema['reviews_count'] = array(
'description' => 'This table holds count of reviews per node.',
'fields' => array(
'nid' => array(
'description' => 'The primary ID of the node',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'count' => array(
'description' => 'The count of reviews for the node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
);
$schema['reviews'] = array(
'description' => 'This table holds content reviews.',
'fields' => array(
'rid' => array(
'description' => 'The primary ID of the review',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => 'The ID of the node being reviewed.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The ID of the user authoring the review.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'review' => array(
'description' => 'The review content.',
'type' => 'text',
'size' => 'big',
'not null' => TRUE,
),
'rating' => array(
'description' => 'The review rating.',
'type' => 'int',
),
'status' => array(
'description' => 'The current status of the review 0=New, 1=Approved, 2=Rejected.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'The Unix timestamp when the review was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'review_created' => array(
'created',
),
),
'unique keys' => array(
'nid_vid' => array(
'rid',
),
),
'foreign keys' => array(
'review_author' => array(
'table' => 'users',
'columns' => array(
'uid' => 'uid',
),
),
),
'primary key' => array(
'rid',
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function reviews_install() {
reviews_update_7001();
}
/**
* Implements hook_uninstall().
*/
function reviews_uninstall() {
variable_del('reviews_*');
}
/**
* Add the reviews_count table to the database
*/
function reviews_update_7001() {
if (!db_table_exists('reviews_count')) {
db_create_table('reviews_count', drupal_get_schema_unprocessed('reviews', 'reviews_count'));
return 'Added the \'reviews_count\' table for the Reviews module.';
}
}
/**
* Add the ratings field to the reviews table
*/
function reviews_update_7002() {
if (!db_field_exists('reviews', 'rating')) {
$schema = drupal_get_schema('reviews');
db_add_field('reviews', 'rating', $schema['fields']['rating']);
}
return "Added the 'rating' field to the 'reviews' table for the Reviews module.";
}
Functions
Name | Description |
---|---|
reviews_install | Implements hook_install(). |
reviews_schema | Implements hook_schema(). |
reviews_uninstall | Implements hook_uninstall(). |
reviews_update_7001 | Add the reviews_count table to the database |
reviews_update_7002 | Add the ratings field to the reviews table |