You are here

heartbeat.install in Heartbeat 8

Install, update and uninstall functions for the node module.

File

heartbeat.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the node module.
 */
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\user\RoleInterface;

/**
 * Implements hook_requirements().
 */
function heartbeat_requirements($phase) {
  $requirements = array();
  if ($phase === 'runtime') {

    // Only show rebuild button if there are either 0, or 2 or more, rows
    // in the {node_access} table, or if there are modules that
    // implement hook_node_grants().
    $grant_count = \Drupal::entityManager()
      ->getAccessControlHandler('node')
      ->countGrants();
    if ($grant_count != 1 || count(\Drupal::moduleHandler()
      ->getImplementations('node_grants')) > 0) {
      $value = \Drupal::translation()
        ->formatPlural($grant_count, 'One permission in use', '@count permissions in use', array(
        '@count' => $grant_count,
      ));
    }
    else {
      $value = t('Disabled');
    }
    $requirements['node_access'] = array(
      'title' => t('Node Access Permissions'),
      'value' => $value,
      'description' => t('If the site is experiencing problems with permissions to content, you may have to rebuild the permissions cache. Rebuilding will remove all privileges to content and replace them with permissions based on the current modules and settings. Rebuilding may take some time if there is a lot of content or complex permission settings. After rebuilding has completed, content will automatically use the new permissions. <a href=":rebuild">Rebuild permissions</a>', array(
        ':rebuild' => \Drupal::url('node.configure_rebuild_confirm'),
      )),
    );
  }
  return $requirements;
}

/**
 * Implements hook_schema().
 * ** //TODO Have not yet set export schema for CTOOLS as CTOOLS is not yet a part of Drupal 8
 */
