Admidio / admidio

Admidio is a free open source user management system for websites of organizations and groups. The system has a flexible role model so that it’s possible to reflect the structure and permissions of your organization.
https://www.admidio.org
GNU General Public License v2.0
336 stars 131 forks source link

Demo Data cannot be installed #1169

Closed kainhofer closed 2 years ago

kainhofer commented 2 years ago

Describe the bug I set up a clean instance of mysql/mariadb and apache and tried to insert the demo data via call to "http://localhost:81/demo_data/build.php?lang=en"

However, this lead to a SQL-Error:

Start installing ...
Reading file "data.sql" ...
Read file "data.sql" finished!
Executing "data.sql" SQL-Statements ...

S Q L - E R R O R

CODE: 42000

1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES (10, 'SYSTEM', 'Admidio Core', 'CORE', '4.0.7', 0, 730) ' at line 6

B A C K T R A C E

FILE: adm_program/system/classes/Database.php
LINE: 720
CALL: Database->showError()

[...]

After some debugging, it turns out that the install script replaces all %PREFIX% by DEMO, so the SQL code is

INSERT INTO %PREFIX%_components (com_id, com_type, com_name, com_name_intern, com_version, com_beta, com_update_step)
                         VALUES (10, 'SYSTEM', 'Admidio Core', 'CORE', '4.0.7', 0, 730)

On the other hand, the demo_data/build.php script does a preg_matchall on (DEMO\w*) and runs the result though $gL10n->get, i.e. it tries to translate the table name DEMO_components to either German or English.

Unfortunately, the language files do not contain translations for the tables, so the Language::get function (adm_program/system/classes/Language.php, line 122) throws an exception and wraps all untranslated strings in "#". Thus, the SQL turns into

INSERT INTO #DEMO_components# (com_id, com_type, com_name, com_name_intern, com_version, com_beta, com_update_step)
                         VALUES (10, 'SYSTEM', 'Admidio Core', 'CORE', '4.0.7', 0, 730)

Clearly, the table name should not be translated, but the demo data install script treats all strings starting with DEMO_ as translatable...

The easiest way to solve the issue is to simply add all table names to the languange files, so no exception is thrown. The other approach would be in build.php to explicitly check for all known table names and not to dall $gL10n->get on the table names...

I cannot think of a generic approach to prevent table names from being translated (or to prevent $gL10n->get from wrapping untranslated table names with #)...

Fasse commented 2 years ago

@kainhofer Could you please try to import the demo data with my current fix.