Index: mollom.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/mollom/mollom.install,v retrieving revision 1.27 diff -u -p -r1.27 mollom.install --- mollom.install 21 Sep 2010 15:59:39 -0000 1.27 +++ mollom.install 24 Sep 2010 17:08:22 -0000 @@ -4,6 +4,9 @@ /** * @file * Install and uninstall functions as well as schema definition for the Mollom module. + * + * @todo Rename 'did' column after mollom_set_data() and mollom_get_data() have + * been removed. */ /** @@ -90,7 +93,14 @@ function mollom_schema() { 'default' => '', ), 'session' => array( - 'description' => "Content author's session ID.", + 'description' => "Session hash returned by Mollom.", + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'form_id' => array( + 'description' => 'The form_id of the form being protected.', 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, @@ -134,6 +144,14 @@ function mollom_schema() { ), 'indexes' => array('session' => array('session')), 'primary key' => array('entity', 'did'), + 'foreign keys' => array( + 'mollom_form_id' => array( + 'table' => 'mollom_form', + 'columns' => array( + 'form_id' => 'form_id', + ), + ), + ), ); $schema['mollom_form'] = array( @@ -199,7 +217,13 @@ function mollom_uninstall() { * An update function to add the language field. */ function mollom_update_1() { - db_add_field('mollom', 'languages', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')); + db_add_field('mollom', 'languages', array( + 'description' => 'Text analysis language check result.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + )); } /** @@ -225,7 +249,7 @@ function mollom_update_3() { $mode = variable_get($name, NULL); // $mode was stored as 1; convert to MOLLOM_MODE_ANALYSIS. if (isset($mode)) { - variable_set($name, MOLLOM_MODE_ANALYSIS); + variable_set($name, 2); } } } @@ -247,22 +271,26 @@ function mollom_update_6105() { $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, @@ -303,9 +331,6 @@ function mollom_update_6105() { /** * Add the {mollom}.form_id column. - * - * @todo Rename 'did' column after mollom_set_data() and mollom_get_data() have - * been removed. */ function mollom_update_6106() { if (db_field_exists('mollom', 'entity')) { @@ -313,6 +338,7 @@ function mollom_update_6106() { } // Add the 'entity' column. db_add_field('mollom', 'entity', array( + 'description' => 'Entity type of the content.', 'type' => 'varchar', 'length' => 32, 'not null' => TRUE, @@ -330,7 +356,7 @@ function mollom_update_6106() { ->condition('did', 'node-%', 'LIKE') ->execute(); db_update('mollom') - ->fields(array('did' => 'SUBSTR(did, 6)')) // @todo Expressions in UPDATE? + ->expression('did', 'SUBSTR(did, 6)') ->condition('entity', 'node') ->execute(); // Migrate existing comment data. @@ -339,7 +365,7 @@ function mollom_update_6106() { ->condition('did', 'comment-%', 'LIKE') ->execute(); db_update('mollom') - ->fields(array('did' => 'SUBSTR(did, 9)')) // @todo Expressions in UPDATE? + ->expression('did', 'SUBSTR(did, 9)') ->condition('entity', 'comment') ->execute(); @@ -347,6 +373,7 @@ function mollom_update_6106() { // @todo We do not change the type to 'int' here to still support named // identifiers. Reconsider this. db_change_field('mollom', 'did', 'did', array( + 'description' => 'Unique entity ID of the content.', 'type' => 'varchar', 'length' => 32, 'not null' => TRUE, @@ -379,6 +406,7 @@ function mollom_update_6108() { function mollom_update_6109() { if (db_field_exists('mollom_form', 'fields')) { db_change_field('mollom_form', 'fields', 'enabled_fields', array( + 'description' => 'Form elements to analyze.', 'type' => 'text', 'serialize' => TRUE, )); @@ -446,6 +474,7 @@ function mollom_update_7001() { function mollom_update_7002() { if (!db_field_exists('mollom', 'changed')) { db_add_field('mollom', 'changed', array( + 'description' => 'Unix timestamp when the data was changed.', 'type' => 'int', 'not null' => TRUE, 'default' => 0, @@ -467,6 +496,7 @@ function mollom_update_7004() { // Add {mollom_form}.checks. if (!db_field_exists('mollom_form', 'checks')) { db_add_field('mollom_form', 'checks', array( + 'description' => 'Text analyis checks to perform.', 'type' => 'text', 'not null' => FALSE, 'serialize' => TRUE, @@ -511,6 +541,7 @@ function mollom_update_7005() { ->condition('quality', '') ->execute(); db_change_field('mollom', 'quality', 'quality', array( + 'description' => 'Text analysis quality check result.', 'type' => 'float', 'size' => 'tiny', 'not null' => FALSE, @@ -523,6 +554,7 @@ function mollom_update_7005() { // Add {mollom}.spam. if (!db_field_exists('mollom', 'spam')) { db_add_field('mollom', 'spam', array( + 'description' => 'Text analysis spam check result.', 'type' => 'int', 'size' => 'tiny', 'not null' => FALSE, @@ -550,6 +582,7 @@ function mollom_update_7005() { // Add {mollom}.profanity. if (!db_field_exists('mollom', 'profanity')) { db_add_field('mollom', 'profanity', array( + 'description' => 'Text analysis profanity check result.', 'type' => 'float', 'size' => 'tiny', 'not null' => FALSE, @@ -596,3 +629,81 @@ function mollom_update_7006() { ->condition('form_id', 'comment_form') ->execute(); } + +/** + * Add {mollom}.form_id column to look up the originating form_id for an entity. + */ +function mollom_update_7007() { + if (!db_field_exists('mollom', 'form_id')) { + db_add_field('mollom', 'form_id', array( + 'description' => 'The form_id of the form being protected.', + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + )); + // Update simple cases first. + db_update('mollom') + ->fields(array('form_id' => 'user_register_form')) + ->condition('entity', 'user') + ->execute(); + db_update('mollom') + ->fields(array('form_id' => 'contact_site_form')) + ->condition('entity', 'session') + ->execute(); + // Also perform simple update on behalf of Webform, as that is a very common + // use-case. + db_update('mollom') + ->expression('form_id', "CONCAT('webform_client_form_', did)") + ->condition('entity', 'webform') + ->execute(); + + // Update node entity data records. + $query = db_select('mollom', 'm'); + $query->join('node', 'n', 'n.nid = m.did'); + $result = $query + ->fields('n', array('type')) + ->fields('m', array('did')) + ->condition('m.entity', 'node') + ->orderBy('type') + ->execute() + ->fetchAll(); + $ids = array(); + foreach ($result as $row) { + $ids[$row->type][] = $row->did; + } + foreach ($ids as $type => $cids) { + db_update('mollom') + ->fields(array('form_id' => "node_{$type}_form")) + ->condition('entity', 'node') + ->condition('did', $nids) + ->execute(); + } + + // Update comment entity data records. + $query = db_select('mollom', 'm'); + $query->join('comment', 'c', 'c.cid = m.did'); + $query->join('node', 'n', 'n.nid = c.nid'); + $result = $query + ->fields('n', array('type')) + ->fields('m', array('did')) + ->condition('m.entity', 'comment') + ->orderBy('type') + ->execute() + ->fetchAll(); + $ids = array(); + foreach ($result as $row) { + $ids[$row->type][] = $row->did; + } + foreach ($ids as $type => $cids) { + db_update('mollom') + ->fields(array('form_id' => "comment_node_{$type}_form")) + ->condition('entity', 'comment') + ->condition('did', $cids) + ->execute(); + } + } + else { + // @todo If it already exists, we still have to update comment_form form_ids. + } +} Index: mollom.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/mollom/mollom.module,v retrieving revision 1.84 diff -u -p -r1.84 mollom.module --- mollom.module 24 Sep 2010 15:29:49 -0000 1.84 +++ mollom.module 24 Sep 2010 17:55:17 -0000 @@ -326,6 +326,8 @@ function _mollom_access($permission = FA * The entity type of the data to report. * @param $id * The entity id of the data to report. + * + * @todo Revamp this based on new {mollom}.form_id info. */ function mollom_report_access($entity, $id) { // The special entity 'session' means that $id is a Mollom session_id, which @@ -433,30 +435,31 @@ function mollom_data_load($entity, $id) * The entity type of the data to save. * @param $id * The entity id the data belongs to. + * @param $form_id + * The form ID the session data belongs to. + * @param $response + * An associative array of session data returned by Mollom. * * @todo Remove usage of global $mollom variable. */ -function mollom_data_save($entity, $id) { +function mollom_data_save($entity, $id, $form_id, $response) { // Nothing to do, if we do not have a valid Mollom response. if (empty($GLOBALS['mollom']['response']['session_id'])) { return FALSE; } - $data = $GLOBALS['mollom']['response']; - $data['session'] = $data['session_id']; - $data['entity'] = $entity; - $data['did'] = $id; - $data['changed'] = REQUEST_TIME; + $data = array( + 'entity' => $entity, + 'did' => $id, + 'form_id' => $form_id, + 'session' => $response['session_id'], + 'changed' => time(), + ); + $data += $response; // Convert languages into a string. if (!empty($data['languages'])) { $data['languages'] = implode(' ', $data['languages']); } - // Merge in default values that may not exist in the response. - $data += array( - 'languages' => '', - 'quality' => '', - 'reputation' => '', - ); $update = db_query_range("SELECT 'did' FROM {mollom} WHERE entity = :entity AND did = :did", 0, 1, array(':entity' => $entity, ':did' => $id))->fetchField(); drupal_write_record('mollom', $data, $update ? $update : array()); @@ -1491,7 +1494,7 @@ function mollom_form_submit($form, &$for $data = mollom_form_get_values($form_state['values'], array(), $form_state['mollom']['mapping']); // We only consider non-empty and non-zero values as valid entity ids. if (!empty($data['post_id'])) { - mollom_data_save($form_state['mollom']['entity'], $data['post_id']); + mollom_data_save($form_state['mollom']['entity'], $data['post_id'], $form_state['mollom']['form_id'], $form_state['mollom']['response']); } } // Remove Mollom session information from form state to account for unforeseen @@ -1936,7 +1939,7 @@ function mollom_get_captcha($type, array * form submissions. */ function mollom_mail_alter(&$message) { - // Attached the Mollom report link to any mails with IDs specified from the + // Attaches the Mollom report link to any mails with IDs specified from the // submitted form's hook_mollom_form_info(). This should ensure that the // report link is added to mails sent by actual users and not any mails sent // by Drupal since they should never be reported as spam. @@ -1950,9 +1953,10 @@ function mollom_mail_alter(&$message) { */ function mollom_mail_add_report_link(&$message) { if (!empty($GLOBALS['mollom']['response']['session_id'])) { - mollom_data_save('session', $GLOBALS['mollom']['response']['session_id']); + $mollom = $GLOBALS['mollom']; + mollom_data_save('session', $mollom['response']['session_id'], $mollom['form_id'], $mollom['response']); $report_link = t('Report as inappropriate: @link', array( - '@link' => url('mollom/report/session/' . $GLOBALS['mollom']['response']['session_id'], array('absolute' => TRUE)), + '@link' => url('mollom/report/session/' . $mollom['response']['session_id'], array('absolute' => TRUE)), )); $message['body'][] = $report_link; } @@ -1981,6 +1985,13 @@ function node_mollom_form_list() { } /** + * Implements hook_node_delete(). + */ +function mollom_node_delete($node) { + mollom_data_delete('node', $node->nid); +} + +/** * Implements hook_mollom_form_info(). */ function node_mollom_form_info($form_id) { @@ -2088,6 +2099,13 @@ function comment_mollom_form_info($form_ } /** + * Implements hook_comment_delete(). + */ +function mollom_comment_delete($comment) { + mollom_data_delete('comment', $comment->cid); +} + +/** * Implements hook_form_FORMID_alter(). */ function mollom_form_comment_multiple_delete_confirm_alter(&$form, &$form_state) {