You are here

function node_registration_update_11 in Node registration 7

Remove `registration_email` fields and notify about deprecated tokens.

File

./node_registration.install, line 276
Install, uninstall, enable and disable hooks and schema.

Code

function node_registration_update_11() {

  // Find field instances: `registration_email`.
  $instances = field_read_instances(array(
    'field_name' => 'registration_email',
  ));

  // Delete those instances.
  foreach ($instances as $instance) {
    field_delete_instance($instance);
  }
  $token_warnings = array();

  // Find tokens in registration type settings.
  $bundles_info = field_info_bundles('node_registration');
  $vars = db_query('SELECT name FROM {variable} WHERE name LIKE :name AND value LIKE :value', array(
    ':name' => 'node\\_registration\\_%',
    ':value' => '%[node-registration:registration_email]%',
  ));
  foreach ($vars as $var_name) {
    $var_name = $var_name->name;
    $registration_type_name = substr($var_name, strlen('node_registration_type_settings_'));
    if (isset($bundles_info[$registration_type_name])) {
      $registration_type = $bundles_info[$registration_type_name];
      $title = $registration_type['label'];
      $href = 'admin/structure/node_registration/manage/' . $registration_type_name . '/settings';
      $token_warnings[] = l($title, $href);
    }
  }

  // Find tokens in node settings.
  $nodes = db_query('SELECT nid FROM {node_registration_node} WHERE settings LIKE :value', array(
    ':value' => '%[node-registration:registration_email]%',
  ));
  foreach ($nodes as $node_settings) {
    $title = 'Node ' . $node_settings->nid;
    $href = 'node/' . $node_settings->nid . '/node_registration/settings';
    $token_warnings[] = l($title, $href);
  }

  // Notify about these settings.
  if ($token_warnings) {
    $t = get_t();
    $message = $t('The following settings still use the token "[node-registration:registration_email]" or "[node-registration:registration-email]": !settings_links. That\'s deprecated and MUST be changed to "[node-registration:email]".', array(
      '!settings_links' => implode(', ', $token_warnings),
    ));
    return $message;
  }
}