'admin/event/past_events', 'title' => t('Past Events'), 'callback' => 'drupal_get_form', 'callback arguments' => array('past_events_admin_settings'), 'description' => t('Set Past Events Settings.'), 'access' => user_access('administer site configuration')); //} return $items; } function past_events_admin_settings(){ $form = array(); $form['past_events_action'] = array( '#type' => 'radios', '#title' => t('Past Events Action to take'), '#default_value' => variable_get('past_events_action', 'Manage'), '#options' => array('manage' => t('manage by the settings below'), 'delete' => t('Delete Event')) ); $form['past_events_manage_options'] = array( '#type' => 'fieldset', '#title' => t('Manage Options'), '#collapsible' => FALSE, '#collapsed' => FALSE, ); $form['past_events_manage_options'] ['past_events_unsticky']= array( '#type' => 'checkbox', '#title' => t('UnSticky event'), '#default_value' => variable_get('past_events_unsticky',0), ); $form['past_events_manage_options'] ['past_events_unpublish']= array( '#type' => 'checkbox', '#title' => t('UnPublish event'), '#default_value' => variable_get('past_events_unpublish',0), ); $form['past_events_manage_options'] ['past_events_unpromote']= array( '#type' => 'checkbox', '#title' => t('UnPromote event'), '#default_value' => variable_get('past_events_unpromote',1), ); //return $form; return system_settings_form($form); } /** * Implementation of hook_cron(). * @ingroup event_core */ /** * Implementation of hook_help(). */ function past_events_help($section) { if ($section == 'admin/modules#description') { return t('A module manage past events, enable to unpublish, unsticky, unpromote or delete .'); } } /** * Implementation of hook_perm(). function past_events_perm() { return array('mark event nodes that are out of date'); } */ function past_events_cron() { $curtime = time(); //calculate the closing time for the event //when closing is preferred. query the database for all events which have a end time less than this, $closing_time = $curtime - variable_get('date_default_timezone', 0); //SELECT e.nid FROM event e inner join node n on e.nid = n.nid where n.status =1 AND e.event_end < 1151360881 $result = db_query("SELECT e.nid FROM {event} e inner join {node} n on e.nid = n.nid where n.status =1 AND e.event_end < %d", $closing_time); $log = ''; // watchdog string $severity = WATCHDOG_NOTICE; $log .= 'past_events cron started'; $action = variable_get('past_events_action','manage'); $unsticky = variable_get('past_events_unsticky',0); $unpublish = variable_get('past_events_unpublish',0); $unpromote = variable_get('past_events_unpromote',1); //print "
closing time is : " . $closing_time; //print "
site timezone is : " . variable_get('date_default_timezone', 0); //loop through the results, calling and remove the sticky for the event while ($event = db_fetch_object($result)) { $node = node_load($event->nid); //print "
" .$node->title . ", End Time : " .$node->event_end; //watchdog('past_events', t('Event %event end date had passed, checking settings for actions...', array('%event' => $node->title))); if ($action =='delete' ) { $log .= '
' .t('Event %event was DELETED.', array('%event' => $node->title)); db_query("DELETE from {node} WHERE nid = %d", $event->nid); $severity = WATCHDOG_WARNING; // action was taken //watchdog('past_events', t('Event %event was DELETED by cron.', array('%event' => $node->title))); } else { // Manage $q =''; if ($unsticky){ $q .= ',sticky = 0 '; //db_query("UPDATE {node} SET sticky = 0 WHERE nid = %d", $event->nid); //watchdog('past_events', t('Sticky removed for %event by cron.', array('%event' => $node->title))); } if ($unpromote ){ // && $node->promote == 1) { //db_query("UPDATE {node} SET promote = 0 WHERE nid = %d", $event->nid); $q .= ',promote = 0 '; //watchdog('past_events', t('Promote removed for %event by cron.', array('%event' => $node->title))); } if ($unpublish){ //&& $node->status == 1) { $q .= ',status = 0 '; //db_query("UPDATE {node} SET status = 0 WHERE nid = %d", $event->nid); //watchdog('past_events', t('Unpublished event %event by cron.', array('%event' => $node->title))); } // check to see that there is an update command (possible to have all unchecked - so do nothing ) if ($q != ''){ $q = substr($q,1); // drop the first comma db_query("UPDATE {node} SET %s WHERE nid = %d", $q ,$event->nid); $log .= '
' . t('Event %event was handled by settings.', array('%event' => $node->title)); $severity = WATCHDOG_WARNING; // action was taken } else { // no action just log $log .= '
' .t('Event %event - NO ACTION WAS TAKEN.', array('%event' => $node->title)); } } } $log .= '
past_events cron end'; watchdog('past_events',$log,$severity); } ?>