function heartbeat_schema() {

  //  $schema['heartbeat_messages'] = array(
  //    'description' => 'Table that contains predefined messages that can be used in heartbeat views.',
  //    'fields' => array(
  //      'hid' => array(
  //        'description' => 'Primary Key: Unique heartbeat_messages event ID.',
  //        'type' => 'serial',
  //        'not null' => TRUE,
  //      ),
  //      'message_id' => array(
  //        'description' => 'The message id which is unique to identify activity.',
  //        'type' => 'varchar',
  //        'length' => 255,
  //        'not null' => FALSE,
  //        'default' => '',
  //      ),
  //      'description' => array(
  //        'description' => 'Description and help text',
  //        'type' => 'text',
  //        'not null' => FALSE,
  //        'size' => 'big'
  //      ),
  //      'message' => array(
  //        'type' => 'text',
  //        'not null' => TRUE,
  //        'size' => 'big',
  //        'description' => 'Text of log message to be passed into the ) function.',
  //        //'alias' => 'message_orig', // Internal heartbeat field/property
  //      ),
  //      'message_concat' => array(
  //        'type' => 'text',
  //        'not null' => TRUE,
  //        'size' => 'big',
  //        'description' => 'Text of translatable log message for in concatenated form.',
  //        //'alias' => 'message_concat_orig', // Internal heartbeat field/property
  //      ),
  //      'perms' => array(
  //        'type' => 'int',
  //        'unsigned' => TRUE,
  //        'not null' => FALSE,
  //        'default' => 4,
  //        'description' => 'Permissions for this message.',
  //      ),
  //      'group_type' => array(
  //        'type' => 'varchar',
  //        'length' => 20,
  //        'not null' => TRUE,
  //        'default' => 'single',
  //        'description' => 'The group type of the template',
  //      ),
  //      'concatargs' => array(
  //        'description' => 'Arguments for concatenation message.',
  //        'type' => 'blob',
  //        'serialize' => TRUE,
  //        'not null' => FALSE,
  //      ),
  //      'variables' => array(
  //        'description' => 'Variables to parse into the message (used in message).',
  //        'type' => 'blob',
  //        'serialize' => TRUE,
  //        'not null' => FALSE,
  //      ),
  //      'attachments' => array(
  //        'description' => 'Attachments on messages.',
  //        'type' => 'blob',
  //        'serialize' => TRUE,
  //        'not null' => FALSE,
  //      ),
  //    ),
  //    'primary key' => array('hid'),
  //    'indexes' => array(
  //      'message_id' => array('message_id'),
  //    ),
  //  );
  $schema['heartbeat_friendship'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid_target' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => 0,
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        'size' => 'tiny',
        'default' => -1,
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'uid_relation' => array(
        'uid',
        'uid_target',
      ),
    ),
  );
  $schema['heartbeat_term_usage'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'timestamp' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'tid_use' => array(
        'tid',
        'timestamp',
      ),
    ),
  );

  //    'indexes' => array(
  //      'created' => array('created'),
  //    ),
  //  );
  //  $schema['heartbeat_activity']['fields']['in_group'] = array(
  //    'type' => 'int',
  //    'not null' => TRUE,
  //    'size' => 'big',
  //    'description' => 'Indicates whether the activity is related to a group.',
  //    'default' => 0,
  //  );
  //  $schema['heartbeat_activity']['indexes']['in_group'] = array('in_group');
  //  $schema['heartbeat_user_templates'] = heartbeat_install_table_user_templates();
  //  $schema['heartbeat_stream'] = array(
  //    'description' => 'Table that contains heartbeat streams.',
  //    // CTools export definitions.

  ////    'export' => array(

  ////      'key' => 'class',

  ////      'key name' => 'name',

  ////      'primary key' => 'class',

  ////      'bulk export' => TRUE,

  ////      'identifier' => 'heartbeatstream',

  ////      'object' => 'HeartbeatStreamConfig',

  ////      'default hook' => 'heartbeat_stream_info',

  ////      'load callback' => '_heartbeat_stream_config_load',

  ////      'load all callback' => '_heartbeat_stream_config_load_all',

  ////      'can disable' => TRUE,

  ////      'api' => array(

  ////        'owner' => 'heartbeat',

  ////        'api' => 'heartbeat',

  ////        'minimum_version' => 1,

  ////        'current_version' => 1,

  ////      ),

  ////    ),

  //    'fields' => array(
  //      //TODO find out if we need id or vid fields in this table

  ////      'id' => array(

  ////        'type' => 'serial',

  ////        'not null' => TRUE,

  ////        'description' => 'Primary Key: Unique heartbeat_activity event ID.',

  ////      ),

  ////      'vid' => array(

  ////        'type' => 'int',

  ////        'not null' => TRUE,

  ////        'description' => 'The Revision ID',

  ////      ),

  //      'class' => array(
  //        'type' => 'varchar',
  //        'length' => 100,
  //        'not null' => TRUE,
  //        'default' => '',
  //        'description' => 'Class of the stream to load.',
  //      ),
  //      'real_class' => array(
  //        'type' => 'varchar',
  //        'length' => 100,
  //        'not null' => TRUE,
  //        'default' => '',
  //        'description' => 'Real Class of the stream to load.',
  //      ),
  //      'name' => array(
  //        'type' => 'varchar',
  //        'length' => 100,
  //        'not null' => TRUE,
  //        'default' => '',
  //        'description' => 'Name of the stream. Cloned streams will have the same object but same cla

  //ss.',

  //      ),
  //      'module' => array(
  //        'type' => 'varchar',
  //        'length' => 100,
  //        'not null' => TRUE,
  //        'default' => '',
  //        'description' => 'The module that defines the class and where the query builder is located.',
  //      ),
  //      'title' => array(
  //        'type' => 'varchar',
  //        'length' => 100,
  //        'not null' => TRUE,
  //        'default' => '',
  //        'description' => 'Human readable name of the stream.',
  //      ),
  //      'path' => array(
  //        'type' => 'varchar',
  //        'length' => 250,
  //        'not null' => TRUE,
  //        'default' => '',
  //        'description' => 'Path to the stream object.',
  //      ),
  //      'settings' => array(
  //        'description' => 'Serialized settings for this stream.',
  //        'type' => 'blob',
  //        'serialize' => TRUE,
  //        'not null' => FALSE,
  //      ),
  //      'variables' => array(
  //        'description' => 'Variables to parse into the message (used in message).',
  //        'type' => 'blob',
  //        'serialize' => TRUE,
  //        'not null' => FALSE,
  //      ),
  //    ),
  //    'primary key' => array('class'),
  //    'indexes' => array(
  //      'name' => array('name'),
  //    ),
  //  );

  //TODO determine if these foreign keys are to be added

  //  db_add_unique_key('heartbeat_act/ivity', 'uaid', array('uaid'));
  //  db_add_unique_key('heartbeat_activity', 'uaid_uid', array('uaid', 'uid'));
  //  db_add_unique_key('heartbeat_activity', 'uaid_nid', array('uaid', 'nid'));
  //  db_add_unique_key('heartbeat_activity', 'uaid_uid_nid', array('uaid', 'uid', 'nid'))
  return $schema;
}
function heartbeat_install_table_user_templates() {
  return array(
    'description' => 'Table that connects translations of the same activity.',
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'The referenced user ID.',
      ),
      'message_id' => array(
        'type' => 'varchar',
        'length' => 250,
        'not null' => FALSE,
        'default' => '',
        'description' => 'The template message ID.',
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'The status of the template.',
      ),
    ),
  );
}
function heartbeat_uninstall() {
  $entities = \Drupal::service("entity.query")
    ->get("heartbeat")
    ->execute();
  foreach ($entities as $entity) {
    $heartbeat = \Drupal::service("entity_type.manager")
      ->getStorage("heartbeat")
      ->load($entity);
    $heartbeat
      ->delete();
  }
  $entities = \Drupal::service("entity.query")
    ->get("heartbeat_stream")
    ->execute();
  foreach ($entities as $entity) {
    $heartbeat = \Drupal::service("entity_type.manager")
      ->getStorage("heartbeat_stream")
      ->load($entity);
    $heartbeat
      ->delete();
  }
}

Functions

Namesort descending Description
heartbeat_install_table_user_templates
heartbeat_requirements Implements hook_requirements().
heartbeat_schema Implements hook_schema(). ** //TODO Have not yet set export schema for CTOOLS as CTOOLS is not yet a part of Drupal 8
heartbeat_uninstall