You are here

function brightcove_update_8100 in Brightcove Video Connect 8

Same name and namespace in other branches
  1. 8.2 brightcove.install \brightcove_update_8100()
  2. 3.x brightcove.install \brightcove_update_8100()

Copy values from brightcove_callback table to a expirable key value store.

File

./brightcove.install, line 113
Brightcove install file.

Code

function brightcove_update_8100(&$sandbox) {

  // Get database connection.
  $database = \Drupal::database();
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['max'] = $database
      ->select('brightcove_callback', 'bc')
      ->fields('bc', [
      'id',
    ])
      ->countQuery()
      ->execute()
      ->fetchField();
  }
  $key_value_expirable = \Drupal::keyValueExpirable('brightcove_callback');
  $entries = $database
    ->select('brightcove_callback')
    ->fields('brightcove_callback')
    ->orderBy('id', 'ASC')
    ->range($sandbox['progress'], 50)
    ->execute()
    ->fetchAll();
  foreach ($entries as $entry) {
    $sandbox['progress']++;
    if (REQUEST_TIME < $entry->expires) {
      $key_value_expirable
        ->setWithExpire($entry->token, $entry->video_id, $entry->expires - REQUEST_TIME);
    }
  }
  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
}