Beispiel #1
0
/**
 * Function to be run periodically according to the moodle cron
 * This function searches for things that need to be done, such
 * as sending out mail, toggling flags etc ...
 *
 * @global object
 * @return bool
 */
function chat_cron()
{
    global $DB;
    chat_update_chat_times();
    chat_delete_old_users();
    /// Delete old messages with a
    /// single SQL query.
    $subselect = "SELECT c.keepdays\n                    FROM {chat} c\n                   WHERE c.id = {chat_messages}.chatid";
    $sql = "DELETE\n              FROM {chat_messages}\n             WHERE ({$subselect}) > 0 AND timestamp < ( " . time() . " -({$subselect}) * 24 * 3600)";
    $DB->execute($sql);
    $sql = "DELETE\n              FROM {chat_messages_current}\n             WHERE timestamp < ( " . time() . " - 8 * 3600)";
    $DB->execute($sql);
    return true;
}
Beispiel #2
0
    if (! $cm = get_coursemodule_from_id('chat', $id)) {
        print_error('invalidcoursemodule');
    }

    if (! $course = $DB->get_record('course', array('id'=>$cm->course))) {
        print_error('coursemisconf');
    }

    chat_update_chat_times($cm->instance);

    if (! $chat = $DB->get_record('chat', array('id'=>$cm->instance))) {
        print_error('invalidid', 'chat');
    }

} else {
    chat_update_chat_times($c);

    if (! $chat = $DB->get_record('chat', array('id'=>$c))) {
        print_error('coursemisconf');
    }
    if (! $course = $DB->get_record('course', array('id'=>$chat->course))) {
        print_error('coursemisconf');
    }
    if (! $cm = get_coursemodule_from_instance('chat', $chat->id, $course->id)) {
        print_error('invalidcoursemodule');
    }
}

require_course_login($course, true, $cm);

$context = context_module::instance($cm->id);
Beispiel #3
0
function chat_cron()
{
    /// Function to be run periodically according to the moodle cron
    /// This function searches for things that need to be done, such
    /// as sending out mail, toggling flags etc ...
    global $CFG;
    chat_update_chat_times();
    chat_delete_old_users();
    /// Delete old messages
    if ($chats = get_records("chat")) {
        foreach ($chats as $chat) {
            if ($chat->keepdays) {
                $timeold = time() - $chat->keepdays * 24 * 3600;
                delete_records_select("chat_messages", "chatid = '{$chat->id}' AND timestamp < '{$timeold}'");
            }
        }
    }
    return true;
}
Beispiel #4
0
function chat_cron()
{
    /// Function to be run periodically according to the moodle cron
    /// This function searches for things that need to be done, such
    /// as sending out mail, toggling flags etc ...
    global $CFG;
    chat_update_chat_times();
    chat_delete_old_users();
    /// Delete old messages
    /// single SQL query.
    $subselect = "SELECT c.keepdays\n                    FROM {$CFG->prefix}chat c\n                   WHERE c.id = {$CFG->prefix}chat_messages.chatid";
    $sql = "DELETE\n              FROM {$CFG->prefix}chat_messages\n             WHERE ({$subselect}) > 0 AND timestamp < ( " . time() . " -({$subselect}) * 24 * 3600)";
    execute_sql($sql, false);
    return true;
}
Beispiel #5
0
function chat_cron()
{
    /// Function to be run periodically according to the moodle cron
    /// This function searches for things that need to be done, such
    /// as sending out mail, toggling flags etc ...
    global $CFG;
    chat_update_chat_times();
    chat_delete_old_users();
    /// Delete old messages
    $sql = "SELECT m.id \n            FROM {$CFG->prefix}chat_messages m \n            JOIN {$CFG->prefix}chat c\n              ON m.chatid = c.id\n            WHERE c.keepdays != 0 \n                  AND m.timestamp < ( " . time() . " - c.keepdays * 24 * 3600)";
    delete_records_select("chat_messages", "id IN ({$sql})");
    return true;
}
Beispiel #6
0
function chat_cron()
{
    /// Function to be run periodically according to the moodle cron
    /// This function searches for things that need to be done, such
    /// as sending out mail, toggling flags etc ...
    global $DB;
    chat_update_chat_times();
    chat_delete_old_users();
    /// Delete old messages with a
    /// single SQL query.
    $subselect = "SELECT c.keepdays\n                    FROM {chat} c\n                   WHERE c.id = {chat_messages}.chatid";
    $sql = "DELETE\n              FROM {chat_messages}\n             WHERE ({$subselect}) > 0 AND timestamp < ( " . time() . " -({$subselect}) * 24 * 3600)";
    $DB->execute($sql);
    $sql = "DELETE\n              FROM {chat_messages_current}\n             WHERE timestamp < ( " . time() . " - 8 * 3600)";
    $DB->execute($sql);
    return true;
}