diff --git a/docs/historical-events.md b/docs/historical-events.md index 1227f3151..5fa1f9d7d 100644 --- a/docs/historical-events.md +++ b/docs/historical-events.md @@ -1,199 +1,21 @@ # Guide to Historical Events -Hey there 👋 so you want to process some events from the past 🕓, probably a time when this plugin wasn't installed on your Moodle. That's awesome and we really want to help with that. Unfortunately, we've [not built this into the plugin natively yet](https://github.com/xAPI-vle/moodle-logstore_xapi/issues/42), but luckily [@davidfkane](https://github.com/davidfkane) kindly posted the script below. 🎉 Before you run the script, you need to copy the events that you'd like to process from the `mdl_logstore_standard_log` into a new table called `mdl_logstore_subset_log`, the script will then process each event in that new table. +Hey there 👋 so you want to process some events from the past 🕓, probably a time when this plugin wasn't installed on your Moodle. That's awesome and we really want to help with that. Unfortunately, we've [not built this into the plugin natively yet](https://github.com/xAPI-vle/moodle-logstore_xapi/issues/42), but we do have a recommended process for inserting these events. -```php - 0, - "increment" => $increment, - "loop" => 0 -); -$sourceTable = "mdl_logstore_subset_log"; -$destinationTable = "mdl_logstore_xapi_log"; -$DEBUGGING = TRUE; -$host = 'localhost'; -$user = 'yourMYSQLusername'; -$password = 'yourMYSQLpassword'; -$db = 'moodleDatabase'; -if($DEBUGGING){ -?> - - -
- - - - - - - - - - - - - -New users of xAPI, who have just installed the Moodle Logstore xAPI plugin are faced with the problem of extracting old data and converting it to xAPI statements in the learning record store.
-This script is designed to take existing log data from a moodle installation, and import it — via the Logstore xAPI Moodle plugin — to the learning record store.
-It does this by paging the logstore_standard_log, transferring the records to a temporary database table (of the same structure) and running export commands on the data stored there. This is what it does normally, except the logstore_standard_log is only parsed for the last n records, where n is set in the settngs.
-# in directory admin/tool/task/cli/ - -php schedule_task.php --execute=\\logstore_xapi\\task\\emit_task - -php schedule_task.php --execute=\\logstore_legacy\\task\\cleanup_task - -php schedule_task.php --execute=\\logstore_standard\\task\\cleanup_task --
The data is also logged to a file called. This file is overwritten with the data from each loop and is never very long. It is also stored as JSON, which struck me as a good idea at the time.
-increment | |
---|---|
lastValue | |
moodlepath | |
logfile | |
Source DB Table (normally mdl_logstore_standard_log) | |
Source DB Table (normally mdl_logstore_xapi_log) | |
Debug | TRUE |
Author | David Kane, dkane@wit.ie, Nov 2016 |
Iteration (count) | -SQL Query | -Affected Rows | -Last Insert ID | -Task Outputs | -$i of $count | "; - } - $conn = new mysqli($host, $user, $password, $db); - if ($conn->connect_error) { - trigger_error('Database connection failed: ' . $conn->connect_error, E_USER_ERROR); - } - $sql = "insert into mdl_logstore_xapi_log (select * from mdl_logstore_subset_log where id > " . $lastValue . " order by id limit " . $increment . ");"; - if($DEBUGGING){echo "\t\t\t\t$sql | \n";} - - if($conn->query($sql) === false) { - trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR); - break; - } else { - $lastValue = $conn->insert_id; - $affected_rows = $conn->affected_rows; - $output["lastValue"] = $lastValue; - $output["loop"] = $i; - if($DEBUGGING){ - echo "\t\t$affected_rows | \n"; - print "\t\t$lastValue | \n"; - } - //echo "executing commands"; - exec("php ".$moodlepath."admin/tool/task/cli/schedule_task.php --execute=\\\\logstore_xapi\\\\task\\\\emit_task ", $output["emit"]); - exec("php ".$moodlepath."admin/tool/task/cli/schedule_task.php --execute=\\\\logstore_legacy\\\\task\\\\cleanup_task", $output["cleanupLegacy"]); - exec("php ".$moodlepath."admin/tool/task/cli/schedule_task.php --execute=\\\\logstore_standard\\\\task\\\\cleanup_task", $output["cleanupStandard"]); - if($DEBUGGING){ - // PRINT OUT THE VARIABLES, IF DEBUGGING - echo "";
- foreach ($output["emit"] as $key => $value) {
- echo "$value "; - } - echo ""; - foreach ($output["cleanupLegacy"] as $key => $value) { - echo "$value "; - } - echo ""; - foreach ($output["cleanupStandard"] as $key => $value) { - echo "$value "; - } - echo " | ";
- }
- unset($output["emit"]);
- unset($output["cleanupLegacy"]);
- unset($output["cleanupStandard"]);
-
- $log = fopen($logfile, 'w');
- fwrite($log, json_encode($output));
- fwrite($log, "\n");
- fclose($log);
-
- if($affected_rows < $increment){
- // no more rows left - time to leave the loop.
- if($DEBUGGING){echo "\t\n\t
---|---|---|---|---|
Breaking out of loop at \$count = $i. | \n\t