You are here

function rules_update_6001 in Rules 6

Upgrade from workflow-ng

File

rules/rules.install, line 71
Rules - Installation file.

Code

function rules_update_6001() {
  drupal_load('module', 'rules');
  rules_include('rules');
  rules_include('rules_forms');
  rules_include('rules_admin');
  $ret = array();
  if (db_table_exists('workflow_ng_cfgs')) {

    //Return all custom created configurations
    $result = db_query("SELECT * FROM {workflow_ng_cfgs}");
    while ($row = db_fetch_object($result)) {
      $cfg = unserialize($row->data);
      $rule = rules_import_workflow_ng_rule($row->name, $cfg);
      if ($rule) {
        rules_item_save('rules', $row->name, $rule);
        $msg = t('Successfully imported rule %label.', array(
          '%label' => $rule['#label'],
        ));
        $ret[] = array(
          'success' => TRUE,
          'query' => $msg,
        );
        db_query("DELETE FROM {workflow_ng_cfgs} WHERE name = '%s'", $row->name);
      }
      else {
        $msg = t('Failed importing the rule %label.', array(
          '%label' => $cfg['#label'],
        ));
        $ret[] = array(
          'success' => FALSE,
          'query' => $msg,
        );
        $failed = TRUE;
      }
    }

    // Uninstall workflow-ng
    if (!isset($failed) || !$failed) {
      db_query("DROP TABLE {cache_workflow_ng}");
      db_query("DROP TABLE {workflow_ng_cfgs}");
      variable_del('workflow_ng_configurations');
      variable_del('workflow_ng_show_fixed');
    }
  }
  rules_clear_cache(FALSE);
  return $ret;
}