From 5866c055bc665e4d83baf1626f9dba10b10a6ea3 Mon Sep 17 00:00:00 2001 From: Mikkel Hoegh Date: Fri, 18 Jan 2013 21:17:40 +0000 Subject: [PATCH 1/4] Implemented event archiving. Automatically archiving past events. --- ding_event/ding_event.module | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/ding_event/ding_event.module b/ding_event/ding_event.module index d4b4052a9..689562aa4 100644 --- a/ding_event/ding_event.module +++ b/ding_event/ding_event.module @@ -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'); } @@ -87,6 +91,42 @@ function ding_event_ctools_plugin_directory($module, $plugin) { } } +/** + * Archive old events, if this setting is enabled. + */ +function ding_event_archive_past_events() { + // 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_add(CURRENT_TIMESTAMP, INTERVAL 1 DAY) + 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. * From 36e16fd7dce10427a263c1969a4678dd7a713dcb Mon Sep 17 00:00:00 2001 From: Mikkel Hoegh Date: Fri, 18 Jan 2013 21:23:27 +0000 Subject: [PATCH 2/4] Made archiving opt-in. ding_event_archive_past_events should be set to 1, either in the variables table or settings.php if you want this functionality. --- ding_event/ding_event.module | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ding_event/ding_event.module b/ding_event/ding_event.module index 689562aa4..241ab88e9 100644 --- a/ding_event/ding_event.module +++ b/ding_event/ding_event.module @@ -95,6 +95,11 @@ 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'; From de83a6c6860143e1e625c6ca143425f00e4c095f Mon Sep 17 00:00:00 2001 From: Mikkel Hoegh Date: Sun, 27 Jan 2013 16:12:03 +0000 Subject: [PATCH 3/4] Unpublishing event older than yesterday. Previously we unpublished events older than tomorrow. Which was not really what we wanted. --- ding_event/ding_event.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_event/ding_event.module b/ding_event/ding_event.module index 241ab88e9..9da34528d 100644 --- a/ding_event/ding_event.module +++ b/ding_event/ding_event.module @@ -111,7 +111,7 @@ function ding_event_archive_past_events() { 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_add(CURRENT_TIMESTAMP, INTERVAL 1 DAY) + AND ' . $colname . ' < date_sub(CURRENT_TIMESTAMP, INTERVAL 1 DAY) AND n.status = 1 '); From 21ea6d2a24b843df55e4e42d29c98e87f1aacff3 Mon Sep 17 00:00:00 2001 From: Mikkel Hoegh Date: Sun, 10 Feb 2013 21:57:40 +0000 Subject: [PATCH 4/4] Increased delay to two days. --- ding_event/ding_event.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ding_event/ding_event.module b/ding_event/ding_event.module index 9da34528d..0d1c1ce1a 100644 --- a/ding_event/ding_event.module +++ b/ding_event/ding_event.module @@ -111,7 +111,7 @@ function ding_event_archive_past_events() { 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 1 DAY) + AND ' . $colname . ' < date_sub(CURRENT_TIMESTAMP, INTERVAL 2 DAYS) AND n.status = 1 ');