You are here

function opigno_moxtra_post_update_recreate_meeting_calendar_events in Opigno Moxtra 3.x

Same name and namespace in other branches
  1. 8 opigno_moxtra.post_update.php \opigno_moxtra_post_update_recreate_meeting_calendar_events()

Recreates calendar events related to the live meetings.

File

./opigno_moxtra.post_update.php, line 58
Contains opigno_moxtra.post_update.

Code

function opigno_moxtra_post_update_recreate_meeting_calendar_events(&$sandbox) {
  if (!isset($sandbox['last_id'])) {
    $sandbox['last_id'] = 0;
    $sandbox['current'] = 0;
    $sandbox['total'] = \Drupal::entityQuery('opigno_moxtra_meeting')
      ->count()
      ->execute();
  }
  $ids = \Drupal::entityQuery('opigno_moxtra_meeting')
    ->condition('id', $sandbox['last_id'], '>')
    ->range(0, 10)
    ->execute();

  /** @var \Drupal\opigno_moxtra\MeetingInterface[] $meetings */
  $meetings = Meeting::loadMultiple($ids);
  foreach ($meetings as $meeting) {
    $event = $meeting
      ->getCalendarEvent();
    $event
      ->delete();
    $meeting
      ->set('calendar_event', NULL);
    $meeting
      ->save();
    $sandbox['last_id'] = $meeting
      ->id();
    $sandbox['current']++;
    $sandbox['#finished'] = $sandbox['current'] / $sandbox['total'];
  }
}