You are here

nfsmigrate.module in Node and Comments Form Settings 6.3

Same filename and directory in other branches
  1. 6.2 nfsmigrate/nfsmigrate.module

File

nfsmigrate/nfsmigrate.module
View source
<?php

function nfsmigrate_perm() {
  return array(
    'use nfs migrate',
  );
}
function nfsmigrate_menu() {
  $items['admin/settings/nfsmigrate'] = array(
    'title' => 'Node Form Settings Migrate',
    'description' => 'Attempt to migrate your current settings from Node Form Settings 1 to Node Form Settings 2',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'nfsmigrate_settings',
    ),
    'access arguments' => array(
      'use nfs migrate',
    ),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}
function nfsmigrate_settings() {
  $form['help'] = array(
    '#type' => 'markup',
    '#value' => t("<p>Welcome to the migrate process. As part of the new version, all variables generated by Node Form Settings, are now in just one variable per content type and the Comments variables had been divided into a separated module.</p><p>The migration process will attempt to migrate all your variable settings, once the process starts, it shouldn't take more than a few seconds and <strong>all your previous variables will be permanently removed, so now is a good time to make a backup of your database.</strong> After the process completes, you will see the new array, please review and make changes if necessary by editing the proper content type.</p><p>Remember to enable the Comment Form Settings module to migrate those variables too</p><p>After you finish migrating both modules is completely safe to disable and uninstall the Migration module</p>"),
  );
  $form['submit_nfs'] = array(
    '#value' => t("Start migration of Node Form Settings"),
    '#type' => 'submit',
    '#submit' => array(
      'nfsmigrate_migrate_nodeformsettings',
    ),
  );
  if (!module_exists("nodeformsettings")) {
    $form['submit_nfs']['#disabled'] = TRUE;
    $form['submit_nfs']['#value'] = t("Install the Node Form Settings module to activate this button");
  }
  $form['submit_cfs'] = array(
    '#value' => t("Start migration of Comment Form Settings"),
    '#type' => 'submit',
    '#submit' => array(
      'nfsmigrate_migrate_commentformsettings',
    ),
  );
  if (!module_exists("commentformsettings")) {
    $form['submit_cfs']['#disabled'] = TRUE;
    $form['submit_cfs']['#value'] = t("Install the Comment Form Settings module to activate this button");
  }
  return $form;
}
function nfsmigrate_migrate_nodeformsettings($form, &$form_state) {
  foreach (node_get_types('names') as $type => $type_name) {

    // Build the import array filled with old values
    $old_cancel = variable_get('nodeformsettings_cancel_' . $type, '');
    $old_hide_node_title = variable_get('hidetitle_' . $type, '');
    $old_inputformat = variable_get("nodeformsettings_inputformat_" . $type, '');
    $old_preview = variable_get("nodeformsettings_preview_" . $type, '');
    $old_revisionlog = variable_get("nodeformsettings_revisionlog_" . $type, '');
    $old_splitsummary = variable_get("nodeformsettings_splitsummary_" . $type, '');
    $old_submission_body_rows = variable_get("submission_body_rows_" . $type, '');
    $old_submit = variable_get("nodeformsettings_submit_" . $type, '');
    $old_nfs_title_create = variable_get("nodeformsettings_title_create_" . $type, '');
    $old_nfs_title_edit = variable_get("nodeformsettings_title_edit_" . $type, '');
    $import = array(
      'nfs_cancel' => array(
        'nfs_cancel_status' => isset($old_cancel) ? $old_cancel : 1,
        'nfs_cancel_behaviour' => 1,
      ),
      'nfs_hide_node_title' => isset($old_hide_node_title) ? $old_hide_node_title : 0,
      'nfs_inputformat' => isset($old_inputformat) ? $old_inputformat : 0,
      'nfs_preview' => isset($old_preview) ? $old_preview : 0,
      'nfs_revisionlog' => isset($old_revisionlog) ? $old_revisionlog : 0,
      'nfs_splitsummary' => isset($old_splitsummary) ? $old_splitsummary : 0,
      'nfs_submission_body_rows' => isset($old_submission_body_rows) ? $old_submission_body_rows : 20,
      'nfs_submit' => isset($old_submit) ? $old_submit : t("Submit"),
      'nfs_title_create' => isset($old_nfs_title_create) ? $old_nfs_title_create : t("Create !node_type"),
      'nfs_title_edit' => isset($old_nfs_title_edit) ? $old_nfs_title_edit : t("!node_title"),
    );

    // Set the new variable
    variable_set('nodeformsettings_' . $type, $import);

    // Delete all old variables
    variable_del('nodeformsettings_cancel_' . $type);
    variable_del('hidetitle_' . $type);
    variable_del("nodeformsettings_inputformat_" . $type);
    variable_del("nodeformsettings_preview_" . $type);
    variable_del("nodeformsettings_revisionlog_" . $type);
    variable_del("nodeformsettings_splitsummary_" . $type);
    variable_del("submission_body_rows_" . $type);
    variable_del("nodeformsettings_submit_" . $type);
    variable_del("nodeformsettings_title_create_" . $type);
    variable_del("nodeformsettings_title_edit_" . $type);
  }
  $out .= "<p>This is the new result of the conversion process. Please review the array values and fix if necessary</p><p></p>";
  drupal_set_message($out);
  foreach (node_get_types('names') as $type => $type_name) {

    // Return the final result
    $val[$type] = variable_get('nodeformsettings_' . $type, '');
  }
  drupal_set_message('<pre>' . htmlentities(print_r($val, 1)) . '</pre>');
}
function nfsmigrate_migrate_commentformsettings($form, &$form_state) {
  foreach (node_get_types('names') as $type => $type_name) {

    // Build the import array filled with old values
    $old_anonymousname = variable_get('commentformsettings_anonymousname_' . $type, '');
    $old_anonymousmail = variable_get('commentformsettings_anonymousmail_' . $type, '');
    $old_anonymoushomepage = variable_get("commentformsettings_anonymoushomepage_" . $type, '');
    $old_author = variable_get("commentformsettings_author_" . $type, '');
    $old_preview = variable_get("commentformsettings_preview_" . $type, '');
    $old_title = variable_get("commentformsettings_title_" . $type, '');
    $old_inputformat = variable_get("commentformsettings_inputformat_" . $type, '');
    $old_size = variable_get("commentformsettings_size_" . $type, '');
    $old_submit = variable_get("commentformsettings_submit_" . $type, '');
    $import = array(
      'cfs_anonymousname' => isset($old_anonymousname) ? $old_anonymousname : 0,
      'cfs_anonymousmail' => isset($old_anonymousmail) ? $old_anonymousmail : 0,
      'cfs_anonymoushomepage' => isset($old_anonymoushomepage) ? $old_anonymoushomepage : 0,
      'cfs_author' => isset($old_author) ? $old_author : 0,
      'cfs_inputformat' => isset($old_inputformat) ? $old_inputformat : 0,
      'cfs_pnc' => array(
        'cfs_post_new_comment' => 0,
        'cfs_post_new_comment_value' => '',
      ),
      'cfs_preview' => isset($old_preview) ? $old_preview : 0,
      'cfs_size' => isset($old_size) ? $old_size : 10,
      'cfs_submit' => isset($old_submit) ? $old_submit : t("Submit"),
      'cfs_title' => isset($old_title) ? $old_title : 0,
    );

    // Set the new variable
    variable_set('commentformsettings_' . $type, $import);

    // Delete all old variables
    variable_del('commentformsettings_anonymousname_' . $type);
    variable_del('commentformsettings_anonymousmail_' . $type);
    variable_del("commentformsettings_anonymoushomepage_" . $type);
    variable_del("commentformsettings_author_" . $type);
    variable_del("commentformsettings_preview_" . $type);
    variable_del("commentformsettings_title_" . $type);
    variable_del("commentformsettings_inputformat_" . $type);
    variable_del("commentformsettings_size_" . $type);
    variable_del("commentformsettings_submit_" . $type);
  }
  $out .= "<p>This is the new result of the conversion process. Please review the array values and fix if necessary</p><p></p>";
  drupal_set_message($out);
  foreach (node_get_types('names') as $type => $type_name) {

    // Return the final result
    $val[$type] = variable_get('commentformsettings_' . $type, '');
  }
  drupal_set_message('<pre>' . htmlentities(print_r($val, 1)) . '</pre>');
}