You are here

function rules_upgrade_form in Rules 7.2

Form builder for the upgrade page.

1 string reference to 'rules_upgrade_form'
rules_menu in ./rules.module
Implements hook_menu().

File

includes/rules.upgrade.inc, line 11
Contains code for upgrading rule configurations from 6.x-1.x to 7.x-2.x.

Code

function rules_upgrade_form($form, &$form_state) {
  if (!empty($form_state['export'])) {
    foreach ($form_state['export'] as $key => $export) {

      // Rules have been already converted and exported, so show the export.
      $form['export'][$key] = array(
        '#type' => 'textarea',
        '#title' => t('Export %name', array(
          '%name' => $key,
        )),
        '#description' => t('For importing copy the content of the text area and paste it into the import page of the Rules admin UI. In case the export does not pass the integrity check during import, try using the save to database method instead and manually fix your configuration after conversion.'),
        '#rows' => 10,
        '#default_value' => $export,
      );
    }
    return $form;
  }
  $form['help'] = array(
    '#prefix' => '<p>',
    '#suffix' => '</p>',
    '#markup' => t('This form allows you to convert rules or rule sets from Rules 1.x to Rules 2.x.') . ' ' . t('In order to convert a rule or rule set make sure you have all dependent modules installed and upgraded, i.e. modules which provide Rules integration that has been used in your rules or rule sets. In addition those modules may need to implement some Rules specific update hooks for the conversion to properly work.') . ' ' . t('After conversion, the old rules and rule sets will stay in the database until you manually delete them. That way you can make sure the conversion has gone right before you delete the old rules and rule sets.'),
  );
  $option_rules = $option_sets = array();
  if (!db_table_exists('rules_rules')) {
    drupal_set_message('There are no Rules 1.x rules or rule sets left to convert.', 'error');
  }
  else {
    foreach (_rules_upgrade_fetch_all_rules() as $name => $rule) {
      if (!empty($rule['#set']) && strpos($rule['#set'], 'event_') === 0) {
        $option_rules[$name] = $name . ': ' . $rule['#label'];
      }
    }
    $query = db_select('rules_sets', 'r')
      ->fields('r');
    foreach ($query
      ->execute() as $row) {
      $set = unserialize($row->data);
      $option_sets[$row->name] = $row->name . ': ' . $set['label'];
    }
    $form['clear'] = array(
      '#prefix' => '<p>',
      '#suffix' => '</p>',
      '#markup' => t('Once you have successfully converted your configuration, you can clean up your database and <a href="!url">delete</a> all Rules 1.x configurations.', array(
        '!url' => url('admin/config/workflow/rules/upgrade/clear'),
      )),
    );
  }
  $form['rules'] = array(
    '#type' => 'select',
    '#title' => t('Rules'),
    '#options' => $option_rules,
    '#multiple' => TRUE,
  );
  $form['sets'] = array(
    '#type' => 'select',
    '#title' => t('Rule sets'),
    '#options' => $option_sets,
    '#multiple' => TRUE,
  );
  $form['method'] = array(
    '#type' => 'radios',
    '#title' => t('Method'),
    '#options' => array(
      'export' => t('Convert configuration and export it.'),
      'save' => t('Convert configuration and save it.'),
    ),
    '#default_value' => 'export',
  );
  $form['actions']['convert'] = array(
    '#type' => 'submit',
    '#value' => t('Convert'),
    '#disabled' => !db_table_exists('rules_rules'),
  );
  return $form;
}