Skip to content

N°9553 upload localised structural data#917

Merged
v-dumas merged 5 commits into
developfrom
feature/9553-upload-localised-structural-data
May 27, 2026
Merged

N°9553 upload localised structural data#917
v-dumas merged 5 commits into
developfrom
feature/9553-upload-localised-structural-data

Conversation

@v-dumas
Copy link
Copy Markdown
Contributor

@v-dumas v-dumas commented May 26, 2026

Base information

Question Answer
Related to a Combodo ticket? N°9553
Type of change? Enhancement

Symptom (bug) / Objective (enhancement)

Add localized structural data for

  • Contact Types
  • Document Types
  • Contract Types

Proposed solution (bug and enhancement)

Define an helper to load the best structural data file based on the iTop default language

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have tested all changes I made on an iTop instance
  • I have added a unit test, otherwise I have explained why I couldn't
  • Is the PR clear and detailed enough so anyone can understand without digging in the code?

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 26, 2026

Greptile Summary

This PR adds localized structural data loading for several iTop modules. The main changes are:

  • Adds French and English structural XML data for contact, document, and contract types.
  • Adds a shared LoadLocalizedData helper for language-specific data files.
  • Updates module installers to load localized structural data during setup.
  • Refactors ticket data loading to use the shared helper.
  • Adds unit tests for localized file selection and helper parameter validation.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Reviews (2): Last reviewed commit: "N°9553- More tests" | Re-trigger Greptile

Comment thread setup/moduleinstaller.class.inc.php
Comment thread datamodels/2.x/itop-structure/data/fr_fr.data.itop-contacttype.xml
Comment thread datamodels/2.x/itop-structure/data/fr_fr.data.itop-documenttype.xml
Comment thread datamodels/2.x/itop-service-mgmt-provider/module.itop-service-mgmt-provider.php Outdated
Comment thread datamodels/2.x/installation.xml
@v-dumas
Copy link
Copy Markdown
Contributor Author

v-dumas commented May 27, 2026

@greptile

@v-dumas v-dumas merged commit 7c49909 into develop May 27, 2026
1 check passed
@v-dumas v-dumas deleted the feature/9553-upload-localised-structural-data branch May 27, 2026 14:32
@rquetiez rquetiez requested a review from odain-cbd May 29, 2026 07:53
$sLang = str_replace(' ', '_', strtolower($sLanguage));
$sFileName = str_replace('{{language_code}}', $sLang, $sFilePattern);
if (!file_exists($sFileName)) {
$sLang = 'en_us';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could add a SetupLog::Debug log to indicate that current default langage file is missing. as a fallback we try us_en.

Comment thread setup/moduleinstaller.class.inc.php
throw new CoreUnexpectedValue("LoadLocalizedData expects sFirstLoadingVersion to match x.y[.z][-name], got '{$sFirstLoadingVersion}'");
}

if (utils::IsNullOrEmptyString($sFilePattern)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is useless. next one is covering it as well. if file is empty no pattern {{xxx}} will be found...

}

if (substr_count($sFilePattern, '{{language_code}}') !== 1) {
throw new CoreUnexpectedValue("LoadLocalizedData expects sFilePattern to contain the exact placeholder '{{language_code}}' exactly once");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add $sFilePattern in Exception message. or at least in its context to ease support

}
}

private static function IsValidLocalizedDataVersion(string $sVersion): bool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no test covering this method. it could be nice to document what is ok. what is not.

/**
* @throws \CoreUnexpectedValue
*/
private static function AssertLoadLocalizedDataParametersAreValid(string $sPreviousVersion, string $sCurrentVersion, string $sFirstLoadingVersion, string $sFilePattern): void
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no test covering this method

$this->AssertOrganizationCountByName($sOrgName, 'en_us', 1);
}

public function LoadLocalizedData_ValidVersionFormatsProvider(): array
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this provider to test IsValidLocalizedDataVersion. and keep only one current version to cover LoadLocalizedData

Comment on lines +415 to +416
* @throws \ConfigException
* @throws \CoreException
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure these exceptions are thrown


/**
* @param array|string $sFileName
* @param \XMLDataLoader $oDataLoader
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont see this parameter anywhere

Comment on lines +338 to +343
if (utils::IsNullOrEmptyString($sPreviousVersion)) {
// Fresh install
$sDefaultLanguage = $oConfiguration->GetDefaultLanguage();
} else {
// Upgrade
$sDefaultLanguage = utils::GetConfig(true)->GetDefaultLanguage();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any idea why we use directly provided $oConfiguration when fresh install. and we use utils::GetConfig(true) otherwise? it does not seem to make sense to me.

&& version_compare($sPreviousVersion, $sFirstLoadingVersion, '<'))) {

// Note: There is an issue when upgrading, default language cannot be retrieved from the passed configuration, we have to read it from the disk
if (utils::IsNullOrEmptyString($sPreviousVersion)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

($sPreviousVersion === '') is enough. as $sPreviousVersion cannot be null (in method signature it would be ?string otherwise)

Copy link
Copy Markdown
Contributor

@odain-cbd odain-cbd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hope it is not too late for this review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Work made by Combodo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants