public function execute() {
        global $CFG, $DB;
        require_once($CFG->dirroot . '/mod/chat/lib.php');

        chat_update_chat_times();
        chat_delete_old_users();

        $timenow = time();
        $subselect = "SELECT c.keepdays
                        FROM {chat} c
                       WHERE c.id = {chat_messages}.chatid";
        $DB->delete_records_select('chat_messages', "($subselect) > 0 AND timestamp < (? - ($subselect) * ?)",
                [$timenow, DAYSECS]);

        $DB->delete_records_select('chat_messages_current', "timestamp < ?", [$timenow - 8 * HOURSECS]);
    }
public function execute() {
        global $CFG, $DB;
        require_once($CFG->dirroot . '/mod/chat/lib.php');

        chat_update_chat_times();
        chat_delete_old_users();

        $timenow = time();
        $subselect = "SELECT c.keepdays
                        FROM {chat} c
                       WHERE c.id = {chat_messages}.chatid";
        $DB->delete_records_select('chat_messages', "($subselect) > 0 AND timestamp < (? - ($subselect) * ?)",
                [$timenow, DAYSECS]);

        $DB->delete_records_select('chat_messages_current', "timestamp < ?", [$timenow - 8 * HOURSECS]);
    }
public function execute ( ) { global $ CFG , $ DB ; require_once ( $ CFG -> dirroot . '/mod/chat/lib.php' ) ; chat_update_chat_times ( ) ; chat_delete_old_users ( ) ; $ timenow = time ( ) ; $ subselect = "SELECT c.keepdays
                        FROM {chat} c
                       WHERE c.id = {chat_messages}.chatid" ; $ DB -> delete_records_select ( 'chat_messages' , "($subselect) > 0 AND timestamp < (? - ($subselect) * ?)" , [ $ timenow , DAYSECS ] ) ; $ DB -> delete_records_select ( 'chat_messages_current' , "timestamp < ?" , [ $ timenow - 8 * HOURSECS ] ) ; }
Run chat cron.
Run chat cron .