If the event module is not installed, signup auto-closes on my nodes every time cron runs. I don't have a patch for this (I just commented out some code) but could create one if it would be helpful.

CommentFileSizeAuthor
#2 signup_cron_query_builder_165791.patch.txt15.53 KBdww

Comments

dww’s picture

Priority: Normal » Critical

Evil, yeah. This was introduced by http://drupal.org/node/154580. Oversight on my part that I let this slip past me. :( This is IMHO critical -- we've broken signup.module for sites without event.module, which is a big no-no...

I have a few ideas. Probably the best thing is to replace the series of individual query builder functions for each date-driven feature (reminders and autoclose) with a single function for each one that expects an array. If the function doesn't exist or the array is empty, the feature is disabled. So, for example, in signup_event_5.x-1.inc, instead of this:

function signup_reminder_sql_fields() {
  // We must manually include this here as the event module doesn't
  // include timezone support on all page requests.
  include_once(drupal_get_path('module', 'event') .'/event_timezones.inc');
  return array('e.event_start', 'e.timezone');
}

function signup_reminder_sql_joins() {
  return array('INNER JOIN {event} e ON e.nid = n.nid');
}

function signup_reminder_sql_where() {
  return array('('. time() .' + ((s.reminder_days_before) * 86400)) > e.event_start');
}

We'd have this:

function signup_reminder_sql() {
  // We must manually include this here as the event module doesn't
  // include timezone support on all page requests.
  include_once(drupal_get_path('module', 'event') .'/event_timezones.inc');
  $sql = array();
  $sql['fields'] = array('e.event_start', 'e.timezone');
  $sql['joins'] = array('INNER JOIN {event} e ON e.nid = n.nid');
  $sql['where'] = array('('. time() .' + ((s.reminder_days_before) * 86400)) > \
e.event_start');
  return $sql;
}

Then, in signup_cron(), we'd see if signup_reminder_sql() was defined and returned data. If so, we'd handle the reminder emails, else, we'd skip all of that. Same story with the auto-close SQL and functionality...

dww’s picture

Assigned: Unassigned » dww
Status: Active » Needs review
StatusFileSize
new15.53 KB

This should do it. ;) This patch does the following:

A) Instead of N separate methods for each query fragment for each feature, there are now just 3 SQL query fragment functions that go in the *.inc files:

  1. signup_reminder_sql()
  2. signup_autoclose_sql()
  3. signup_admin_sql()

Each one returns an array of query elements it cares about.

B) Added a _signup_build_query() helper function to merge the results of these backend query element functions with the main, common SQL elements for each feature.

C) Split up signup_cron() into helper functions for each feature.

D) Moved the code to figure out what event-based backend .inc file we need into a method that could be shared by signup_menu() and signup_cron(). Previously, signup_cron() wasn't getting the .inc files at all, since hook_menu() isn't invoked during cron...

E) Added a bunch of phpdoc.

I tested this fairly heavily with event 5.x-1.* enabled and without, for both basic event and story (non-event) nodes, and all the autoclose stuff seems to be working correctly, as is the admin page. I didn't test reminder emails yet (but it's now 5am here and I *really* need sleep).

Reviews and testing would be most appreciated!
Thanks,
-Derek

samuelet’s picture

Works for me with drupal 5.2.
It solves also bug which prevents the cron to run manually from shell.

mfb’s picture

It's working on my setup. cannot test reminders as I don't have the event module.

dww’s picture

Status: Needs review » Fixed

Committed to HEAD.

Anonymous’s picture

Status: Fixed » Closed (fixed)