mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-07 08:34:29 +01:00
Add feature to regularly remove old calendar events that are more than x years in the past. Set in Admin -> Calendar -> Site configuration
This commit is contained in:
parent
a3e6e6e2f6
commit
c4a8515d99
@ -2160,4 +2160,41 @@ class calendar_boupdate extends calendar_bo
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Delete events that are more than $age years old
|
||||
*
|
||||
* Purges old events from the database
|
||||
*
|
||||
* @param int $age How many years old the event must be before it is deleted
|
||||
*/
|
||||
function purge($age)
|
||||
{
|
||||
$query = array(
|
||||
'end' => strtotime("-$age years", time()),
|
||||
'enum_recuring' => false
|
||||
);
|
||||
$events = $this->search($query);
|
||||
foreach($events as $event)
|
||||
{
|
||||
// Delete single events or recurring events where all ocurrences are old enough
|
||||
if(!$event['recur_type'] || $event['recur_type'] && $event['recur_enddate'] && $event['recur_enddate'] <= $query['end'])
|
||||
{
|
||||
$this->delete($event['id'], 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
// If preserve history is on, we'll need to do this again to completely remove it
|
||||
$config = config::read('phpgwapi');
|
||||
if($config['calendar_delete_history']) {
|
||||
$query['filter'] = 'deleted';
|
||||
$events = $this->search($query);
|
||||
foreach($events as $event)
|
||||
{
|
||||
if(!$event['recur_type'] || $event['recur_type'] && $event['recur_enddate'] && $event['recur_enddate'] <= $query['end'])
|
||||
{
|
||||
$this->delete($event['id'], 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -531,4 +531,27 @@ class calendar_hooks
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function config_validate() {
|
||||
$GLOBALS['egw_info']['server']['found_validation_hook'] = True;
|
||||
}
|
||||
}
|
||||
|
||||
// Not part of the class, since config hooks are still using the old style
|
||||
function calendar_purge_old($config) {
|
||||
$id = 'calendar_purge';
|
||||
|
||||
// Cancel old purge
|
||||
ExecMethod('phpgwapi.asyncservice.cancel_timer', $id);
|
||||
|
||||
$result = ExecMethod2('phpgwapi.asyncservice.set_timer',
|
||||
array('month' => '*', 'day' => 1),
|
||||
$id,
|
||||
'calendar.calendar_boupdate.purge',
|
||||
(int)$config
|
||||
);
|
||||
if(!$result)
|
||||
{
|
||||
$GLOBALS['config_error'] = 'Unable to schedule purge';
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,7 @@ $setup_info['calendar']['hooks']['preferences'] = 'calendar_hooks::preferences';
|
||||
$setup_info['calendar']['hooks']['settings'] = 'calendar_hooks::settings';
|
||||
$setup_info['calendar']['hooks']['sidebox_menu'] = 'calendar.calendar_ui.sidebox_menu';
|
||||
$setup_info['calendar']['hooks']['search_link'] = 'calendar_hooks::search_link';
|
||||
$setup_info['calendar']['hooks']['config_validate'] = 'calendar_hooks::config_validate';
|
||||
|
||||
/* Dependencies for this app to work */
|
||||
$setup_info['calendar']['depends'][] = array(
|
||||
|
@ -68,6 +68,20 @@
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="row_off">
|
||||
<td> {lang_Automatically_purge_old_events_after}</td>
|
||||
<td>
|
||||
<select name="newsettings[calendar_purge_old]">
|
||||
<option value="">{lang_No_automatic_purging}</option>
|
||||
<option value="1"{selected_calendar_purge_old_1}>1 {lang_year}</option>
|
||||
<option value="2"{selected_calendar_purge_old_2}>2 {lang_years}</option>
|
||||
<option value="3"{selected_calendar_purge_old_3}>3 {lang_years}</option>
|
||||
<option value="4"{selected_calendar_purge_old_4}>4 {lang_years}</option>
|
||||
<option value="5"{selected_calendar_purge_old_5}>5 {lang_years}</option>
|
||||
<option value="10"{selected_calendar_purge_old_10}>10 {lang_years}</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="th">
|
||||
<td colspan="2"><b>{lang_Birthdays}</b></td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user