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

Drupal example source code file (fivestar_comment.install)

This example Drupal source code file (fivestar_comment.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

and, array, database, default, fivestar_comment, function, not, null, php, ret, sql, true, unsigned, vote_id

The fivestar_comment.install Drupal example source code

<?php

/**
 * @file
 * Installation file for Fivestar Comment module.
 */

function fivestar_comment_schema() {
  $schema['fivestar_comment'] = array(
    'fields' => array(
      'cid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
      'vote_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'value' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
      'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'),
    ),
    'primary key' => array('cid'),
    'indexes' => array(
      'vote_id' => array('vote_id'),
    ),
  );
  return $schema;
}

function fivestar_comment_uninstall() {
  db_query("DELETE FROM {variable} WHERE name LIKE 'fivestar_comment_%'");
}

/**
 * Add vote_id column to the fivestar_comment table. This update will only
 * be run when upgrading to fivestar schema 6103.
 */
function fivestar_comment_update_6100() {
  $ret = array();

  // This update will already be run as fivestar_comment_update_5100 on Drupal 5.
  if (FIVESTAR_VERSION >= 6100) {
    db_add_field($ret, 'fivestar_comment', 'vote_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
    db_add_index($ret, 'fivestar_comment', 'vote_id', array('vote_id'));

    $comments = db_query('SELECT fc.cid, fc.value, v.vote_id FROM {fivestar_comment} fc INNER JOIN {comments} c ON fc.cid = c.cid INNER JOIN {votingapi_vote} v ON fc.value = v.value AND c.nid = v.content_id AND c.uid = v.uid WHERE v.tag = "vote" AND v.value_type = "percent" AND v.content_type = "node"');
    while ($comment = db_fetch_object($comments)) {
      db_query('UPDATE {fivestar_comment} SET vote_id = %d WHERE cid = %d', $comment->vote_id, $comment->cid);
    }
  }

  return $ret;
}

/**
 * Add tag column to the fivestar_comment table.
 */
function fivestar_comment_update_6200() {
  $ret = array();

  db_add_field($ret, 'fivestar_comment', 'tag', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => 'vote'));

  return $ret;
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal fivestar_comment.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.