You are here

function content_alter_db_mask in Content Construction Kit (CCK) 6.2

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

Create a mask for the column data that should be deleted in each field.

This is a bit tricky. We could theoretically have some columns that should be set to empty and others with valid info that should not be emptied out. But if delta values > X are to be wiped out, they need to wipe out even columns that still have values. And the NULL values in these columns after the alteration may be enough to make the item 'empty', as defined by hook_content_is_empty(), even if some columns still have values, so all these things need to be tested.

1 call to content_alter_db_mask()
content_alter_fields in includes/content.admin.inc
Batching process for changing the field schema, running each affected node through node_save() first, to fire all hooks.

File

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

Code

function content_alter_db_mask($previous_field, $new_field) {

  // Get an array of column values that will be dropped by this
  // schema change and create a mask to feed to content_batch_update.
  $dropped = content_alter_db_analyze($previous_field, $new_field);
  if (empty($dropped)) {
    return array();
  }
  $mask = array(
    'mask' => array(),
  );
  foreach (array_keys($previous_field['columns']) as $column_name) {

    // The basic mask will empty the dropped columns.
    if (isset($dropped['columns']) && in_array($column_name, $dropped['columns'])) {
      $mask['mask'][$column_name] = NULL;
    }

    // Over the delta we'll empty all columns.
    if (isset($dropped['delta'])) {
      $mask['alt_mask'][$column_name] = NULL;
    }
  }
  if (isset($dropped['delta'])) {
    $mask['delta'] = $dropped['delta'];
  }
  return $mask;
}