Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chamilo-lms/plugin/exercisemonitoring/cron/cleanup.php

98 lines
2.3 KiB

Plugin: Exercise monitoring and mouse focus tracking - refs BT#20900 BT#20901 (#4900) * Plugin: ExerciseFocused: Add plugin - refs BT#20900 * Plugin: ExerciseFocused: Refactoring variable and setting names - refs BT#20900 * Plugin: ExerciseMonitoring: Add plugin - refs BT#20901 * Plugin: ExerciseMonitoring: Terms popup is not callable - refs BT#20901 * Plugin: ExerciseMonitoring: Remove countdown to snap - refs BT#20901 * Plugin: ExerciseMonitoring: Snap when pressing spacer - refs BT#20901 * Plugin: ExerciseMonitoring: Redirect when ending initial photos - refs BT#20901 * Plugin: ExerciseMonitoring: Differ between exercise one per page or all question per page - refs BT#20901 * Plugin: ExerciseMonitoring: Set snapshot dimension to 640x480 - refs BT#20901 * Plugin: ExerciseFocused: Show warning to alert user before leaving exercise - refs BT#20900 * Plugin: ExerciseMonitoring: Don't show modal when there isn't Start button - refs BT#20901 * Plugin: ExerciseFocused: Block click event - refs BT#20900 * Plugin: ExerciseMonitoring: Fix video responsive - refs BT#20901 * Plugin: ExerciseMonitoring: Add instructions to take snapshots - refs BT#20901 * Plugin: ExerciseFocused: Refactor query for results - refs BT#20901 * Plugin: ExerciseFocused: Add setting to generate random sampling - refs BT#21074 * Plugin: ExerciseFocused: Display motive in report with contextual style - refs BT#21074 * Plugin: ExerciseMonitoring: Show snapshot logs in ExerciseFocused plugin report - refs BT#21074 * Minor: Format code - refs BT#21074 * Plugin: ExerciseFocused: Language variable - refs BT#20900 * Plugin: ExerciseMonitoring: Fix extrafield name - refs BT#20900 * Plugin: ExerciseFocused: Allow to enable time limit by setting - refs BT#20901 * Plugin: ExerciseFocused: Add spanish language - refs BT#20901 * Plugin: ExerciseMonitoring: Add spanish language - refs BT#20900 * Plugin: ExerciseMonitoring: Add placeholders to camera - refs BT#20901 * Plugin: ExerciseMonitoring: Refactor to show link in plugin Exercise Focused - refs BT#20901 * Plugin: ExerciseMonitoring: Fix lang var - refs BT#20901 * Plugin: ExerciseMonitoring: Fix irregular grid - refs BT#20901 * Plugin: ExerciseFocused: Allow save level in log - refs BT#20900 * Plugin: ExerciseFocused: Allow export for exercise with one question per page - refs BT#21074 * Plugin: ExerciseFocused: ExerciseMonitoring: Fix lang variables - refs BT#20900 BT#20901 * Plugin: ExerciseFocused: Fix report when there is no exercise attempts in course - refs BT#21074 * Plugin: ExerciseFocused: Include snapshots column from ExerciseMonitoring plugin in report - refs BT#21074 * Minor: Format code - refs BT#21074 * Plugin: ExerciseFocused: Simplify conditions with exercise type - refs BT#20900 * Plugin: ExerciseFocused: ExerciseMonitoring: Use new term to level + improve warning message - refs BT#21074 * Plugin: ExerciseMonitoring: set genera column to level in report - refs BT#21074 * Plugin: ExerciseMonitoring: ExerciseFocused: Change language vars - refs BT#21074 * Plugin: ExerciseMonitoring: ExerciseFocused: unify header in modals - BT#21074 * Plugin: ExerciseMonitoring: ExerciseFocused: use Student term instead of Learner - BT#21074 * Plugin: ExerciseFocused: Display level reached in detail - BT#21074 * Plugin: ExerciseMonitoring: Move code to function - BT#21074 * Plugin: ExerciseFocused: Change language variable - refs BT#21074 * Plugin: ExerciseFocused: Change language variables - refs BT#21074 * Plugin: ExerciseFocused: Add columns about session/course in admin report - refs BT#21074 * Plugin: ExerciseFocused: Fix language vars in report - refs BT#21074 * Plugin: ExerciseFocused: Add IP report exported + fix lang var - refs BT#21074 * Plugin: ExerciseMonitoring: Add option to set instructions with age distinction - refs BT#21179 * Plugin: ExerciseMonitoring: Move code to function - refs BT#20901 * Plugin: ExerciseMonitoring: Fix ID and user snapshots without track_e_exercise.id - refs BT#20901 * Plugin: ExerciseFocused: Separate the column full name in two columns + separate username row in report - refs BT#21074 * Plugin: ExerciseFocused: Search form has optional fields - refs BT#21074 * Plugin: ExerciseMonitoring: Show the birthdate and legal age in report - refs BT#21074 * Minor: Add missing webcam.png icon with size small - refs BT#21074 * Plugin: ExerciseFocused: Fix detail for admin report - refs BT#21074 * Plugin: ExerciseMonitoring: Add setting and cron job to delete snapshots taken - refs BT#21074 * Minor: Plugin: ExerciseFocused: Delay backdrop - refs BT#21074 * Minor: Plugin: ExerciseFocused: change message for window/tab title - refs BT#21074 * Plugin: ExerciseFocused: Keep message visibility after refocusing - refs BT#20901 * Plugin: ExerciseFocused: Fix filter by session extra fields - refs BT#21074 * Plugin: ExerciseFocused: Fix report by session extra fields - refs BT#21074 * Plugin: ExerciseMonitoring: Make the live camera floating - refs BT#20901 * Plugin: ExerciseFocused: Make the alert message floating - refs BT#20901 * Plugin: ExerciseFocused: Change lang var for motive - refs BT#21074 * Plugin: ExerciseFocused: Increase delay time to hide messages - refs BT#20900 * Plugin: ExerciseMonitoring: Improve image placeholders for id card and student - refs BT#20901 * Plugin: ExerciseMonitoring: Improve image placeholders for id card - refs BT#20901 * Minor: Plugin: ExerciseFocused: Fix lang var - refs BT#20901 * Plugin: ExerciseFocused: Fix random results - refs BT#21074 * Plugin: ExerciseFocused: Fix session filter - refs BT#21074 * Plugin: ExerciseFocused: Allow multiple match in firstname and lastname filters - refs BT#21074 * Plugin: ExerciseFocused: Round number of random results - refs BT#21074 * Plugin: ExerciseFocused: Add button to reset search - refs BT#21074 * Minor: Format code
11 months ago
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\TrackEExercises;
use Chamilo\PluginBundle\ExerciseMonitoring\Entity\Log;
use Symfony\Component\Filesystem\Filesystem;
require_once __DIR__.'/../../../main/inc/global.inc.php';
if ('cli' !== PHP_SAPI) {
exit('For security reasons, this script can only be launched from cron or from the command line');
}
exit;
$plugin = ExerciseMonitoringPlugin::create();
$em = Database::getManager();
$repo = $em->getRepository(Log::class);
$trackExeRepo = $em->getRepository(TrackEExercises::class);
$lifetimeDays = (int) $plugin->get(ExerciseMonitoringPlugin::SETTING_SNAPSHOTS_LIFETIME);
if (empty($lifetimeDays)) {
logging("There is no set time limit");
exit;
}
$timeLimit = api_get_utc_datetime(null, false, true);
$timeLimit->modify("-$lifetimeDays day");
logging(
sprintf("Deleting snapshots taken before than %s", $timeLimit->format('Y-m-d H:i:s'))
);
$fs = new Filesystem();
$logs = findLogsBeforeThan($timeLimit);
foreach ($logs as $log) {
$sysPath = ExerciseMonitoringPlugin::generateSnapshotUrl(
$log['exe_user_id'],
$log['image_filename'],
SYS_UPLOAD_PATH
);
if (!file_exists($sysPath)) {
logging(
sprintf("File %s not exists", $sysPath)
);
continue;
}
$fs->remove($sysPath);
Database::update(
'plugin_exercisemonitoring_log',
['removed' => true],
['id = ?' => $log['log_id']]
);
logging(
sprintf(
"From exe_id %s; deleting filename %s created at %s",
$log['exe_id'],
$sysPath,
$log['created_at']
)
);
}
function findLogsBeforeThan(DateTime $timeLimit): array
{
$sql = "SELECT tee.exe_id, l.id AS log_id, l.image_filename, tee.exe_user_id
FROM plugin_exercisemonitoring_log l
INNER JOIN chamilo.track_e_exercises tee on l.exe_id = tee.exe_id
WHERE l.created_at <= '".$timeLimit->format('Y-m-d H:i:s')."'
AND l.removed IS FALSE";
$result = Database::query($sql);
$rows = [];
while ($row = Database::fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
}
function logging(string $message)
{
$time = time();
printf("[%s] %s \n", $time, $message);
}