src/Core/Activity.php
public static function purgeCaliperEvents() {
        global $CFG;

        // We really want some quiet time...
        if ( U::apcAvailable() ) {
            $push_found = false;
            $last_push = apc_fetch('last_event_push_time',$push_found);
            $push_diff = time() - $last_push;

            $purge_found = false;
            $last_purge = apc_fetch('last_event_purge_time',$purge_found);
            $purge_diff = time() - $last_purge;

            if ( ($push_found && $push_diff < self::PUSH_REPEAT_SECONDS) ||
                 ($purge_found && $purge_diff < self::PURGE_REPEAT_SECONDS) ) {
                // error_log("Last purge was $purge_diff seconds ago last push was $push_diff seconds ago");
                return 0;
            }
            apc_store('last_event_purge_time', time());
        } else { // purge probabilistically
            $check = isset($CFG->eventcheck) ? $CFG->eventcheck : 1000;
            if ( $check < 1 ) $check = 1000;
            if ( time() % $check !== 0 ) return 0;
        }

        $eventtime = isset($CFG->eventtime) ? $CFG->eventtime : 24*60*60; // one day

        $PDOX = LTIX::getConnection();

        $stmt = $PDOX->queryDie("DELETE FROM {$CFG->dbprefix}cal_event WHERE
            created_at < DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -{$eventtime} SECOND)");

        if ( $stmt->rowCount() > 0 ) {
            error_log("Event table cleanup rows=".$stmt->rowCount());
        }

        return $stmt->rowCount();
    }
public static function purgeCaliperEvents() {
        global $CFG;

        // We really want some quiet time...
        if ( U::apcAvailable() ) {
            $push_found = false;
            $last_push = apc_fetch('last_event_push_time',$push_found);
            $push_diff = time() - $last_push;

            $purge_found = false;
            $last_purge = apc_fetch('last_event_purge_time',$purge_found);
            $purge_diff = time() - $last_purge;

            if ( ($push_found && $push_diff < self::PUSH_REPEAT_SECONDS) ||
                 ($purge_found && $purge_diff < self::PURGE_REPEAT_SECONDS) ) {
                // error_log("Last purge was $purge_diff seconds ago last push was $push_diff seconds ago");
                return 0;
            }
            apc_store('last_event_purge_time', time());
        } else { // purge probabilistically
            $check = isset($CFG->eventcheck) ? $CFG->eventcheck : 1000;
            if ( $check < 1 ) $check = 1000;
            if ( time() % $check !== 0 ) return 0;
        }

        $eventtime = isset($CFG->eventtime) ? $CFG->eventtime : 24*60*60; // one day

        $PDOX = LTIX::getConnection();

        $stmt = $PDOX->queryDie("DELETE FROM {$CFG->dbprefix}cal_event WHERE
            created_at < DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -{$eventtime} SECOND)");

        if ( $stmt->rowCount() > 0 ) {
            error_log("Event table cleanup rows=".$stmt->rowCount());
        }

        return $stmt->rowCount();
    }
public static function purgeCaliperEvents ( ) { global $ CFG ; // We really want some quiet time... if ( U :: apcAvailable ( ) ) { $ push_found = false ; $ last_push = apc_fetch ( 'last_event_push_time' , $ push_found ) ; $ push_diff = time ( ) - $ last_push ; $ purge_found = false ; $ last_purge = apc_fetch ( 'last_event_purge_time' , $ purge_found ) ; $ purge_diff = time ( ) - $ last_purge ; if ( ( $ push_found && $ push_diff < self :: PUSH_REPEAT_SECONDS ) || ( $ purge_found && $ purge_diff < self :: PURGE_REPEAT_SECONDS ) ) { // error_log("Last purge was $purge_diff seconds ago last push was $push_diff seconds ago"); return 0 ; } apc_store ( 'last_event_purge_time' , time ( ) ) ; } else { // purge probabilistically $ check = isset ( $ CFG -> eventcheck ) ? $ CFG -> eventcheck : 1000 ; if ( $ check < 1 ) $ check = 1000 ; if ( time ( ) % $ check !== 0 ) return 0 ; } $ eventtime = isset ( $ CFG -> eventtime ) ? $ CFG -> eventtime : 24 * 60 * 60 ; // one day $ PDOX = LTIX :: getConnection ( ) ; $ stmt = $ PDOX -> queryDie ( "DELETE FROM {$CFG->dbprefix}cal_event WHERE
            created_at < DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -{$eventtime} SECOND)" ) ; if ( $ stmt -> rowCount ( ) > 0 ) { error_log ( "Event table cleanup rows=" . $ stmt -> rowCount ( ) ) ; } return $ stmt -> rowCount ( ) ; }
Periodic cleanup of broken Caliper events

This is needed when an lti_key has Caliper turned on for a while
and then later turns it off - the non-pushed events are stranded
since they no longer have a good caliper_url / caliper_key.  So
once in a great while, we clean these up.
Periodic cleanup of broken Caliper events