You are here

function activity_send_update_8001 in Open Social 8.5

Same name and namespace in other branches
  1. 8.9 modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  2. 8 modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  3. 8.2 modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  4. 8.3 modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  5. 8.4 modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  6. 8.6 modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  7. 8.7 modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  8. 8.8 modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  9. 10.3.x modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  10. 10.0.x modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  11. 10.1.x modules/custom/activity_send/activity_send.install \activity_send_update_8001()
  12. 10.2.x modules/custom/activity_send/activity_send.install \activity_send_update_8001()

Add a new database column to user_activity_send, migrate the old settings.

File

modules/custom/activity_send/activity_send.install, line 58
Installation code for the activity_send module.

Code

function activity_send_update_8001() {

  // Get the full table spec (needed for $schema->addIndex()).
  $spec = [
    'fields' => [
      'uid' => [
        'description' => 'The {user}.uid of user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'destination' => [
        'description' => 'The activity destination name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'message_template' => [
        'description' => 'The message template name.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ],
      'frequency' => [
        'description' => 'The frequency the emails should be sent. It should match the EmailFrequency plugin id.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => 'immediately',
      ],
    ],
    'indexes' => [
      'uas_uid' => [
        'uid',
      ],
      'uas_destination' => [
        'destination',
      ],
      'uas_message_template' => [
        'message_template',
      ],
      'uas_frequency' => [
        'frequency',
      ],
    ],
  ];

  // Setup DB connection and schema.
  $db = Database::getConnection();
  $schema = $db
    ->schema();

  // Add field and index.
  $schema
    ->addField('user_activity_send', 'frequency', $spec['fields']['frequency']);
  $schema
    ->addIndex('user_activity_send', 'uas_frequency', $spec['indexes']['uas_frequency'], $spec);

  // Update old status value of 0 to none.
  $db
    ->update('user_activity_send')
    ->fields([
    'frequency' => 'none',
  ])
    ->condition('status', 0)
    ->execute();

  // Update old status value of 1 to immediately.
  $db
    ->update('user_activity_send')
    ->fields([
    'frequency' => 'immediately',
  ])
    ->condition('status', 1)
    ->execute();

  // Drop old column and index.
  $schema
    ->dropField('user_activity_send', 'status');
  $schema
    ->dropIndex('user_activity_send', 'uasstatus');
}