You are here

function migrate_content_set_mappings_submit in Migrate 6

Implementation of hook_submit().

File

./migrate_pages.inc, line 716

Code

function migrate_content_set_mappings_submit($form, &$form_state) {
  $mcsid = $form_state['values']['mcsid'];
  if ($form_state['clicked_button']['#parents'][0] == 'delete') {
    migrate_delete_content_set($mcsid);
    drupal_set_message(t('Content set deleted'));
  }
  else {

    // Get list of current mappings, so we know if any need deletion
    $sql = "SELECT mcmid,destfield FROM {migrate_content_mappings} WHERE mcsid=%d";
    $result = db_query($sql, $mcsid);
    $prevdests = array();
    while ($row = db_fetch_object($result)) {
      $prevdests[$row->destfield] = $row->mcmid;
    }
    $sourcekey = $form_state['values']['sourcekey'];
    foreach ($form_state['values']['cols'] as $key => $destfield) {
      $mapping = new stdClass();
      $mapping->mcsid = $mcsid;
      $mapping->srcfield = $form_state['values']['srcfield'][$destfield];
      $mapping->destfield = $destfield;
      $mapping->default_value = $form_state['values']['default_value'][$destfield];
      $mapping->mcmid = db_result(db_query("SELECT mcmid\n         FROM {migrate_content_mappings}\n         WHERE mcsid=%d AND destfield='%s'", $mcsid, $destfield));
      if ($form_state['values']['primary_key'] == $destfield) {
        $mapping->primary_key = TRUE;
      }
      else {
        $mapping->primary_key = FALSE;
      }
      migrate_save_content_mapping($mapping);

      // This mapping is currently valid, so remove from the deletion list
      unset($prevdests[$mapping->destfield]);
    }

    // Delete any mappings we didn't save
    foreach ($prevdests as $mcmid) {
      migrate_delete_content_mapping($mcmid);
    }
    migrate_save_content_set($form_state['values']);
    drupal_set_message('Changes saved');
  }
  $form_state['redirect'] = 'admin/content/migrate/dashboard';
}