function makemeeting_update_7204 in Make Meeting Scheduler 7.2
Migrate questions to date keys so that we can handle timezones
File
- ./
makemeeting.install, line 246 - Makemeeting installation schemas
Code
function makemeeting_update_7204(&$sandbox) {
$fields = makemeeting_get_makemeeting_fields();
foreach ($fields as $field) {
$table_prefixes = [
_field_sql_storage_tablename($field),
_field_sql_storage_revision_tablename($field),
];
foreach ($table_prefixes as $table) {
$items = db_select($table, 'f')
->fields('f')
->execute();
foreach ($items as $item) {
$field_prefix = $field['field_name'] . '_';
// convert value to date key
$choices = unserialize($item->{$field_prefix . 'choices'});
$new_choices = array();
foreach ($choices as $key => $choice) {
$date = DateTime::createFromFormat('U', $key);
$new_choices[$date
->format('d-m-Y')] = $choice;
}
// initialize timezone given author
$tz = drupal_get_user_timezone();
$entity = reset(entity_load($item->entity_type, [
$item->entity_id,
]));
if (variable_get('configurable_timezones', 1)) {
if (property_exists($entity, 'uid') && $entity->uid) {
$account = user_load($entity->uid);
$tz = $account->timezone;
}
elseif (property_exists($entity, 'uid')) {
$account = user_load($entity->uid);
$tz = $account->timezone;
}
}
db_update($table)
->fields([
$field_prefix . 'choices' => serialize($new_choices),
$field_prefix . 'timezone' => $tz,
])
->condition('entity_type', $item->entity_type)
->condition('entity_id', $item->entity_id)
->condition('revision_id', $item->revision_id)
->condition('language', $item->language)
->condition('delta', $item->delta)
->execute();
}
}
}
return t('Timezone column added to makemeeting forms.');
}