You are here

function makemeeting_update_7203 in Make Meeting Scheduler 7.2

Migrate answers to date keys so that we can handle timezones

File

./makemeeting.install, line 204
Makemeeting installation schemas

Code

function makemeeting_update_7203(&$sandbox) {
  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    $sandbox['current_aid'] = 0;
    $sandbox['max'] = db_query('SELECT COUNT(DISTINCT answer_id) FROM {makemeeting_answers}')
      ->fetchField();
  }
  $answers = db_select('makemeeting_answers', 'a')
    ->fields('a', [
    'answer_id',
    'value',
  ])
    ->condition('answer_id', $sandbox['current_aid'], '>')
    ->range(0, 10)
    ->orderBy('answer_id', 'ASC')
    ->execute()
    ->fetchAllKeyed();
  foreach ($answers as $answer_id => $data) {
    $values = unserialize($data);
    $new_value = array();
    foreach ($values as $key => $value) {
      list($timestamp, $rest) = explode(':', $key, 2);
      $date = DateTime::createFromFormat('U', $timestamp);
      $new_value[$date
        ->format('d-m-Y') . ':' . $rest] = $value;
    }
    db_update('makemeeting_answers')
      ->fields([
      'value' => serialize($new_value),
    ])
      ->condition('answer_id', $answer_id)
      ->execute();
    $sandbox['progress']++;
    $sandbox['current_aid'] = $answer_id;
  }
  $sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];

  // To display a message to the user when the update is completed, return it.
  // If you do not want to display a completion message, simply return nothing.
  return t('Migrate answers to date format.');
}