Check in initial version - requires cronjob

This commit is contained in:
Kumi 2022-01-22 08:45:12 +01:00
commit 8f2e603d1c
2 changed files with 38 additions and 0 deletions

28
execute.php Normal file
View file

@ -0,0 +1,28 @@
<?php
define("CLI_SCRIPT", true);
require_once(__DIR__ . "/../../config.php");
$query = file_get_contents("query.sql");
$results = $DB->get_records_sql($query);
$fields = array("Email", "User Last Access", "Course ID", "Course Name", "Certificate Creation Date");
$date = date('Ymd', strtotime("-1 days"));
$mem = fopen("/replication/csv/" . $date . ".csv", "w");
$delim = ",";
fputcsv($mem, $fields, $delim);
foreach ($results as $result) {
$resultfields = array(
$result->email,
$result->user_last_access,
$result->id,
$result->fullname,
$result->certificate_created
);
fputcsv($mem, $resultfields, $delim);
}

10
query.sql Normal file
View file

@ -0,0 +1,10 @@
SELECT u.email,
FROM_UNIXTIME(u.lastaccess, "%d.%m.%Y %H:%i:%s") "user_last_access",
c.id,
c.fullname,
FROM_UNIXTIME(ci.timecreated, "%d.%m.%Y %H:%i:%s") "certificate_created"
FROM mdl_customcert_issues ci
LEFT JOIN mdl_customcert cc ON ci.customcertid = cc.id
LEFT JOIN mdl_user u ON u.id = ci.userid
LEFT JOIN mdl_course c ON c.id = cc.course
WHERE DATE(FROM_UNIXTIME(ci.timecreated)) = DATE_SUB(CURDATE(), INTERVAL 1 DAY);