<?php
/**
* Implements hook_entity_presave().
*
* This hook autamatically sets an unpublish date for events so that they are no
* longer indexed by search engines after event has occurred.
*/
function event_removal_entity_presave($entity, $type) {
if($entity->type == 'event') {
$start_date = date('U', strtotime($entity->field_date['und'][0]['value']));
$end_date = date('U', strtotime($entity->field_date['und'][0]['value2']));
if ($start_date > $end_date) {
$entity->unpublish_on = strtotime('+1 day', $start_date);
}
else {
$entity->unpublish_on = strtotime('+1 day', $end_date);
}
}
}