Skip to content

Commit 6126661

Browse files
committed
feat(form): version check of file on import
allows import of files without version data, at own risk of the admin Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 0e78cf6 commit 6126661

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

front/export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
}
3939

4040
$form = new PluginFormcreatorForm;
41-
$export_array = ['forms' => []];
41+
$export_array = ['schema_version' => PLUGIN_FORMCREATOR_SCHEMA_VERSION, 'forms' => []];
4242
foreach ($_GET['plugin_formcreator_forms_id'] as $id) {
4343
$form->getFromDB($id);
4444
$export_array['forms'][] = $form->export();

inc/form.class.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,17 +1842,31 @@ public function importJson($params = []) {
18421842
// parse json file(s)
18431843
foreach ($params['_json_file'] as $filename) {
18441844
if (!$json = file_get_contents(GLPI_TMP_DIR."/".$filename)) {
1845-
Session::addMessageAfterRedirect(__("Forms import impossible, the file is empty"));
1845+
Session::addMessageAfterRedirect(__("Forms import impossible, the file is empty", 'formcreator'));
18461846
continue;
18471847
}
18481848
if (!$forms_toimport = json_decode($json, true)) {
1849-
Session::addMessageAfterRedirect(__("Forms import impossible, the file seems corrupt"));
1849+
Session::addMessageAfterRedirect(__("Forms import impossible, the file seems corrupt", 'formcreator'));
18501850
continue;
18511851
}
18521852
if (!isset($forms_toimport['forms'])) {
1853-
Session::addMessageAfterRedirect(__("Forms import impossible, the file seems corrupt"));
1853+
Session::addMessageAfterRedirect(__("Forms import impossible, the file seems corrupt", 'formcreator'));
18541854
continue;
18551855
}
1856+
if (isset($forms_toimport['schema_version'])) {
1857+
if (($forms_toimport['schema_version']) != PLUGIN_FORMCREATOR_SCHEMA_VERSION) {
1858+
Session::addMessageAfterRedirect(
1859+
__("Forms import impossible, the file was generated with another version", 'formcreator'),
1860+
false, ERROR
1861+
);
1862+
continue;
1863+
}
1864+
} else {
1865+
Session::addMessageAfterRedirect(
1866+
__("The file does not specifies the schema version. It was probably generated with a version older than 2.10 and import is expected to create incomplete or buggy forms.", 'formcreator'),
1867+
false, WARNING
1868+
);
1869+
}
18561870

18571871
$success = true;
18581872
foreach ($forms_toimport['forms'] as $form) {

0 commit comments

Comments
 (0)