]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11674 fixed mysql incompatible SQL in chat cron
authorskodak <skodak>
Tue, 9 Oct 2007 16:46:04 +0000 (16:46 +0000)
committerskodak <skodak>
Tue, 9 Oct 2007 16:46:04 +0000 (16:46 +0000)
mod/chat/lib.php

index d559949b2da3e97e779e2f688603bd7fd576559e..f802cb154e62d3ebba91796759e44a389dc1cad6 100644 (file)
@@ -233,14 +233,15 @@ function chat_cron () {
     chat_delete_old_users();
 
     /// Delete old messages
-    $sql = "SELECT m.id 
-            FROM {$CFG->prefix}chat_messages m 
-            JOIN {$CFG->prefix}chat c
-              ON m.chatid = c.id
-            WHERE c.keepdays != 0 
-                  AND m.timestamp < ( ".time()." - c.keepdays * 24 * 3600)";
-
-    delete_records_select("chat_messages", "id IN ($sql)");
+    $keepdays = "SELECT c.keepdays
+                   FROM {$CFG->prefix}chat c
+                  WHERE c.id = {$CFG->prefix}chat_messages.chatid AND c.keepdays > 0";
+
+    $sql = "DELETE 
+              FROM {$CFG->prefix}chat_messages
+             WHERE timestamp < ( ".time()." - COALESCE(($keepdays), 999999) * 24 * 3600)";
+
+    execute_sql($sql, false);
 
     return true;
 }