Skip to content

Commit 5879c81

Browse files
committed
Minor - improve debug, add opcache_reset, default time value 600 seconds
1 parent c49cfa8 commit 5879c81

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

main/cron/check_lp_total_time.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
api_protect_admin_script();
1414

15+
opcache_reset();
16+
1517
$testSessionId = 182;
1618
$testCourseId = 97;
1719
$max = 10;
@@ -80,7 +82,7 @@
8082
function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
8183
{
8284
$userId = $user['user_id'];
83-
$defaultValue = 1800; // 30 min
85+
$defaultValue = 600; // 10 min
8486
$courseCode = $courseInfo['code'];
8587
$courseId = $courseInfo['real_id'];
8688

@@ -102,9 +104,12 @@ function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
102104
);
103105
$content = '';
104106
if ($totalLpTime > $totalCourseTime) {
105-
$totalCourseTime = api_time_to_hms($totalCourseTime);
106-
$totalLpTime = api_time_to_hms($totalLpTime);
107-
$content = "User: ".$user['user_id']." - Total course: $totalCourseTime / Total LP: $totalLpTime";
107+
$totalCourseTimeFormatted = api_time_to_hms($totalCourseTime);
108+
$totalLpTimeFormatted = api_time_to_hms($totalLpTime);
109+
$diff = $totalLpTime - $totalCourseTime;
110+
111+
$content = PHP_EOL."User: ".$user['user_id']." - Total course: $totalCourseTimeFormatted / Total LP: $totalLpTimeFormatted".PHP_EOL;
112+
$content .= PHP_EOL."Diff: ".api_time_to_hms($diff).PHP_EOL;
108113
$url = api_get_path(WEB_CODE_PATH).'mySpace/myStudents.php?student='.$userId.'&course='.$courseCode.'&id_session='.$sessionId;
109114
$content .= Display::url('Check', $url, ['target' => '_blank']);
110115
$content .= PHP_EOL;
@@ -121,6 +126,7 @@ function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
121126
ORDER BY total_time desc
122127
LIMIT 1
123128
";
129+
echo $sql.PHP_EOL;
124130
$result = Database::query($sql);
125131
$results = Database::store_result($result, 'ASSOC');
126132
if (!empty($results)) {
@@ -132,7 +138,12 @@ function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
132138
$content .= "total_time = ".api_time_to_hms($item['total_time']).PHP_EOL;
133139
$content .= Display::url('See report before update', $link, ['target' => '_blank']).PHP_EOL;
134140
$content .= "SQL with possible fix:".PHP_EOL;
135-
$content .= "UPDATE c_lp_item_view SET total_time = '$defaultValue' WHERE iid = ".$item['iid'].";".PHP_EOL.PHP_EOL;
141+
142+
if ($item['total_time'] < $defaultValue) {
143+
$content .= "Skip because total_time is too short. total_time: ".$item['total_time'].' value to rest'.$defaultValue.PHP_EOL;
144+
continue;
145+
}
146+
$content .= "UPDATE c_lp_item_view SET total_time = total_time - '$defaultValue' WHERE iid = ".$item['iid'].";".PHP_EOL.PHP_EOL;
136147
}
137148
}
138149
}

0 commit comments

Comments
 (0)