You are here

function _auto_entitylabel_ant_migrate in Automatic Entity Label 7

Migrate settings from the automatic nodetitle module.

1 call to _auto_entitylabel_ant_migrate()
auto_entitylabel_install in ./auto_entitylabel.install
Implements hook_install().

File

./auto_entitylabel.install, line 73
Installation file for the automatic entity labels module.

Code

function _auto_entitylabel_ant_migrate() {

  // Grant the entitylabel permission to all roles which had the nodetitle one.
  $roles = user_roles(TRUE, 'use PHP for title patterns');
  foreach ($roles as $rid => $role) {
    user_role_grant_permissions($rid, array(
      'use PHP for label patterns',
    ));
  }

  // Stop migration if no ant_* variables exist.
  $ant_variables_exist = db_select('variable', 'v')
    ->fields('v', array(
    'name',
  ))
    ->condition('name', 'ant_%', 'LIKE')
    ->execute()
    ->rowCount();
  if (!$ant_variables_exist) {
    return;
  }
  $types = node_type_get_types();
  $php_types = array();
  foreach ($types as $key => $value) {

    // Import auto_nodetitle variables (ant_*)
    if (variable_get('ant_' . $key)) {
      variable_set('auto_entitylabel_node_' . $key, variable_get('ant_' . $key));
    }
    if (variable_get('ant_pattern_' . $key)) {
      variable_set('auto_entitylabel_pattern_node_' . $key, variable_get('ant_pattern_' . $key));
    }
    if (variable_get('ant_php_' . $key)) {
      variable_set('auto_entitylabel_php_node_' . $key, variable_get('ant_php_' . $key));
    }
    variable_del('ant_' . $key);
    variable_del('ant_php_' . $key);
    variable_del('ant_pattern_' . $key);

    // Import variables from vasi1186's intial entitylabel patch (see #1124484)
    if (variable_get('ant_node_' . $key)) {
      variable_set('auto_entitylabel_node_' . $key, variable_get('ant_node_' . $key));
    }
    if (variable_get('ant_pattern_node_' . $key)) {
      variable_set('auto_entitylabel_pattern_node_' . $key, variable_get('ant_pattern_node_' . $key));
    }
    if (variable_get('ant_php_node_' . $key)) {
      variable_set('auto_entitylabel_php_node_' . $key, variable_get('ant_php_node_' . $key));
    }
    variable_del('ant_node_' . $key);
    variable_del('ant_php_node_' . $key);
    variable_del('ant_pattern_node_' . $key);

    // Create list of types using php patterns for warning.
    if (variable_get('auto_entitylabel_php_node_' . $key)) {
      $php_types[] = $value->name;
    }
  }
  drupal_set_message(t('All settings from the <em>Automatic Nodetitles</em> module have been migrated to the entity labels module. You can disable the <em>Automatic Nodetitles</em> module now if you have it installed.'));
  if (!empty($php_types)) {
    $php_types = '<em>' . implode('</em>, <em>', $php_types) . '</em>';
    drupal_set_message(t('Please check all title patterns which use PHP evaluation! Any patterns using the <code>$node</code> variable need to be updated to use the <code>$entity</code> variable instead. The following node types have php evaluation enabled at the moment: !types', array(
      '!types' => filter_xss($php_types, array(
        'em',
      )),
    )), 'warning');
  }
}