You are here

function social_post_update_8802 in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_post/social_post.install \social_post_update_8802()
  2. 8.8 modules/social_features/social_post/social_post.install \social_post_update_8802()
  3. 10.3.x modules/social_features/social_post/social_post.install \social_post_update_8802()
  4. 10.0.x modules/social_features/social_post/social_post.install \social_post_update_8802()
  5. 10.1.x modules/social_features/social_post/social_post.install \social_post_update_8802()

Give access to creating posts of specific types.

File

modules/social_features/social_post/social_post.install, line 119
Install, update and uninstall functions for the social_post module.

Code

function social_post_update_8802(&$sandbox) {
  if (!isset($sandbox['total'])) {
    $sandbox['total'] = \Drupal::entityQuery('user_role')
      ->condition('id', 'administrator', '<>')
      ->count()
      ->execute();
    $sandbox['processed'] = 0;
    $sandbox['limit'] = Settings::get('entity_update_batch_size', 50);
    $sandbox['permissions'] = array_keys(\Drupal::service('social_post.permission_generator')
      ->permissions());
  }
  $role_ids = \Drupal::entityQuery('user_role')
    ->condition('id', 'administrator', '<>')
    ->range($sandbox['processed'], $sandbox['limit'])
    ->execute();
  $storage = \Drupal::entityTypeManager()
    ->getStorage('user_role');
  foreach ($role_ids as $role_id) {

    /** @var \Drupal\user\RoleInterface $role */
    $role = $storage
      ->load($role_id);
    if ($role
      ->hasPermission('add post entities')) {
      user_role_grant_permissions($role_id, $sandbox['permissions']);
    }
  }
  $sandbox['processed'] += count($role_ids);
  $sandbox['#finished'] = $sandbox['processed'] / $sandbox['total'];
}