home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (votingapi.install)

This example Drupal source code file (votingapi.install) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

64, array, default, entity_id, function, int, length, not, null, php, tag, true, unsigned, varchar

The votingapi.install Drupal example source code

<?php
// $Id: votingapi.install,v 1.21.4.11.2.5 2011/01/11 16:00:18 eaton Exp $

/**
 * @file
 * Installation file for VotingAPI module.
 */

function votingapi_schema() {
  $schema['votingapi_vote'] = array(
    'fields' => array(
      'vote_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
      'entity_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'node'),
      'entity_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'value' => array('type' => 'float', 'not null' => TRUE, 'default' => 0),
      'value_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'percent'),
      'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'),
      'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'vote_source' => array('type' => 'varchar', 'length' => 255),
    ),
    'primary key' => array('vote_id'),
    'indexes' => array(
      'content_uid' => array('entity_type', 'entity_id', 'uid'),
      'content_uid_2' => array('entity_type', 'uid'),
      'content_source' => array('entity_type', 'entity_id', 'vote_source'),
      'content_value_tag' => array('entity_type', 'entity_id', 'value_type', 'tag'),
    ),
  );
  $schema['votingapi_cache'] = array(
    'fields' => array(
      'vote_cache_id' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
      'entity_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'node'),
      'entity_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'value' => array('type' => 'float', 'not null' => TRUE, 'default' => 0),
      'value_type' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'percent'),
      'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'),
      'function' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''),
      'timestamp' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
    ),
    'primary key' => array('vote_cache_id'),
    'indexes' => array(
      'content' => array('entity_type', 'entity_id'),
      'content_function' => array('entity_type', 'entity_id', 'function'),
      'content_tag_func' => array('entity_type', 'entity_id', 'tag', 'function'),
      'content_vtype_tag' => array('entity_type', 'entity_id', 'value_type', 'tag'),
      'content_vtype_tag_func' => array('entity_type', 'entity_id', 'value_type', 'tag', 'function'),
    ),
  );
  return $schema;
}

/**
 * The most recent update removed for version-to-version compatibility.
 */
function votingapi_update_last_removed() {
  return 6101;
}


/**
 * Renaming the 'content_type' and 'content_id' columns to entity_type and entity_id.
 * Reduces confusion about 'content types' versus 'node types'.
 */
function votingapi_update_7201() {
  db_change_field('votingapi_vote', 'content_type', 'entity_type', array('type' => 'varchar', 'length' => 64));
  db_change_field('votingapi_vote', 'content_id', 'entity_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));

  db_change_field('votingapi_cache', 'content_type', 'entity_type', array('type' => 'varchar', 'length' => 64));
  db_change_field('votingapi_cache', 'content_id', 'entity_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));

  return t('Updated VotingAPI table structure.');
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal votingapi.install source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.