You are here

function brightcove_update_8106 in Brightcove Video Connect 8

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

Create default subscription for each available client.

File

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

Code

function brightcove_update_8106() {

  /* @var BrightcoveAPIClient[] $clients */
  $clients = BrightcoveAPIClient::loadMultiple();
  $messages = [];
  foreach ($clients as $client) {

    // Create new default subscription if not exist yet, only with the old
    // BrightcoveSubscription entity type.
    if (get_parent_class(BrightcoveSubscription::class) == 'ConfigEntityBase') {
      $id = "default_{$client->id()}";
      $subscription = BrightcoveSubscription::load($id);
      if (empty($subscription)) {
        BrightcoveSubscription::create([
          'id' => $id,
          'status' => FALSE,
          'default' => TRUE,
          'api_client_id' => $client
            ->id(),
          'endpoint' => BrightcoveUtil::getDefaultSubscriptionUrl(),
          'events' => [
            'video-change',
          ],
        ])
          ->save(FALSE);
      }
      else {
        $messages[] = t('Default subscription for "@client" client already exist, skipping...', [
          '@client' => $client
            ->label(),
        ]) . PHP_EOL;
      }
    }
  }
  return implode(PHP_EOL, $messages);
}