mollom_update_6105

  1. drupal
    1. 6 mollom.install function
    2. 7 mollom.install function
Drupal 7 mollom_update_6105()

Add the {mollom_form} table.

File

sites/all/modules/mollom/mollom.install, line 332
Install and uninstall functions as well as schema definition for the Mollom module.

Code

function mollom_update_6105() {
  if (db_table_exists('mollom_form')) {
    return;
  }
  $schema = array(
    'fields' => array(
      'form_id' => array(
        'description' => 'The protected form ID.', 
        'type' => 'varchar', 
        'length' => 255, 
        'not null' => TRUE, 
        'default' => '',
      ), 
      'mode' => array(
        'description' => 'Protection mode for the form.', 
        'type' => 'int', 
        'size' => 'tiny', 
        'not null' => TRUE, 
        'default' => 0,
      ), 
      'enabled_fields' => array(
        'description' => 'Form elements to analyze.', 
        'type' => 'text', 
        'serialize' => TRUE,
      ), 
      'module' => array(
        'description' => 'Module name owning the form.', 
        'type' => 'varchar', 
        'length' => 255, 
        'not null' => TRUE, 
        'default' => '',
      ),
    ), 
    'primary key' => array('form_id'),
  );
  db_create_table('mollom_form', $schema);

  // Migrate form configuration for enabled, supported modules.
  foreach (module_list(FALSE, FALSE) as $module) {
    drupal_load('module', $module);
  }
  drupal_load('module', 'mollom');

  $form_list = mollom_form_list();
  $result = db_query("SELECT name, value FROM {variable} WHERE name LIKE 'mollom_%%' AND name NOT IN ('mollom_servers', 'mollom_fallback', 'mollom_public_key', 'mollom_private_key')");
  foreach ($result as $row) {
    $form_id = substr($row->name, 7);
    $mode = unserialize($row->value);
    if (!empty($mode) && isset($form_list[$form_id])) {
      $info = $form_list[$form_id];
      $info += mollom_form_info($form_id, $info['module']);
      if ($mode == MOLLOM_MODE_ANALYSIS && isset($info['elements']) && is_array($info['elements'])) {
        $info['enabled_fields'] = array_keys($info['elements']);
      }
      else {
        $info['enabled_fields'] = array();
      }
      db_insert('mollom_form')
        ->fields(array(
        'form_id' => $form_id, 
        'mode' => $mode, 
        'enabled_fields' => serialize($info['enabled_fields']), 
        'module' => $info['module'],
      ))
        ->execute();
    }
    variable_del($row->name);
  }
}