tracker.install

Install, update, and uninstall functions for tracker.module.

File

drupal/core/modules/tracker/tracker.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for tracker.module.
 */

/**
 * Implements hook_uninstall().
 */
function tracker_uninstall() {
  Drupal::state()
    ->delete('tracker.index_nid');
}

/**
 * Implements hook_enable().
 */
function tracker_enable() {
  $max_nid = db_query('SELECT MAX(nid) FROM {node}')
    ->fetchField();
  if ($max_nid != 0) {
    Drupal::state()
      ->set('tracker.index_nid', $max_nid);

    // To avoid timing out while attempting to do a complete indexing, we
    // simply call our cron job to remove stale records and begin the process.
    tracker_cron();
  }
}

/**
 * Implements hook_schema().
 */
function tracker_schema() {
  $schema['tracker_node'] = array(
    'description' => 'Tracks when nodes were last changed or commented on.',
    'fields' => array(
      'nid' => array(
        'description' => 'The {node}.nid this record tracks.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'published' => array(
        'description' => 'Boolean indicating whether the node is published.',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
        'size' => 'tiny',
      ),
      'changed' => array(
        'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'tracker' => array(
        'published',
        'changed',
      ),
    ),
    'primary key' => array(
      'nid',
    ),
    'foreign keys' => array(
      'tracked_node' => array(
        'table' => 'node',
        'columns' => array(
          'nid' => 'nid',
        ),
      ),
    ),
  );
  $schema['tracker_user'] = array(
    'description' => 'Tracks when nodes were last changed or commented on, for each user that authored the node or one of its comments.',
    'fields' => array(
      'nid' => array(
        'description' => 'The {node}.nid this record tracks.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'The {users}.uid of the node author or commenter.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'published' => array(
        'description' => 'Boolean indicating whether the node is published.',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
        'size' => 'tiny',
      ),
      'changed' => array(
        'description' => 'The Unix timestamp when the node was most recently saved or commented on.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'tracker' => array(
        'uid',
        'published',
        'changed',
      ),
    ),
    'primary key' => array(
      'nid',
      'uid',
    ),
    'foreign keys' => array(
      'tracked_node' => array(
        'table' => 'node',
        'columns' => array(
          'nid' => 'nid',
        ),
      ),
      'tracked_user' => array(
        'table' => 'users',
        'columns' => array(
          'uid' => 'uid',
        ),
      ),
    ),
  );
  return $schema;
}

/**
 * @addtogroup updates-7.x-to-8.x
 * @{
 */

/**
 * Moves tracker settings from variable to config.
 */
function tracker_update_8000() {
  update_variables_to_config('tracker.settings', array(
    'tracker_batch_size' => 'cron_index_limit',
  ));
}

/**
 * Make *id fields unsigned.
 */
function tracker_update_8001() {
  db_drop_primary_key('tracker_user');
  db_drop_index('tracker_user', 'tracker');
  db_change_field('tracker_user', 'uid', 'uid', array(
    'description' => 'The {users}.uid of the node author or commenter.',
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  ), array(
    'primary key' => array(
      'nid',
      'uid',
    ),
    'indexes' => array(
      'tracker' => array(
        'uid',
        'published',
        'changed',
      ),
    ),
  ));
}

/**
 * Convert tracker_index_nid variable to state system.
 *
 * @ingroup state_upgrade
 */
function tracker_update_8002() {
  update_variables_to_state(array(
    'tracker_index_nid' => 'tracker.index_nid',
  ));
}

/**
 * @} End of "defgroup updates-7.x-to-8.x".
 * The next series of updates should start at 9000.
 */

Functions

Namesort descending Description
tracker_enable Implements hook_enable().
tracker_schema Implements hook_schema().
tracker_uninstall Implements hook_uninstall().
tracker_update_8000 Moves tracker settings from variable to config.
tracker_update_8001 Make *id fields unsigned.
tracker_update_8002 Convert tracker_index_nid variable to state system.