activity_stream-1.0.x-dev/activity_stream.install

activity_stream.install
<?php

/**
 * @file
 * Install, update and uninstall functions for the Activity Stream module.
 */

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Database\Database;

/**
 * Implements hook_schema().
 */
function activity_stream_schema() {
  $schema['activity_notification_status'] = [
    'fields' => [
      'uid' => [
        'description' => 'The {user}.uid of user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'aid' => [
        'description' => 'The {activity}.id of activity.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'status' => [
        'description' => 'The activity status.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ],
    ],
    'indexes' => [
      'ans_uid' => ['uid'],
      'ans_aid' => ['aid'],
      'ans_uid_aid' => ['uid', 'aid'],
      'ans_status' => ['status'],
    ],
  ];

  return $schema;
}


 /**
  * Add field storage for message entity:
  * - field_message_context
  * - field_message_related_object
  * - field_message_destination
  */
 function activity_stream_update_8001() {

   if (!$field_storage = FieldStorageConfig::loadByName('message', 'field_message_context')) {    
     // Create Message Context
     FieldStorageConfig::create([
       'field_name' => 'field_message_context',
       'label' => 'Message Context',
       'type' => 'string',
       'entity_type' => 'message',
       'cardinality' => 1,
       'required' => TRUE,
     ])->save();  
    
    }   
    
    if (!$field_storage = FieldStorageConfig::loadByName('message', 'field_message_destination')) {    
    
      // Create Message Destinations
      FieldStorageConfig::create([
        'field_name' => 'field_message_destination',
        'label' => 'Message Destinations',
        'type' => 'entity_reference',
        'entity_type' => 'message',
        'cardinality' => -1,
        'required' => TRUE,
        'settings' => [
          'target_type' => 'activity_destination'       
        ],
      ])->save();    
    
    }
    
    if (!$field_storage = FieldStorageConfig::loadByName('message', 'field_message_related_object')) {  
    
      // Create Message Related Object
      FieldStorageConfig::create([
        'field_name' => 'field_message_related_object',
        'label' => 'Message Related Object',
        'type' => 'dynamic_entity_reference',
        'entity_type' => 'message',
        'cardinality' => 1,
        'required' => TRUE,
        'settings' => [
          'exclude_entity_types' => TRUE,
          'entity_type_ids' => [
            'message',
            'activity_stream_activity'
          ],
        ],
      ])->save();
  
   }   

}

/**
 * Update activity stream activity entity:
 * - NEW BASEFIELD activity_entity_bundle, 
 *   to track the bundle of a dynamic entity
 *   reference with ease.
*/
function activity_stream_update_8002() {

  $field_storage_definition = BaseFieldDefinition::create('string')
    ->setLabel(t('Activity Entity Bundle'))
    ->setDescription(t('The bundle for this entity.'))
    ->setReadonly(TRUE)
    ->setTranslatable(TRUE)
    ->setSettings([
      'default_value' => '',
      'max_length' => 32,
    ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayOptions('view', [
      'label' => 'above',
      'type' => 'string',
      'weight' => 25,
    ])
    ->setDisplayConfigurable('view', TRUE);  

  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('activity_entity_bundle', 'activity_stream_activity', 'activity_stream', $field_storage_definition);
}

/**
 * Add database table for notification statuses.
 */
function activity_stream_update_8003() {

  $spec['activity_notification_status'] = [
    'fields' => [
      'id' => [
        'description' => 'The primary identifier for a notification status.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE
      ],      
      'uid' => [
        'description' => 'The {user}.uid of user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'aid' => [
        'description' => 'The {activity}.id of activity.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'status' => [
        'description' => 'The activity status.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ],
    ],
    'indexes' => [
      'ans_uid' => ['uid'],
      'ans_aid' => ['aid'],
      'ans_uid_aid' => ['uid', 'aid'],
      'ans_status' => ['status'],
    ],
    'primary key' => [
      'nid'
    ]
  ];

  $db = Database::getConnection();
  $schema = $db->schema();
  $schema->createTable('activity_notification_status', $spec['activity_notification_status']);

}

/**
 * Update activity stream activity entity:
 * - NEW BASEFIELD activity_recipient_actor, 
 *   to track if this was group content related
 *   recipient.
 */
function activity_stream_update_8004() {

  $field_storage_definition = BaseFieldDefinition::create('boolean')
    ->setRevisionable(TRUE)
    ->setLabel(t('Activity Recipient Actor'))
    ->setDefaultValue(FALSE)
    ->setSetting('on_label', 'Recipient as Actor')
    ->setDisplayOptions('form', [
      'type' => 'boolean_checkbox',
      'settings' => [
        'display_label' => FALSE,
      ],
      'weight' => 0,
    ])
    ->setDisplayConfigurable('form', TRUE)
    ->setDisplayOptions('view', [
      'type' => 'boolean',
      'label' => 'above',
      'weight' => 0,
      'settings' => [
        'format' => 'enabled-disabled',
      ],
    ])
    ->setDisplayConfigurable('view', TRUE);   

  \Drupal::entityDefinitionUpdateManager()
    ->installFieldStorageDefinition('activity_recipient_actor', 'activity_stream_activity', 'activity_stream', $field_storage_definition);
}

/**
 * Add new columns and make it primary key
 * Table: activity_notification_status
 * Field: id
 * Reason: READ-COMMITTED MySQL!
 */
function activity_stream_update_8005() {
  // Add column ID  
  $field = [
    'type' => 'int',
    'unsigned' => TRUE,
    'size' => 'normal', // tiny / small / medium / normal / big
    'not null' => TRUE, 
    'description' => 'ID',
  ];  

  $schema = Database::getConnection()->schema();
  // Add new column for user session id.
  $schema->addField('activity_notification_status', 'id', $field);    
  // Add primary key
  $schema->addPrimaryKey('activity_notification_status', ['id']);
}

/**
 * Add make id field auto increment
 * Table: activity_notification_status
 * Field: id
 */
function activity_stream_update_8006() {
  $schema = Database::getConnection()->schema();
  // Add new column for user session id.
  $schema->changeField('activity_notification_status', 'id', 'id', [
    'type' => 'serial',
    'not null' => TRUE,
  ]);    
}

/**
 * Add index to field_activity_date
 * Table: activity_stream_activity__field_activity_date
 */  
function activity_stream_update_8007() {
  // First we need to get update manager.
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();

  // Load the storage definition of the field.
  $field_storage = $definition_update_manager
    ->getFieldStorageDefinition('field_activity_date', 'activity_stream_activity');
  // Set a new list of options for the list field.
  $field_storage->setIndexes([
    'value' => ['value']
  ]);
  // Update the field storage definition.
  $definition_update_manager->updateFieldStorageDefinition($field_storage); 
}



 

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc