소스 검색

Add cron script see BT#13552

 - Checks the c_lp_item_view.total_time field, if field has big values
  (in hours) then the script can update the record and/or
  send an alert (email/chamilo inbox message) to a user.

Check the variables:
$sendMessage (bool), $userId (int) and $update (bool).
jmontoyaa 7 년 전
부모
커밋
41b5d31c02
1개의 변경된 파일56개의 추가작업 그리고 0개의 파일을 삭제
  1. 56 0
      main/cron/fix_lp_total_time.php

+ 56 - 0
main/cron/fix_lp_total_time.php

@@ -0,0 +1,56 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+/**
+ * This script checks that the c_lp_item_view.total_time field
+ * doesn't have big values. The scripts updates it or send a message to the admin (depending the settings).
+ */
+
+exit;
+
+require_once __DIR__.'/../../main/inc/global.inc.php';
+
+$maxSeconds = 5 * 60 * 60; // Check records higher than 5 hours
+$valueToUpdate = 1 * 60 * 60; // Update this abusive records with 1 hours
+$limit = 10; // Only fix first 10
+$sendMessage = true;
+$userId = 1; // User id that will receive a report
+$update = false;
+
+$sql = "SELECT iid, total_time FROM c_lp_item_view 
+        WHERE total_time > $maxSeconds 
+        order by total_time desc 
+        LIMIT $limit
+";
+
+$result = Database::query($sql);
+$log = '';
+while ($row = Database::fetch_array($result, 'ASSOC')) {
+    $id = $row['iid'];
+    $oldTotalTime = $row['total_time'];
+    $sql = "UPDATE c_lp_item_view SET total_time = '$valueToUpdate' WHERE iid = $id;";
+    // Uncomment to fix
+    if ($update) {
+        Database::query($sql);
+    }
+
+    $oldTotalTime = round($oldTotalTime / 3600 , 2) ;
+    $report = "Previous total_time : ".round($oldTotalTime/3600,2)." hours";
+    $report .= PHP_EOL;
+    $report .= "New total_time: $valueToUpdate";
+    $report .= PHP_EOL;
+    $report .= $sql;
+    $report .= PHP_EOL;
+    $report .= PHP_EOL;
+    $log .= $report;
+    echo $report;
+}
+
+if ($sendMessage && !empty($log)) {
+    $log = nl2br($log);
+    MessageManager::send_message_simple(
+        $userId,
+        'Course time spent fixes',
+        $log
+    );
+}