Statements Import


Introduction

TRAX LRS provides a convenient feature which lets you import existing statements into your LRS. The import process may be a very long task so this feature is accessible only from command line.

Configuration

The default settings of the import feature can be changed in the .env file.

File Path

The location of the file to import, which must be accessible from your application with reading permissions.

IMPORTER_FILE_PATH="C:\wamp64\www\elastic\xapi_statements.json"

Pseudonymization

If the statements to import have not been pseudonymized yet, you can do it during the import process.

IMPORTER_PSEUDONIMIZE=false

Batch Size

The number of statements imported at the same time. Usually, 100 is a good setting. Lower values may result in a slower process. Higher values may result in memory issues.

IMPORTER_BATCH_SIZE=100

Authority

The authority that will be assigned to the imported statements.

IMPORTER_AUTHORITY_NAME=authority
IMPORTER_AUTHORITY_HOMEPAGE=http://traxlrs.com

File Format

Basic format

A text file with 1 statement per line. The \n line return code must be used.

{"actor":{"mbox":"mailto:agent1@traxlrs.com"},"verb":{"id":"http://adlnet.gov/expapi/verbs/completed"},"object":{"id":"https://traxlrs.com/course01"}}
{"actor":{"mbox":"mailto:agent2@traxlrs.com"},"verb":{"id":"http://adlnet.gov/expapi/verbs/completed"},"object":{"id":"https://traxlrs.com/course02"}}

Elasticsearch friendly

A text file with 1 statement per line, embedded in the _source property of a JSON object (there may be other properties). The \n line return code must be used.

{"_source":{"actor":{"mbox":"mailto:agent1@traxlrs.com"},"verb":{"id":"http://adlnet.gov/expapi/verbs/completed"},"object":{"id":"https://traxlrs.com/course01"}}}
{"_source":{"actor":{"mbox":"mailto:agent2@traxlrs.com"},"verb":{"id":"http://adlnet.gov/expapi/verbs/completed"},"object":{"id":"https://traxlrs.com/course02"}}}

JSON friendly

One of the previous option, with [ and ] at the begining and end of the file, and a , at the end of each line, in order to make this file JSON compliant.

[
{"actor":{"mbox":"mailto:agent1@traxlrs.com"},"verb":{"id":"http://adlnet.gov/expapi/verbs/completed"},"object":{"id":"https://traxlrs.com/course01"}},
{"actor":{"mbox":"mailto:agent2@traxlrs.com"},"verb":{"id":"http://adlnet.gov/expapi/verbs/completed"},"object":{"id":"https://traxlrs.com/course02"}},
]

Commands

Before using these commands, you must create a store in your LRS.

Import statements

php artisan statements:import

The following parameters are optional. When not provided in the command line, some of them will be asked.

Option Example of value Description
--file "/path/to/file" Path of the file to import
--batch 50 The batch size
--owner 1 Internal ID of the LRS store
--entity 1 Internal ID of an LRS entity
--pseudo Pseudonymize statements
--noprompt Don't ask options (take defaults)
--restart Restart from the 1st statement

For example, the following command line could be used to import and pseudonymize statements:

php artisan statements:import --file="/statements.json" --pseudo

Display last import status

php artisan statements:import-status

When not provided in the command line, the following option will be asked.

Option Example of value Description
--owner 1 Internal ID of the LRS store

Resuming

When an import fails or is interrupted, you can resume it where it stopped. Relaunch the command and it will ask you if you want to resume or restart.

When the --noprompt option is used, it always tries to resume, except when the --restart option is used together.

{warning} Be aware that you can't import a statement with a given ID twice. The LRS detects a conflict and throws an error. So if you want to restart the import of a file with IDs, be sure to remove the previously imported statements first.