Sounds simple, but Drupal makes this quite a challenge.

While D7 provides http://api.drupal.org/api/function/system_get_info/7, there's no way to quickly retrieve already stored info.

Likewise, distribution and installation profile info requires to do some heavy loading and lifting via http://api.drupal.org/api/function/drupal_install_profile_distribution_n...

Comments

Status: Needs review » Needs work

The last submitted patch, mollom-HEAD.version-info.0.patch, failed testing.

dries’s picture

+++ mollom.module	7 Aug 2010 12:52:49 -0000
@@ -1398,6 +1398,31 @@ function mollom($method, $data = array()
+    if (!empty($info['distribution_name'])) {
+      $platform_name .= ' ' . $info['distribution_name'];
+    }

I didn't even remember that there was a property called 'distribution_name'. ;-)

Sounds like core should provide better APIs for this kind of stuff.

sun’s picture

StatusFileSize
new2.7 KB

It's also not documented very well. Defaults to "Drupal", not an empty string, like I wrongly suspected:

Error 1000 from http://174.37.205.152 for mollom.verifyKey: XMLRPC parse problem. The SAX parser returned: The specified field 'platform_name' is not valid.:

Array
(
    [testing] => 1
    [platform_name] => Drupal Drupal
    [platform_version] => 7.0-dev
    [client_name] => Mollom
    [client_version] => 
)

This patch additionally injects a fake version into mollom.info for testing.

The error message indicates that those parameters may not be on the production servers yet.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new2.72 KB

Let's try again.

dries’s picture

+++ mollom.info	2 Sep 2010 15:25:28 -0000
@@ -8,3 +8,6 @@ files[] = mollom.pages.inc
+; Dummy version required for testing. Do not remove.
+version = 7.x-1.x-dev

This is going to be prone to errors. We must remember to update this field for every release (which I'll fail to do).

Not sure I understand why it is required for testing. I don't see any tests for this functionality in the latest patch.

+++ mollom.module	2 Sep 2010 15:35:36 -0000
@@ -1565,6 +1571,47 @@ function _mollom_watchdog($messages, $se
+ * Returns version information to send with mollom.verifyKey.

I'd explain why Mollom captures this information and how Mollom might use it. Without an explanation, some people might think it is 'spyware'.

+++ mollom.module	2 Sep 2010 15:35:36 -0000
@@ -1565,6 +1571,47 @@ function _mollom_watchdog($messages, $se
+  // Fetch Mollom module information.
+  $mollom_info = db_query("SELECT info FROM {system} WHERE type = 'module' AND name = 'mollom'")->fetchField();
+  $mollom_info = unserialize($mollom_info);

Would be nice if there was an API for this ... ;-)

sun’s picture

1) Without that version in the .info file, all CVS module checkouts will send no client version to Mollom. We could only send the value of http://api.drupal.org/api/constant/VERSION/7 then. If that is sufficient, we can do it.

2) ok, will try to write a sensible explanation.

dries’s picture

Maybe we need to update the code comment in the .info file then? The version number has nothing to do with testing, it sounds like.

Alternatively, we could use a CVS keyword like $Revision: $. It is better in some ways (i.e. auto-magical and more precise than "7.x-1.x-dev"), but worse in others ways (i.e. no easy correlation with an actual release).

sun’s picture

StatusFileSize
new4.95 KB

Does this work for you?

Note that CVS keywords are hopefully a relict of the past very soon. AFAIK, git does not support such keywords at all. (I may be mistaken though)

Status: Needs review » Needs work

The last submitted patch, mollom-HEAD.version-info.8.patch, failed testing.

dries’s picture

I think this patch needs work (in addition to tests failing):

+++ mollom.module	3 Sep 2010 00:22:02 -0000
@@ -1429,6 +1429,12 @@ function mollom($method, $data = array()
+  // Add statistical data for mollom.verifyKey, which is normally invoked on
+  // Mollom's administration pages only.
+  if ($method == 'mollom.verifyKey') {
+    $data += _mollom_get_version();
+  }

I don't understand why we need to hard-code this in mollom(). That is bad practice. We should update the caller instead:

$status['keys valid'] = mollom('mollom.verifyKey', _mollom_get_version());

+++ mollom.module	3 Sep 2010 00:22:02 -0000
@@ -1565,6 +1571,59 @@ function _mollom_watchdog($messages, $se
+  if ($cache = cache_get('mollom_version')) {
+    $data = $cache->data;
+    return $data;
+  }

Why not return $cache->data;? No need to assign it to a temporary variable first.

+++ mollom.module	3 Sep 2010 00:22:02 -0000
@@ -1565,6 +1571,59 @@ function _mollom_watchdog($messages, $se
+    'client_version' => !empty($mollom_info['version']) ? $mollom_info['version'] : VERSION . '',

$mollom_info['version'] is always set now. We can remove the conditional/check.

+++ tests/mollom.test	3 Sep 2010 00:37:41 -0000
@@ -98,14 +98,17 @@ class MollomWebTestCase extends DrupalWe
-      $this->admin_user = $this->drupalCreateUser(array(
+      $permissions = array(
         'administer mollom',
         'access administration pages',
         'administer content types',
-        'administer comments',
         'administer permissions',
         'administer users',
-      ));
+      );
+      if ($this->profile == 'standard' || in_array('comment', $modules)) {
+        $permissions[] = 'administer comments';
+      }
+      $this->admin_user = $this->drupalCreateUser($permissions);
     }

I don't understand this change. Makes the code unnecessarily harder to read, it seems.

+++ tests/mollom.test	3 Sep 2010 00:37:41 -0000
@@ -2349,6 +2354,22 @@ class MollomDataTestCase extends MollomW
+    // Verify that we additionally sent version data.
+    $data = $this->getServerRecord('mollom.verifyKey');
+    $info = _mollom_get_version();
+    $this->assertSame('platform_name', $data['platform_name'], $info['platform_name']);
+    $this->assertSame('platform_version', $data['platform_version'], $info['platform_version']);
+    $this->assertSame('client_name', $data['client_name'], $info['client_name']);
+    $this->assertSame('client_version', $data['client_version'], $info['client_version']);
+  }

Even if _mollom_get_version() returned nothing or when _mollom_get_version() returned incorrect information, assertSame() would still pass. Both use _mollom_get_version(). If we want to check that values were set, we need to use something other than assertSame().

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new4.08 KB

1) Ah, you're right! I was mistakenly under the assumption that mollom.verifyKey would be invoked from elsewhere, too. Fixed that.

2) When fetching version information from the database cache, we populate the static cache prior to returning the info, so we're not hitting... hm, now that you mention it's only _mollom_status() that calls it, the static cache seems to be needless. We only need the database cache, _mollom_status() is "cached" already (in a system variable though).

3) d'oh on $mollom_info['version'], it was kinda late.

4) That's preparation code for the new testing installation profile, which we should be able to use for most of our tests. Separate issue indeed (running tests just takes horribly long on my computer for unknown reasons, so I'm always trying to make them as fast as possible).

5) Good catch! Fixed that.

dries’s picture

Status: Needs review » Patch (to be ported)

Looks great now. Committed to CVS HEAD.

Should be ported to DRUPAL-6--1.

sun’s picture

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

Same patch for D6.

Status: Needs review » Needs work

The last submitted patch, mollom-DRUPAL-6--1.version-info.13.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new4.07 KB

That wasn't really a complete port.

sun’s picture

Status: Needs review » Reviewed & tested by the community
dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks!

Status: Fixed » Closed (fixed)

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

  • Commit 3001caa on master, fai6, 8.x-2.x, fbajs, actions by Dries:
    - Patch #876486 by sun: send statistical data to Mollom.com.
    
    

  • Commit 3001caa on master, fai6, 8.x-2.x, fbajs, actions by Dries:
    - Patch #876486 by sun: send statistical data to Mollom.com.