Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Active » Needs review
FileSize
11.71 KB

Initial stab. My hope is to get this ready for the new release tomorrow already.

Dries’s picture

What is the motivation for this patch? I looked at #909484: Add {mollom}.form_id and store originating form_id for session values but it didn't provide any motivation for this patch either. Having context helps with the review process.

sun’s picture

We're starting to make further use of the session data we are getting from Mollom. Everything in the module is tied to a form_id in the meantime, except for the session data stored in {mollom}.

Right now, in various places, we are loading the locally stored data, so as to perform an action on it. However, the process of getting from that {mollom} data back to the originating form_id is a painful job that requires lengthy loops and lots of code lines. We need to get back to the form_id, to be able to load the registered Mollom form information, to e.g. figure out whether there is a 'report access callback' to invoke, or a registered 'delete form' to integrate with.

More specifically, #903770: Integrate with Mollom moderation will only get a Mollom session hash from mollom.com, so that's the only information we have. With the session hash, we can load our locally stored data, but as of now, that data only contains an entity type and entity ID. Thus, to be able to report content to Mollom, or to display or execute the delete (confirmation) form, we have to invoke mollom_form_list() to collect all registered forms, and for each registered form, compare the form information with the data of the session, in order to find the corresponding form information that belongs to the session. So only after taking this long code path of trying to find the originating form information, we can actually perform the desired action.

With a {mollom}.form_id, it gets as simple as this:

  $data = mollom_session_load($session_id);
  $mollom_form = mollom_form_load($data->form_id);

And this is an example for the painful ride we currently have:

function mollom_report_access($entity, $id) {
  // Retrieve information about all protectable forms. We use the first valid
  // definition, because we assume that multiple form definitions just denote
  // variations of the same entity (e.g. node content types).
  foreach (mollom_form_list() as $form_id => $info) {
    if (!isset($info['entity']) || $info['entity'] != $entity) {
      continue;
    }
    // If there is a 'report access callback', invoke it.
    if (isset($info['report access callback']) && function_exists($info['report access callback'])) {
      $function = $info['report access callback'];
      return $function($entity, $id);
    }
    // Otherwise, if there is a 'report access' list of permissions, iterate
    // over them.
    if (isset($info['report access'])) {
      foreach ($info['report access'] as $permission) {
        if (user_access($permission)) {
          return TRUE;
        }
      }
    }
  }
  // If we end up here, then the current user is not permitted to report this
  // content.
  return FALSE;
}
Dries’s picture

OK, that looks like a really good idea.

Reviewed the patch and it looks good.

There is one @todo in the code though -- probably something that something we want to tackle first?

sun’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
FileSize
13.46 KB

To facilitate testing, let's do this for HEAD first.

sun’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
15.39 KB

OK, I think this is ready to fly.

Dries’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Heavy duty upgrade path. Committed to CVS HEAD.

sun’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Patch (to be ported) » Needs review
FileSize
711 bytes

Sorry, working on the other issue revealed that a style $GLOBALS condition remained in mollom_data_save().

sun’s picture

FileSize
1.99 KB

Plus, mollom_data_save() should allow to use re-save existing data.

sun’s picture

Ran into one more bug in trying to re-save existing $data. Actually, it would be a good idea to finally change the {mollom}.session column into {mollom}.session_id... if you'd be on board with that.

Dries’s picture

+++ mollom.module	27 Sep 2010 21:07:50 -0000
@@ -437,32 +437,37 @@ function mollom_data_load($entity, $id) 
+  if (!$is_array) {
+    $data = (array) $data;
+  }

I'm not a fan of this kind of casting. I much prefer to pass in an element of a certain type instead of accepting fuzzy parameters. Ditto for the return value.

+++ mollom.module	27 Sep 2010 21:07:50 -0000
@@ -437,32 +437,37 @@ function mollom_data_load($entity, $id) 
+  // @todo Rename {mollom}.session.
+  if (isset($data['session_id'])) {
+    $data['session'] = $data['session_id'];
+  }

Happy to rename to session_id.

Powered by Dreditor.

sun’s picture

Thanks for reviewing! I agree that the casting is poor design. Only used it, because I didn't have time to analyze whether $data should be an array or an object. If we enforce it for mollom_data_save(), then all other mollom_data_* functions and calling code should follow. As of now, I can only guess that an array makes more sense, since the data is derived from XML-RPC, resp., $form_state, which are both arrays. However, I need to double-check all existing code to make sure it's the right decision.

sun’s picture

So I've analyzed our current and also upcoming usage of $data, and also took into account best practices for data types in Drupal core, and figured that $data should be an object, and we also want to explicitly require the $entity, $id, and $form_id properties to be set on $data, instead of overloading those individually via function arguments.

I'm going to resolve the @todo of renaming the two columns 'session' and 'did' now, which should ideally be part of this patch.

All of this is an API change, but I don't think (and actually hope) that no one is using those functions.

Dries’s picture

This looks good. Renaming those looks good too.

sun’s picture

FileSize
12.12 KB

I actually expected a giant patch now, but the size of the attached one basically proves that the module provides really good API functions.

Status: Needs review » Needs work

The last submitted patch, mollom-HEAD.form-id.14.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
FileSize
12.31 KB

Forgot to also update the 'session' table index.

Dries’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

Committed to CVS HEAD. Thanks.

sun’s picture

Status: Patch (to be ported) » Needs review
FileSize
19.92 KB

Cumulative backport to D6. Note that I've committed two small follow-up fixes for the existing update path in HEAD (typos).

sun’s picture

Fixed stale code in mollom_data_save().

sun’s picture

oh my, sorry - forgot to revert disabled test class methods.

sun’s picture

Fixed lots of hiccups + learned something new about the D6 version: We only happen to store Mollom session date for nodes and comments in D6, because we implement dedicated hook_nodeapi() and hook_comment() hooks.

sun’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
21.89 KB

More bullet-proof. Ran tests manually.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS DRUPAL-6--1. Thanks sun.

Dries’s picture

Status: Fixed » Reviewed & tested by the community

Or not. Firewall didn't let my CVS commit through. Feel free to commit on my behalf.

sun’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for reviewing! Committed to D6.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit 0576519 on master, fai6, 8.x-2.x, fbajs, actions by sun:
    #909484 by sun: Fixed typos in {mollom}.form_id update path.
    
    
  • Commit 4dff337 on master, fai6, 8.x-2.x, fbajs, actions by Dries:
    - Patch #909484 by sun:  add {mollom}.form_id() and store originating...
  • Commit 5fe66c4 on master, fai6, 8.x-2.x, fbajs, actions by Dries:
    - Patch #909484 by sun: add {mollom}.form_id() and store originating...
  • Commit 8fad8f6 on master, fai6, 8.x-2.x, fbajs, actions by sun:
    #909484 by sun: Fixed index and primary key changes in {mollom}.id...

  • Commit 0576519 on master, fai6, 8.x-2.x, fbajs, actions by sun:
    #909484 by sun: Fixed typos in {mollom}.form_id update path.
    
    
  • Commit 4dff337 on master, fai6, 8.x-2.x, fbajs, actions by Dries:
    - Patch #909484 by sun:  add {mollom}.form_id() and store originating...
  • Commit 5fe66c4 on master, fai6, 8.x-2.x, fbajs, actions by Dries:
    - Patch #909484 by sun: add {mollom}.form_id() and store originating...
  • Commit 8fad8f6 on master, fai6, 8.x-2.x, fbajs, actions by sun:
    #909484 by sun: Fixed index and primary key changes in {mollom}.id...