You are here

function content_alter_fields in Content Construction Kit (CCK) 6.2

Same name and namespace in other branches
  1. 6.3 includes/content.admin.inc \content_alter_fields()
  2. 6 includes/content.admin.inc \content_alter_fields()

Batching process for changing the field schema, running each affected node through node_save() first, to fire all hooks.

TODO This is just a placeholder for now because batching can't be safely used with API hooks. Need to come back and figure out how to incorporate this and get it working properly when the fields are altered via the API.

File

includes/content.admin.inc, line 1684
Administrative interface for content type creation.

Code

function content_alter_fields($previous_field, $new_field) {

  // See what values need to be updated in the field data.
  $mask = content_alter_db_mask($previous_field, $new_field);

  // We use batch processing to prevent timeout when updating a large number
  // of nodes. If there is no previous data to adjust, we can just go straight
  // to altering the schema, otherwise use batch processing to update
  // the database one node at a time, then update the schema.
  if (empty($mask)) {
    return content_alter_db($previous_field, $new_field);
  }
  $updates = array(
    'mask' => $mask['mask'],
    'alt_mask' => $mask['alt_mask'],
    'delta' => $mask['delta'],
  );
  $batch = array(
    'operations' => array(
      array(
        'content_field_batch_update',
        array(
          $previous_field['field_name'] => $updates,
        ),
      ),
      array(
        'content_alter_db',
        array(
          $previous_field,
          $new_field,
        ),
      ),
    ),
    'finished' => '_content_alter_fields_finished',
    'title' => t('Processing'),
    'error_message' => t('The update has encountered an error.'),
    'file' => './' . drupal_get_path('module', 'content') . '/includes/content.admin.inc',
  );
  batch_set($batch);
  if (!empty($url)) {
    batch_process($url, $url);
  }
}