Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event archiver #40

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions ding_event/ding_event.module
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ function ding_event_cron() {
// time, since the cache will be refilled only by the cron job.
if (date('Ymd', $timestamp) != date('Ymd', $_SERVER['REQUEST_TIME']) &&
lock_acquire('ding_event_similar_data_generated', 600.0)) {

// Before we generate the similar events data, archive any old events.
ding_event_archive_past_events();

ding_event_similar_data(TRUE);
lock_release('ding_event_similar_data_generated');
}
Expand Down Expand Up @@ -87,6 +91,47 @@ function ding_event_ctools_plugin_directory($module, $plugin) {
}
}

/**
* Archive old events, if this setting is enabled.
*/
function ding_event_archive_past_events() {
// Do nothing if archiving is not enabled.
if (!variable_get('ding_event_archive_past_events', FALSE)) {
return;
}

// CCK field name for the date/time field on event nodes.
$fieldname = 'field_datetime';

$field = content_fields('field_datetime', 'event');
$dbinfo = content_database_info($field);
$colname = $dbinfo['columns']['value2']['column'];

$query = db_query('
SELECT n.nid FROM {node} AS n
INNER JOIN ' . $dbinfo['table'] . ' AS cte ON (n.vid = cte.vid)
WHERE ' . $colname . ' IS NOT NULL
AND ' . $colname . ' < date_sub(CURRENT_TIMESTAMP, INTERVAL 2 DAYS)
AND n.status = 1
');

$nids = array();
while ($nid = db_result($query)) {
$nids[] = $nid;
}

if (count($nids) < 1) {
watchdog('ding_event', 'There are no outdated events that need to be archived.');
}
else {
watchdog('ding_event', 'Found @num outdated events that will be archived.', array(
'@num' => count($nids),
));

db_query('UPDATE {node} SET status = 0 WHERE nid IN (' . implode(',', $nids) . ')');
}
}

/**
* Similar events data.
*
Expand Down