努力对 Moodle 数据库 table "mdl_logstore_standard_log" 进行正确查询,以便从 GUI 导出日志
Struggle to make the right query to the Moodle database table "mdl_logstore_standard_log" in order to export logs as it happens from the GUI
我的问题是我正在尝试从 Moodle DB "mdl_logstore_standard_log" 导出一个 csv 文件,其顺序与站点管理 > 报告下的日志页面的顺序完全相同。
The Moodle GUI report fields order
实现这一目标的一个想法是通过如下查询:
SELECT
FROM_UNIXTIME(l.timecreated,'%d %b, %H:%i') AS `Time`,
CONCAT(u.firstname, ' ', u.lastname) AS `User full name`,
CONCAT(au.firstname, ' ', au.lastname) AS `Affected user`,
l.origin AS `Origin`,
l.ip AS `IP address`
FROM mdl_logstore_standard_log AS l
LEFT JOIN mdl_user AS u ON u.id = l.userid
LEFT JOIN mdl_user AS au ON au.id = l.relateduserid
不幸的是,上述查询的行为与我预期的不同。我需要来自 moodle 的 GUI 报告的确切数据。不知道这个查询是否已经在 moodle 的 php 文件中实现,或者有人以前试过这个?
Web 表单不依赖于单个查询,而是一系列查询和 PHP 代码来创建日志报告。如果你有兴趣,我在这里记录了两个这样的系列:Todays Logs and All Logs。
日志中的大部分查询专门用于查看权限等,主要部分可以在最后找到,大致从这里开始:
SELECT COUNT('x') FROM mdl_course
SELECT id,shortname,fullname,category FROM mdl_course ORDER BY fullname
SELECT u.id, u.firstnamephonetic,u.lastnamephonetic,u.middlename,u.alternatename,u.firstname,u.lastname
FROM mdl_user u
JOIN (SELECT DISTINCT eu1_u.id
FROM mdl_user eu1_u
WHERE 1 = 1 AND eu1_u.deleted = 0) je ON je.id = u.id
WHERE u.deleted = 0 ORDER BY u.lastname, u.firstname, u.id LIMIT 0, 1001
SELECT COUNT('x') FROM mdl_logstore_standard_log WHERE anonymous = 0
SELECT * FROM mdl_logstore_standard_log WHERE anonymous = 0 ORDER BY timecreated DESC, id DESC LIMIT 0, 100
SELECT id,firstnamephonetic,lastnamephonetic,middlename,alternatename,firstname,lastname FROM mdl_user WHERE id = '2'
SELECT * FROM mdl_logstore_standard_log WHERE anonymous = 0 ORDER BY timecreated DESC, id DESC LIMIT 0, 100
SELECT * FROM mdl_user WHERE id = '2' AND deleted = '0'
就是这样。
所以基本上,你做对了。但是,您需要漂亮地打印剩余的列,即 contextid
、component
、eventname
和 other
,您自己:
SELECT FROM_UNIXTIME(l.timecreated, '%d %b, %H:%i') AS `Time`
,CONCAT (u.firstname, ' ', u.lastname) AS `User FULL name`
,CONCAT (au.firstname, ,' ', au.lastname) AS `Affected user`
,l.contextid AS EventContext
,l.component
,l.eventname
,other AS description
,l.origin AS `Origin`
,l.ip AS `IP address`
FROM mdl_logstore_standard_log AS l
LEFT JOIN mdl_user AS u ON u.id = l.userid
LEFT JOIN mdl_user AS au ON au.id = l.relateduserid
WHERE l.anonymous = 0
ORDER BY l.timecreated DESC
,l.id DESC
如果这与自动化有任何关系而不仅仅是报告,我会避免繁琐的翻译,只使用此处选择的原始数据。
我的问题是我正在尝试从 Moodle DB "mdl_logstore_standard_log" 导出一个 csv 文件,其顺序与站点管理 > 报告下的日志页面的顺序完全相同。
The Moodle GUI report fields order
实现这一目标的一个想法是通过如下查询:
SELECT
FROM_UNIXTIME(l.timecreated,'%d %b, %H:%i') AS `Time`,
CONCAT(u.firstname, ' ', u.lastname) AS `User full name`,
CONCAT(au.firstname, ' ', au.lastname) AS `Affected user`,
l.origin AS `Origin`,
l.ip AS `IP address`
FROM mdl_logstore_standard_log AS l
LEFT JOIN mdl_user AS u ON u.id = l.userid
LEFT JOIN mdl_user AS au ON au.id = l.relateduserid
不幸的是,上述查询的行为与我预期的不同。我需要来自 moodle 的 GUI 报告的确切数据。不知道这个查询是否已经在 moodle 的 php 文件中实现,或者有人以前试过这个?
Web 表单不依赖于单个查询,而是一系列查询和 PHP 代码来创建日志报告。如果你有兴趣,我在这里记录了两个这样的系列:Todays Logs and All Logs。
日志中的大部分查询专门用于查看权限等,主要部分可以在最后找到,大致从这里开始:
SELECT COUNT('x') FROM mdl_course
SELECT id,shortname,fullname,category FROM mdl_course ORDER BY fullname
SELECT u.id, u.firstnamephonetic,u.lastnamephonetic,u.middlename,u.alternatename,u.firstname,u.lastname
FROM mdl_user u
JOIN (SELECT DISTINCT eu1_u.id
FROM mdl_user eu1_u
WHERE 1 = 1 AND eu1_u.deleted = 0) je ON je.id = u.id
WHERE u.deleted = 0 ORDER BY u.lastname, u.firstname, u.id LIMIT 0, 1001
SELECT COUNT('x') FROM mdl_logstore_standard_log WHERE anonymous = 0
SELECT * FROM mdl_logstore_standard_log WHERE anonymous = 0 ORDER BY timecreated DESC, id DESC LIMIT 0, 100
SELECT id,firstnamephonetic,lastnamephonetic,middlename,alternatename,firstname,lastname FROM mdl_user WHERE id = '2'
SELECT * FROM mdl_logstore_standard_log WHERE anonymous = 0 ORDER BY timecreated DESC, id DESC LIMIT 0, 100
SELECT * FROM mdl_user WHERE id = '2' AND deleted = '0'
就是这样。
所以基本上,你做对了。但是,您需要漂亮地打印剩余的列,即 contextid
、component
、eventname
和 other
,您自己:
SELECT FROM_UNIXTIME(l.timecreated, '%d %b, %H:%i') AS `Time`
,CONCAT (u.firstname, ' ', u.lastname) AS `User FULL name`
,CONCAT (au.firstname, ,' ', au.lastname) AS `Affected user`
,l.contextid AS EventContext
,l.component
,l.eventname
,other AS description
,l.origin AS `Origin`
,l.ip AS `IP address`
FROM mdl_logstore_standard_log AS l
LEFT JOIN mdl_user AS u ON u.id = l.userid
LEFT JOIN mdl_user AS au ON au.id = l.relateduserid
WHERE l.anonymous = 0
ORDER BY l.timecreated DESC
,l.id DESC
如果这与自动化有任何关系而不仅仅是报告,我会避免繁琐的翻译,只使用此处选择的原始数据。