Files
iTop/tests/php-unit-tests/unitary-tests/setup/modulediscovery/resources/module.itop-tickets.php
odain-cbd 15103dc49f N°4789 - Parse datamodel module.xxx.php files instead of interpreting them (#746)
* N°4789 - Parse datamodel module.xxx.php files instead of interpreting them - refactoring all in a dedicated service first

* N°4789 - fix broken setup + tests

* N°4789 - replace legacy eval by module file parsing

* N°4789 - handle constants and if conditional structures

* N°4789 - compute boolean expressions

* N°4789 - make autoselect and dependencies work as well

* cleanup

* N°4789 - fix BeforeWritingConfig calls during setup

* N°4789 - refactor and split in ModuleDiscoveryEvaluationService + handle ModuleInstallerAPI methods calls during setup

* N°4789 - PR review changes with Romain

* PR review + code cleanup + added usecases and test cover

* temp evaluation work

* replace eval by iTop custom evaluation classes

* move PhpParser/Evaluation classes in a specific namespave + composer dumpautoload

* fix broken setup

* fix broken setup

* complete Evaluators list + autoload

* cleanup useless testing resources

* cleanup + replace last eval call in VariableEvaluator

* fix few Evaluators code

* enhance nikic evaluators + test with/without nikic lib

* Evaluator fixes/enhancements + tests

* bump to nikic fork temporarly

* bump nikic-parser fork + use only nikic fork  evaluation + cleanup itop redondant evaluators

* review with Romain: use distinct whitelists in setup time/runtime + move ModuleFileParser internal logic into ModuleFileReader

* PhpExpressionEvaluator used via constructor and not as a service

* dumpautoload again after rebase
2025-09-09 17:54:18 +02:00

108 lines
2.8 KiB
PHP

<?php
SetupWebPage::AddModule(
__FILE__,
'itop-tickets/3.3.0',
array(
// Identification
//
'label' => 'Tickets Management',
'category' => 'business',
// Setup
//
'dependencies' => array(
'itop-structure/2.7.1',
),
'mandatory' => false,
'visible' => true,
'installer' => 'TicketsInstaller',
// Components
//
'datamodel' => array(
'main.itop-tickets.php',
),
'data.struct' => array(
// 'data.struct.ta-actions.xml',
),
'data.sample' => array(
),
// Documentation
//
'doc.manual_setup' => '',
'doc.more_information' => '',
// Default settings
//
'settings' => array(
),
)
);
// Module installation handler
//
class TicketsInstaller extends ModuleInstallerAPI
{
public static function AfterDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
{
// Delete all Triggers corresponding to a no more valid class
CMDBObject::SetTrackInfo('Uninstallation');
$oSearch = new DBObjectSearch('TriggerOnObject');
$oSet = new DBObjectSet($oSearch);
while($oTrigger = $oSet->Fetch())
{
try
{
if (!MetaModel::IsValidClass($oTrigger->Get('target_class')))
{
$oTrigger->DBDelete();
}
}
catch(Exception $e)
{
utils::EnrichRaisedException($oTrigger, $e);
}
}
// It's not very clear if it make sense to test a particular version,
// as the loading mechanism checks object existence using reconc_keys
// and do not recreate them, nor update existing.
// Without test, new entries added to the data files, would be automatically loaded
if (($sPreviousVersion === '') ||
(version_compare($sPreviousVersion, $sCurrentVersion, '<')
&& version_compare($sPreviousVersion, '3.0.0', '<'))) {
$oDataLoader = new XMLDataLoader();
CMDBObject::SetTrackInfo("Initialization TicketsInstaller");
$oMyChange = CMDBObject::GetCurrentChange();
$sLang = null;
// - Try to get app. language from configuration fil (app. upgrade)
$sConfigFileName = APPCONF.'production/'.ITOP_CONFIG_FILE;
if (file_exists($sConfigFileName)) {
$oFileConfig = new Config($sConfigFileName);
if (is_object($oFileConfig)) {
$sLang = str_replace(' ', '_', strtolower($oFileConfig->GetDefaultLanguage()));
}
}
// - I still no language, get the default one
if (null === $sLang) {
$sLang = str_replace(' ', '_', strtolower($oConfiguration->GetDefaultLanguage()));
}
$sFileName = dirname(__FILE__)."/data/{$sLang}.data.itop-tickets.xml";
SetupLog::Info("Searching file: $sFileName");
if (!file_exists($sFileName)) {
$sFileName = dirname(__FILE__)."/data/en_us.data.itop-tickets.xml";
}
SetupLog::Info("Loading file: $sFileName");
$oDataLoader->StartSession($oMyChange);
$oDataLoader->LoadFile($sFileName, false, true);
$oDataLoader->EndSession();
}
}
}