Skip to content

Issue 366 LMS Demo Data Would Not Import

Ed Mozley edited this page Nov 16, 2026 · 1 revision

πŸŽ“ #366 The LMS demo data would not import

GitHub #366, reported by @UncleJS Β· LMS, demo data Β· since portal learners were added to the LMS, fixed in 5.4.1 (#2984)

What you saw

System β†’ Demo data, import LMS:

The Lms demo data could not be added: a record in lms_progress ("analyst-0-1") already exists and is not marked as demo data, so the importer will not touch it. Nothing has been changed.

On a fresh install there was no such record - the message was wrong too.

What was wrong

When the LMS gained portal learners, a course's progress stopped being keyed by analyst and became keyed by learner: learner_type (analyst or portal user) and learner_id. analyst_id stayed only as a legacy column, kept in step for analysts. The unique key is the new pair plus the course:

-- includes/db_verify_indexes.php (from database/freeitsm.sql)
UNIQUE KEY uq_lp_learner_course (learner_type, learner_id, course_id)

The demo file was never updated. Its four progress rows set only analyst_id:

{ "analyst_id": "@analysts.jsmith", "course_id": "@lms_courses.sec", ... }

so each took the schema defaults - learner_type = 'analyst', learner_id = 0 - and three of them were for the same course: the second hit ('analyst', 0, course) again and the import stopped. Even without that, the progress would have belonged to learner 0 - nobody - and the Progress screen, which reads the learner, would not have shown it.

The message was the second fault. The import explains a duplicate by assuming the clashing record was already in your database and not marked as demo data. Here it had been written seconds earlier by the same import.

Was it more than one place? Only this file used the old key. A new check (below) looks at every demo module's rows against every unique key, and found nothing else.

The fix

1. The data. Each progress row names its learner, as @UncleJS proposed; analyst_id stays, because the schema still keeps it in step for analysts:

"analyst_id": "@analysts.jsmith",
"learner_type": "analyst",
"learner_id": "@analysts.jsmith",

2. The message. demoDuplicateIsOwnData() (includes/demo_data.php) takes the key name and value from the database's error, looks up the key's columns, and checks for a row this import has just written (marked is_demo = 1) with that value. If there is one, the import says so:

The Lms demo data could not be added: two of its own records clash in lms_progress ("analyst-0-5"). That is a fault in FreeITSM's demo data, not in your data - please report it. Nothing has been changed.

Anything it cannot be sure of keeps the older wording.

3. A guard. tests/demo-data-ownership.php (static, no database) now fills each demo row's missing columns with their schema defaults and checks that no two rows in a module clash on any of the table's unique keys. A NULL never clashes (a unique key allows repeated NULLs) and a __GENERATE__ token becomes a fresh value per row.

πŸ“ Files

File Change
βšͺ database/demo-data/lms.json learner_type / learner_id on the four progress rows
🟣 includes/demo_data.php demoDuplicateIsOwnData(), used by demoDuplicateExplanation()
🟒 tests/demo-data-ownership.php The unique-key check across every demo module

How it was verified

Reproduced first, on a test install through the real import endpoint: a record in lms_progress ("analyst-0-1") already exists, nothing imported. After the fix the module imports (36 rows, 4 of them progress), each progress row belongs to its analyst, and LMS β†’ Progress shows Administrator passed, James Smith failed, Sarah Williams incomplete and Michael Jones completed. With the old file put back, the import now gives the new, accurate message, and rolls back as before.

tests/demo-data-ownership.php: 233 passed. Control: on the old file it fails on lms_progress, naming the clash (analyst, 0, @lms_courses.sec).

What this means for you

Update to 5.4.1 and the LMS demo data imports. Nothing changes for your own LMS data.

For developers: a demo row must give every column of a unique key that it means to be distinct - a column left out takes its schema default, and two rows on the same default clash. When a key changes (as uq_lp_learner_course did), update the demo JSON in the same commit; tests/demo-data-ownership.php fails until you do.

Related: Demo data Β· LMS

FreeITSM

Getting Started

Modules

Multi-tenancy (planned)

Responses to feedback

Blue sky thinking

Bugs resolved

Pull requests

Links

Clone this wiki locally