function flexiform_update_7007 in Flexiform 7
Move flexiform_submission stuff to a submodule.
File
- ./
flexiform.install, line 358 - Sets up the base table for our entity and a table to store information about the entity types.
Code
function flexiform_update_7007() {
module_enable(array(
'flexiform_webform',
), FALSE);
db_update('field_config_instance')
->fields(array(
'entity_type' => 'flexiform_webform_submission',
))
->condition('entity_type', 'flexiform_submission')
->execute();
drupal_flush_all_caches();
// Make flexiform webforms out of all flexiforms with the base entity set to
// flexiform submission.
$webforms = db_select('flexiform', 'f')
->fields('f', array(
'label',
'form',
'id',
))
->condition('base_entity', 'flexiform_submission')
->execute()
->fetchAllAssoc('form');
foreach ($webforms as $record) {
$values = array(
'id' => $record->id,
'label' => $record->label,
'webform' => $record->form,
);
$flexiform_webform = entity_create('flexiform_webform', $values);
$flexiform_webform
->save();
foreach (field_info_instances('flexiform_webform_submission', $record->form) as $instance) {
$tables = array(
'field_data_' . $instance['field_name'],
'field_revision_' . $instance['field_name'],
);
foreach ($tables as $table) {
db_update($table)
->fields(array(
'entity_type' => 'flexiform_webform_submission',
))
->condition('entity_type', 'flexiform_submission')
->condition('bundle', $record->form)
->execute();
}
}
$flexiform = entity_load_single('flexiform', $record->form);
$flexiform->entities['base_entity']['entity_type'] = 'flexiform_webform_submission';
$flexiform
->save();
if (module_exists('field_group')) {
$groups = field_group_info_groups('flexiform_submission', $record->form, 'form', TRUE);
foreach ($groups as $group) {
$group->entity_type = 'flexiform_webform_submission';
$bits = explode('|', $group->identifier);
$bits[1] = 'flexiform_webform_submission';
$group->identifier = implode('|', $bits);
ctools_export_crud_save('field_group', $group);
}
}
}
// Update the base entities on these flexiforms.
if (!empty($webforms)) {
db_update('flexiform')
->fields(array(
'base_entity' => 'flexiform_webform_submission',
))
->condition('form', array_keys($webforms))
->execute();
}
// Migrate existing submissions to the new entity tables.
$query = db_select('flexiform_submission', 'f');
$query
->addField('f', 'flexiform_submission_id', 'id');
$query
->addField('f', 'form', 'webform');
$query
->addField('f', 'language', 'language');
$query
->addField('f', 'created', 'created');
$query
->addField('f', 'changed', 'changed');
$query
->addField('f', 'user', 'user');
db_insert('flexiform_webform_submission')
->from($query)
->execute();
db_drop_table('flexiform_submission');
}