Hi we're using drupal 6 (actully pressflow 6).

In browscap_cron() is use of REQUEST_TIME, from what I can tell this is only defined in drupal 7 not drupal 6. As a result this is causing my cron.php to error. Is there somewhere else this is defined so that the module can use it? Or is this just a result of a backport from drupal 7 where something got missed?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ChrisConolly’s picture

Version: 7.x-1.0 » 6.x-1.2
FileSize
638 bytes

I've moved this to 6.x-1.2 as thats what I meant to tag it with to start, also, as I'm pretty sure this a bug so I've created the following patch.

Be gentle with me, this is the first patch I've posted on Drupal.org, just let me know if something with it is wrong

Devin Carlson’s picture

Version: 6.x-1.2 » 6.x-1.x-dev
Category: support » bug

Nice catch. Thanks for the bug report and patch! As you mentioned, the undefined constant is the result of code backporting from Browscap 7.x.

After reviewing your patch, I've noticed a few issues:

+  //Drupal 6 does not definde REQUEST_TIME in bootstrap.inc so define it here 

There should be a space between "//" and "Drupal", "definde" is misspelled and there is trailing whitespace.

+  if(!defined('REQUEST_TIME')){

There should be a space between "if" and "(!" and a space between "'))" and "{".

+    define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);

$_SERVER['REQUEST_TIME'] is only available in PHP 5.1.0 and Drupal 6 must support PHP 4.4.0.

A few other tips when contributing (much appreciated) patches:

  • Review the Drupal Coding standards.
  • Use the standard naming convention [short-description]-[issue-number]-[comment-number].patch.
  • Always post patches against the most recent development version which contains the issue (in this case 6.x-1.x-dev).
  • If you've included a patch then set the issue status to "needs review".
Devin Carlson’s picture

Assigned: Unassigned » Devin Carlson
Status: Active » Needs review
FileSize
550 bytes

Attached is a modified version of the patch in #1 which:

  • Moves the code to the top of the .module file.
  • Expands the comment to better explain why we're defining the constant.
  • Defines the constant using time() instead of $_SERVER['REQUEST_TIME'] as $_SERVER['REQUEST_TIME'] has only been available since PHP 5.1.0 and Drupal 6 supports PHP 4.x (4.4.0 or higher).
  • Fixes code formatting errors and spelling mistakes.
Devin Carlson’s picture

Status: Needs review » Fixed

Committed #3 to 6.x-1.x.

Status: Fixed » Closed (fixed)

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

Drave Robber’s picture

Assigned: Devin Carlson » Unassigned
Priority: Normal » Minor
Status: Closed (fixed) » Needs review
FileSize
2.44 KB

There are two problems with this approach:

  • a constant defined in browscap.module is not available in browscap.install; hence, browscap_imported variable is not set correctly upon initial install (to reproduce, install Browscap on a fresh D6 and peek into variable table; not that it breaks anything, but it's wrong anyway);
  • the whole purpose of introducing REQUEST_TIME in D7 was to extract some performance gain from avoiding multiple calls to time() in a single page request; however, if we are defining it ourselves and using only once per page request, and nobody/nothing else is using it, then we gain nothing from the whole affair.

On the other hand, some D6 contributed modules (e.g., Acquia Search) do define and use REQUEST_TIME; still, there's maybe p≈0.01 chance of 'meeting' another module that does that.

Suggested action: stop tinkering and revert to the good ol' time(). :)

Patch to that effect attached.

Devin Carlson’s picture

Status: Needs review » Fixed

#6 sounds fine to me. Committed and pushed to 6.x-1.x.

Status: Fixed » Closed (fixed)

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