Habari\EventLog::trim PHP Method

trim() public static method

* Trim the EventLog down to the defined number of days to prevent it getting massively large.
public static trim ( )
    public static function trim()
    {
        // allow an option to be set to override the log retention - in days
        $retention_days = Options::get('log_retention', 14);
        // default to 14 days
        // make it into the string we'll use
        $retention = '-' . intval($retention_days) . ' days';
        // Trim the log table down
        $date = DateTime::create()->modify($retention);
        $result = DB::query('DELETE FROM {log} WHERE timestamp < ?', array($date->sql));
        if ($result) {
            EventLog::log(_t('Entries over %d days old were trimmed from the EventLog', array($retention_days)), 'info');
        } else {
            EventLog::log(_t('There was an error trimming old entries from the EventLog!'), 'err');
        }
        return $result;
    }