You are here

heartbeat_comments.install in Heartbeat 6.4

Same filename and directory in other branches
  1. 7 modules/heartbeat_comments/heartbeat_comments.install

Installation file for heartbeat comments by Stalski - Menhir - www.menhir.be

File

modules/heartbeat_comments/heartbeat_comments.install
View source
<?php

/**
 * @file
 *   Installation file for heartbeat comments
 *   by Stalski - Menhir - www.menhir.be
 */

/**
 * Implementation of hook_install().
 */
function heartbeat_comments_install() {
  drupal_install_schema('heartbeat_comments');
}

/**
 * Implementation of hook_uninstall().
 */
function heartbeat_comments_uninstall() {
  drupal_uninstall_schema('heartbeat_comments');
}

/**
 * Implementation of hook_schema().
 */
function heartbeat_comments_schema() {
  $schema['heartbeat_comments'] = array(
    'description' => t('Stores heartbeat comments of users.'),
    'fields' => array(
      'hcid' => array(
        'description' => t('The primary identifier for the comment.'),
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => t('The user_id from the user that commented.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'uaid' => array(
        'description' => t('heartbeat user activity id if there is one.'),
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'message' => array(
        'description' => t('Reaction message'),
        'type' => 'text',
        'not null' => FALSE,
        'size' => 'big',
      ),
      'cleared' => array(
        'description' => t('Did the user clear this message?'),
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'time' => array(
        'description' => t('Timestamp when the reaction has been posted'),
        'type' => 'datetime',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'hcid',
    ),
  );
  return $schema;
}

/**
 * Update to version 4.10.x
 *
 * @return sql statements array
 */
function heartbeat_comments_update_410() {

  // Due to racing conditions it's possible the update hook in heartbeat.install
  // has not ran yet. Check for the 'uaid_comments' field and in case it doesn't
  // exists, run heartbeat_update_410 first.
  if (!db_column_exists('heartbeat_activity', 'uaid_comments')) {
    module_load_include('install', 'heartbeat');
    heartbeat_update_410();
  }

  // Crazy, but hey, who cares :)
  $result = db_query("SELECT uaid FROM {heartbeat_activity}");
  while ($row = db_fetch_object($result)) {
    $count = db_result(db_query("SELECT COUNT(*) FROM {heartbeat_comments} WHERE uaid = %d ", $row->uaid));
    $update_q = "UPDATE {heartbeat_activity} set uaid_comments = %d WHERE uaid = %d";
    db_query($update_q, $count, $row->uaid);
  }
  return array();
}

Functions

Namesort descending Description
heartbeat_comments_install Implementation of hook_install().
heartbeat_comments_schema Implementation of hook_schema().
heartbeat_comments_uninstall Implementation of hook_uninstall().
heartbeat_comments_update_410 Update to version 4.10.x