Commit 2c899f77 authored by Eugene Venter's avatar Eugene Venter
Browse files

cron: Added relevant cronjobs and functions for cleaning activity...

cron: Added relevant cronjobs and functions for cleaning activity notifications (notification_internal_activity) (bug #645744)
parent 4339a0b4
......@@ -103,6 +103,21 @@ class PluginArtefactComment extends PluginArtefact {
}
return $artefacts;
}
public static function get_cron() {
return array(
(object)array(
'callfunction' => 'clean_feedback_notifications',
'minute' => '35',
'hour' => '22',
),
);
}
public static function clean_feedback_notifications() {
safe_require('notification', 'internal');
PluginNotificationInternal::clean_notifications(array('feedback'));
}
}
class ArtefactTypeComment extends ArtefactType {
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010031900;
$config->version = 2010100700;
$config->release = '0.0.1';
?>
......@@ -345,9 +345,19 @@ EOF;
'callfunction' => 'interaction_forum_new_post',
'minute' => '*/30',
),
(object)array(
'callfunction' => 'clean_forum_notifications',
'minute' => '30',
'hour' => '22',
),
);
}
public static function clean_forum_notifications() {
safe_require('notification', 'internal');
PluginNotificationInternal::clean_notifications(array('newpost'));
}
/**
* Subscribes the forum plugin to events
*
......
......@@ -25,7 +25,7 @@
*
*/
$config->version = 2009111200;
$config->version = 2010100700;
$config->release = '1.2.1';
?>
......@@ -2193,5 +2193,29 @@ function xmldb_core_upgrade($oldversion=0) {
);
}
if ($oldversion < 2010100701) {
// Add general notification cleanup cron
if (!record_exists('cron', 'callfunction', 'cron_clean_internal_activity_notifications')) {
$cron = new StdClass;
$cron->callfunction = 'cron_clean_internal_activity_notifications';
$cron->minute = 45;
$cron->hour = 22;
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = '*';
insert_record('cron', $cron);
}
// Add forum notification cleanup cron
if ($data = check_upgrades('interaction.forum')) {
upgrade_plugin($data);
}
// Add feedback notification cleanup cron
if ($data = check_upgrades('artefact.comment')) {
upgrade_plugin($data);
}
}
return $status;
}
......@@ -2383,6 +2383,13 @@ function recalculate_quota() {
}
}
/**
* A cronjob to clean general internal activity notifications
*/
function cron_clean_internal_activity_notifications() {
safe_require('notification', 'internal');
PluginNotificationInternal::clean_notifications(array('viewaccess', 'watchlist', 'institutionmessage'));
}
/**
* Cronjob to check Launchpad for the latest Mahara version
......
......@@ -790,21 +790,22 @@ function core_install_firstcoredata_defaults() {
// install the cronjobs...
$cronjobs = array(
'rebuild_artefact_parent_cache_dirty' => array('*', '*', '*', '*', '*'),
'rebuild_artefact_parent_cache_complete' => array('0', '4', '*', '*', '*'),
'auth_clean_partial_registrations' => array('5', '0', '*', '*', '*'),
'auth_handle_account_expiries' => array('5', '10', '*', '*', '*'),
'auth_handle_institution_expiries' => array('5', '9', '*', '*', '*'),
'activity_process_queue' => array('*/5', '*', '*', '*', '*'),
'auth_remove_old_session_files' => array('30', '20', '*', '*', '*'),
'recalculate_quota' => array('15', '2', '*', '*', '*'),
'import_process_queue' => array('*/5', '*', '*', '*', '*'),
'cron_send_registration_data' => array(rand(0, 59), rand(0, 23), '*', '*', rand(0, 6)),
'export_cleanup_old_exports' => array('0', '3,15', '*', '*', '*'),
'import_cleanup_old_imports' => array('0', '4,16', '*', '*', '*'),
'cron_site_data_weekly' => array('55', '23', '*', '*', '6'),
'cron_site_data_daily' => array('51', '23', '*', '*', '*'),
'cron_check_for_updates' => array(rand(0, 59), rand(0, 23), '*', '*', '*'),
'rebuild_artefact_parent_cache_dirty' => array('*', '*', '*', '*', '*'),
'rebuild_artefact_parent_cache_complete' => array('0', '4', '*', '*', '*'),
'auth_clean_partial_registrations' => array('5', '0', '*', '*', '*'),
'auth_handle_account_expiries' => array('5', '10', '*', '*', '*'),
'auth_handle_institution_expiries' => array('5', '9', '*', '*', '*'),
'activity_process_queue' => array('*/5', '*', '*', '*', '*'),
'auth_remove_old_session_files' => array('30', '20', '*', '*', '*'),
'recalculate_quota' => array('15', '2', '*', '*', '*'),
'import_process_queue' => array('*/5', '*', '*', '*', '*'),
'cron_send_registration_data' => array(rand(0, 59), rand(0, 23), '*', '*', rand(0, 6)),
'export_cleanup_old_exports' => array('0', '3,15', '*', '*', '*'),
'import_cleanup_old_imports' => array('0', '4,16', '*', '*', '*'),
'cron_site_data_weekly' => array('55', '23', '*', '*', '6'),
'cron_site_data_daily' => array('51', '23', '*', '*', '*'),
'cron_check_for_updates' => array(rand(0, 59), rand(0, 23), '*', '*', '*'),
'cron_clean_internal_activity_notifications'=> array(45, 22, '*', '*', '*'),
);
foreach ($cronjobs as $callfunction => $times) {
$cron = new StdClass;
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010091500;
$config->version = 2010100702;
$config->release = '1.4.0dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
......@@ -68,7 +68,7 @@ class PluginNotificationInternal extends PluginNotification {
}
return $unreadcount[$userid];
}
public static function get_event_subscriptions() {
$subscriptions = array(
(object)array(
......@@ -83,6 +83,30 @@ class PluginNotificationInternal extends PluginNotification {
public static function deleteuser($event, $user) {
delete_records('notification_internal_activity', 'usr', $user['id']);
}
/**
* A method that does housekeeping on the notification_internal_activity table
* @param $types string|array the activity types to be cleaned
* @param $olderthandays integer the age an entry should at least be, before cleaning
*/
public static function clean_notifications($types, $olderthandays=182) {
$staletime = db_format_timestamp(time() - ($olderthandays * 24 * 60 * 60));
if (!is_array($types)) {
// We're potentially dealing with just one type
$types = array($types);
}
$select = "
ctime < ?
AND read = 1
AND type IN(
SELECT id FROM {activity_type}
WHERE name IN (" . join(",", array_map(create_function('$a', 'return db_quote($a);'), $types)) . "))";
delete_records_select('notification_internal_activity', $select, array(db_format_timestamp($staletime)));
}
}
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment