You are here

function botcha_update_7000 in BOTCHA Spam Prevention 7

Migrate form configuration for changed form ids in Drupal 7.

File

./botcha.install, line 157

Code

function botcha_update_7000() {

  // 'user_register' became 'user_register_form'.
  db_update('botcha_points')
    ->fields(array(
    'form_id' => 'user_register_form',
  ))
    ->condition('form_id', 'user_register')
    ->execute();

  // 'contact_mail_page' became 'contact_site_form'.
  db_update('botcha_points')
    ->fields(array(
    'form_id' => 'contact_site_form',
  ))
    ->condition('form_id', 'contact_mail_page')
    ->execute();

  // 'contact_mail_user' became 'contact_personal_form'.
  db_update('botcha_points')
    ->fields(array(
    'form_id' => 'contact_personal_form',
  ))
    ->condition('form_id', 'contact_mail_user')
    ->execute();

  // The D6-style comment_form form_id is split per node type
  // in D7: comment_node_{type}_form, e.g. comment_node_page_form.
  // Get the current settings for 'comment_form'.
  $botcha_point = db_query("SELECT * FROM {botcha_points} WHERE form_id = :comment_form_id", array(
    ':comment_form_id' => 'comment_form',
  ))
    ->fetchObject();
  if ($botcha_point !== FALSE) {

    // Create entries for D7-style node form IDs.
    $botcha_type = $botcha_point->botcha_type;
    foreach (node_type_get_names() as $type => $name) {
      $form_id = 'comment_node_' . $type . '_form';
      db_insert('botcha_points')
        ->fields(array(
        'form_id' => $form_id,
        'botcha_type' => $botcha_type,
      ))
        ->execute();
    }

    // Delete outdated entry.
    db_delete('botcha_points')
      ->condition('form_id', 'comment_form')
      ->execute();
  }
}