diff --git a/.make/release/update.classes.inc.php b/.make/release/update.classes.inc.php index 8f1499439..5b67edad3 100644 --- a/.make/release/update.classes.inc.php +++ b/.make/release/update.classes.inc.php @@ -199,7 +199,7 @@ class DatamodelsXmlFiles extends AbstractGlobFileVersionUpdater libxml_clear_errors(); $oFileXml->formatOutput = true; $oFileXml->preserveWhiteSpace = false; - $oFileXml->loadXML($sFileContent); + $oFileXml->loadXML($sFileContent, LIBXML_BIGLINES); $oFileItopFormat = new iTopDesignFormat($oFileXml); diff --git a/application/forms.class.inc.php b/application/forms.class.inc.php index 4cac5ea9c..a41317865 100644 --- a/application/forms.class.inc.php +++ b/application/forms.class.inc.php @@ -319,6 +319,7 @@ EOF if ($sIntroduction != null) { $oPage->add('
'.$sIntroduction.'
'); } + $oPage->add('
'); $this->Render($oPage); $oPage->add(''); diff --git a/core/cmdbsource.class.inc.php b/core/cmdbsource.class.inc.php index c911d766e..4ea759ae9 100644 --- a/core/cmdbsource.class.inc.php +++ b/core/cmdbsource.class.inc.php @@ -597,12 +597,12 @@ class CMDBSource $oResult = DbConnectionWrapper::GetDbConnection(true)->query($sSql); } catch (mysqli_sql_exception $e) { self::LogDeadLock($e, true); - throw new MySQLException('Failed to issue SQL query', ['query' => $sSql, $e]); + throw new MySQLException('Failed to issue SQL query', ['query' => $sSql, $e, 'stack' => $e->getTraceAsString()]); } finally { $oKPI->ComputeStats('Query exec (mySQL)', $sSql); } if ($oResult === false) { - $aContext = ['query' => $sSql]; + $aContext = ["\nstack" => (new Exception(''))->getTraceAsString(), "\nquery" => $sSql]; $iMySqlErrorNo = DbConnectionWrapper::GetDbConnection(true)->errno; $aMySqlHasGoneAwayErrorCodes = MySQLHasGoneAwayException::getErrorCodes(); diff --git a/core/designdocument.class.inc.php b/core/designdocument.class.inc.php index 91318090a..3ff14e32f 100644 --- a/core/designdocument.class.inc.php +++ b/core/designdocument.class.inc.php @@ -70,6 +70,11 @@ class DesignDocument extends DOMDocument $this->preserveWhiteSpace = true; // otherwise the formatOutput option would have no effect } + public function loadXML(string $source, int $options = 0) + { + return parent::loadXML($source, $options | LIBXML_BIGLINES); + } + /** * Overload of the standard API * diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 8725bbe2f..1f75ae980 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -6193,12 +6193,14 @@ abstract class MetaModel if ($bMustBeFound && empty($aRow)) { $sNotFoundErrorMessage = "No result for the single row query"; - IssueLog::Info($sNotFoundErrorMessage, LogChannels::CMDB_SOURCE, [ + $e = new CoreException($sNotFoundErrorMessage); + IssueLog::Error($sNotFoundErrorMessage, LogChannels::CMDB_SOURCE, [ 'class' => $sClass, 'key' => $iKey, 'sql_query' => $sSQL, + 'stack' => $e->getTraceAsString(), ]); - throw new CoreException($sNotFoundErrorMessage); + throw $e; } return $aRow; diff --git a/js/links/links_widget.js b/js/links/links_widget.js index eaffcae21..1dbdde0fd 100644 --- a/js/links/links_widget.js +++ b/js/links/links_widget.js @@ -390,16 +390,17 @@ function LinksWidget(id, sClass, sAttCode, iInputId, sSuffix, bDuplicates, oWizH this.RegisterChange = function () { // Listen only used inputs - $('#linkedset_'+me.id+' :input[name^="attr_'+me.sAttCode+'["]').off('change').on('change', function () { + $('body').off('change', '#linkedset_'+me.id+' :input[name^="attr_'+me.sAttCode+'["]') + .on('change', '#linkedset_'+me.id+' :input[name^="attr_'+me.sAttCode+'["]', function () { if (!($(this).hasClass('selection'))) - { - let oCheckbox = $(this).closest('tr').find('.selection'); - let iLink = oCheckbox.attr('data-link-id'); - let iUniqueId = oCheckbox.attr('data-unique-id'); - let sAttCode = $(this).closest('.attribute-edit').attr('data-attcode'); - let value = $(this).val();; - return me.OnValueChange(iLink, iUniqueId, sAttCode, value, this); - } + { + let oCheckbox = $(this).closest('tr').find('.selection'); + let iLink = oCheckbox.attr('data-link-id'); + let iUniqueId = oCheckbox.attr('data-unique-id'); + let sAttCode = $(this).closest('.attribute-edit').attr('data-attcode'); + let value = $(this).val();; + return me.OnValueChange(iLink, iUniqueId, sAttCode, value, this); + } return true; }); }; diff --git a/js/property_field.js b/js/property_field.js index 59ea62c68..ac363bfcf 100644 --- a/js/property_field.js +++ b/js/property_field.js @@ -548,6 +548,7 @@ function ValidateWithPattern(sFieldId, bMandatory, sPattern, sFormId, aForbidden if (sMessage) { $('#'+sFieldId).attr('data-tooltip-content', sMessage); + $('#'+sFieldId).attr('data-tooltip-theme', 'error'); CombodoTooltip.InitTooltipFromMarkup($('#'+sFieldId), true); $('#'+sFieldId)[0]._tippy.show(); } diff --git a/setup/modelfactory.class.inc.php b/setup/modelfactory.class.inc.php index dea6a2f1b..d43f0c6a3 100644 --- a/setup/modelfactory.class.inc.php +++ b/setup/modelfactory.class.inc.php @@ -70,14 +70,37 @@ class MFException extends Exception * MFException constructor. * * @inheritDoc + * + * @param $message + * @param $code: error code + * @param $oNode: dom node + * @param $sXPath: XML xpath: if provided used in exception message. otherwise computed via $oNode + * @param $sExtraInfo: additional information stored in exception + * @param $oParentFallbackNode: fallback dom node (usually parent). in case $oNode XML line is wrong (set to 0), line number computed/displayed in error message comes from $oParentFallbackNode */ - public function __construct($message = null, $code = 0, $iSourceLineNumber = 0, $sXPath = '', $sExtraInfo = '', $previous = null) + public function __construct($message = null, $code = 0, $oNode, $sXPath = null, $sExtraInfo = '', $oParentFallbackNode = null) { - parent::__construct($message, $code, $previous); + $iSourceLineNumber = ModelFactory::GetXMLLineNumber($oNode); + if ($iSourceLineNumber==0 && ! is_null($oParentFallbackNode)){ + $iSourceLineNumber = ModelFactory::GetXMLLineNumber($oParentFallbackNode); + } + + if (is_null($sXPath)){ + $sXPath = DesignDocument::GetItopNodePath($oNode); + } + $this->iSourceLineNumber = $iSourceLineNumber; $this->iSourceLineOffset = 0; $this->sXPath = $sXPath; $this->sExtraInfo = $sExtraInfo; + parent::__construct("$sXPath at line $iSourceLineNumber: $message", $code); + + $aContext = [ + 'error' => $code, + 'stack' => $this->getTraceAsString(), + 'extra_info' => $sExtraInfo, + ]; + \IssueLog::Error($this->getMessage(), null, $aContext); } /** @@ -196,6 +219,10 @@ class MFModule return; } + if (!is_dir($sRootDir)) { + $sRootDir = APPROOT.$sRootDir; + } + // Scan the module's root directory to find the datamodel(*).xml files if ($hDir = opendir($sRootDir)) { // This is the correct way to loop over the directory. (according to the documentation) @@ -735,14 +762,7 @@ class ModelFactory case 'define_if_not_exists': /** @var \MFElement $oParentNode */ $oParentNode = $oSubClassNode->parentNode; - $iLine = ModelFactory::GetXMLLineNumber($oParentNode); - $sItopNodePath = DesignDocument::GetItopNodePath($oParentNode); - throw new MFException( - "$sItopNodePath at line $iLine: _delta=\"$sParentDeltaSpec\" not supported for classes in hierarchy", - MFException::NOT_FOUND, - $iLine, - $sItopNodePath - ); + throw new MFException("_delta=\"$sParentDeltaSpec\" not supported for classes in hierarchy", MFException::NOT_FOUND, $oParentNode); } } @@ -798,14 +818,7 @@ class ModelFactory // Move class after new parent class (before its next sibling) $oNodeForTargetParent = $oTargetDocument->GetNodes("/itop_design/classes/class[@id=\"$sParentClassName\"]")->item(0); if (is_null($oNodeForTargetParent)) { - $iLine = ModelFactory::GetXMLLineNumber($oSourceParentClassNode); - $sItopNodePath = DesignDocument::GetItopNodePath($oSourceParentClassNode); - throw new MFException( - $sItopNodePath." at line $iLine: invalid parent class '$sParentClassName'", - MFException::NOT_FOUND, - $iLine, - $sItopNodePath - ); + throw new MFException("invalid parent class '$sParentClassName'", MFException::NOT_FOUND, $oSourceParentClassNode); } $oNextParentSibling = $oNodeForTargetParent->nextSibling; if ($oNextParentSibling) { @@ -833,29 +846,14 @@ class ModelFactory if (!$oTargetNode || $oTargetNode->IsRemoved()) { // The node does not exist or is marked as removed if ($bMustExist) { - $iLine = ModelFactory::GetXMLLineNumber($oSourceNode); - $sItopNodePath = DesignDocument::GetItopNodePath($oSourceNode); - throw new MFException( - $sItopNodePath.' at line '.$iLine.': could not be found or marked as removed', - MFException::NOT_FOUND, - $iLine, - $sItopNodePath - ); + throw new MFException("could not be found or marked as removed", MFException::NOT_FOUND, $oSourceNode); } if ($bIfExists) { // Do not continue deeper $oTargetNode = null; } else { if (!$bSpecifiedMerge && $sMode === self::LOAD_DELTA_MODE_STRICT && ($sSearchId !== '' || is_null($oSourceNode->GetFirstElementChild()))) { - $iLine = ModelFactory::GetXMLLineNumber($oSourceNode); - $sItopNodePath = DesignDocument::GetItopNodePath($oSourceNode); - throw new MFException( - $sItopNodePath.' at line '.$iLine.': could not be found or marked as removed (strict mode)', - MFException::NOT_FOUND, - $iLine, - $sItopNodePath, - 'strict mode' - ); + throw new MFException("could not be found or marked as removed (strict mode)", MFException::NOT_FOUND, $oSourceNode, null, 'strict mode'); } // Ignore renaming non-existant node @@ -904,15 +902,7 @@ class ModelFactory if (is_null($oSourceNode->GetFirstElementChild()) && $oTargetParentNode instanceof MFElement) { // Leaf node if ($sMode === self::LOAD_DELTA_MODE_STRICT && !$oSourceNode->hasAttribute('_rename_from') && trim($oSourceNode->GetText('')) !== '') { - $iLine = ModelFactory::GetXMLLineNumber($oSourceNode); - $sItopNodePath = DesignDocument::GetItopNodePath($oSourceNode); - throw new MFException( - $sItopNodePath.' at line '.$iLine.': cannot be modified without _delta flag (strict mode)', - MFException::AMBIGUOUS_LEAF, - $iLine, - $sItopNodePath, - 'strict mode' - ); + throw new MFException("cannot be modified without _delta flag (strict mode)", MFException::AMBIGUOUS_LEAF, $oSourceNode, null, 'strict mode'); } else { // Lax mode: same as redefine // Replace the existing node by the given node - copy child nodes as well @@ -920,7 +910,7 @@ class ModelFactory if (trim($oSourceNode->GetText('')) !== '') { $oTargetNode = $oTargetDocument->importNode($oSourceNode, true); $sSearchId = $oSourceNode->hasAttribute('_rename_from') ? $oSourceNode->getAttribute('_rename_from') : $oSourceNode->getAttribute('id'); - $oTargetParentNode->RedefineChildNode($oTargetNode, $sSearchId); + $oTargetParentNode->RedefineChildNode($oTargetNode, $sSearchId, $oSourceNode); } } } else { @@ -964,7 +954,7 @@ class ModelFactory // Replace the existing node by the given node - copy child nodes as well /** @var \MFElement $oTargetNode */ $oTargetNode = $oTargetDocument->importNode($oSourceNode, true); - $oTargetParentNode->RedefineChildNode($oTargetNode, $sSearchId); + $oTargetParentNode->RedefineChildNode($oTargetNode, $sSearchId, $oSourceNode); break; case 'delete_if_exists': @@ -984,38 +974,18 @@ class ModelFactory case 'delete': /** @var \MFElement $oTargetNode */ $oTargetNode = $oTargetParentNode->_FindChildNode($oSourceNode, $sSearchId); - $sPath = MFDocument::GetItopNodePath($oSourceNode); - $iLine = $this->GetXMLLineNumber($oSourceNode); if ($oTargetNode == null) { - throw new MFException( - $sPath.' at line '.$iLine.": could not be deleted (not found)", - MFException::COULD_NOT_BE_DELETED, - $iLine, - $sPath - ); + throw new MFException("could not be deleted (not found)", MFException::COULD_NOT_BE_DELETED, $oSourceNode); } if ($oTargetNode->IsRemoved()) { - throw new MFException( - $sPath.' at line '.$iLine.": could not be deleted (already marked as deleted)", - MFException::ALREADY_DELETED, - $iLine, - $sPath - ); + throw new MFException("could not be deleted (already marked as deleted)", MFException::ALREADY_DELETED, $oSourceNode); } $oTargetNode->Delete(); break; default: - $sPath = MFDocument::GetItopNodePath($oSourceNode); - $iLine = $this->GetXMLLineNumber($oSourceNode); - throw new MFException( - $sPath.' at line '.$iLine.": unexpected value for attribute _delta: '".$sDeltaSpec."'", - MFException::INVALID_DELTA, - $iLine, - $sPath, - $sDeltaSpec - ); + throw new MFException("unexpected value for attribute _delta: '".$sDeltaSpec."'", MFException::INVALID_DELTA, $oSourceNode, null, $sDeltaSpec); } if ($oTargetNode && $oTargetNode->parentNode) { @@ -2139,14 +2109,12 @@ class MFElement extends Combodo\iTop\DesignElement $oExisting = $this->_FindChildNode($oNode); if ($oExisting) { if (!$oExisting->IsRemoved()) { - $sPath = MFDocument::GetItopNodePath($oNode); - $iLine = ModelFactory::GetXMLLineNumber($oNode); $sExistingPath = MFDocument::GetItopNodePath($oExisting).' created_in: ['.$oExisting->getAttribute('_created_in').']'; $iExistingLine = ModelFactory::GetXMLLineNumber($oExisting); $sExceptionMessage = <<ReplaceWithSingleNode($oNode); $sFlag = 'replaced'; @@ -2164,13 +2132,14 @@ EOF; * * @param MFElement $oNode The node (including all subnodes) to set * @param string|null $sSearchId + * @param mixed $oParentFallbackNode: provided to print accurate line number in case $oNode line is 0 * * @return void * * @throws MFException * @throws \Exception */ - public function RedefineChildNode(MFElement $oNode, $sSearchId = null) + public function RedefineChildNode(MFElement $oNode, $sSearchId = null, $oParentFallbackNode=null) { // First: cleanup any flag behind the new node, and eventually add trace data $oNode->ApplyChanges(); @@ -2179,25 +2148,13 @@ EOF; $oExisting = $this->_FindChildNode($oNode, $sSearchId); if (!$oExisting) { $sPath = MFDocument::GetItopNodePath($this)."/".$oNode->tagName.(empty($sSearchId) ? '' : "[$sSearchId]"); - $iLine = ModelFactory::GetXMLLineNumber($oNode); - throw new MFException( - $sPath." at line $iLine: could not be modified (not found)", - MFException::COULD_NOT_BE_MODIFIED_NOT_FOUND, - $sPath, - $iLine - ); + throw new MFException('could not be modified (not found)', MFException::COULD_NOT_BE_MODIFIED_NOT_FOUND, $oNode, $sPath, $oParentFallbackNode); } $sPrevFlag = $oExisting->GetAlteration(); $sOldId = $oExisting->getAttribute('_old_id'); if ($oExisting->IsRemoved()) { $sPath = MFDocument::GetItopNodePath($this)."/".$oNode->tagName.(empty($sSearchId) ? '' : "[$sSearchId]"); - $iLine = ModelFactory::GetXMLLineNumber($oNode); - throw new MFException( - $sPath." at line $iLine: could not be modified (marked as deleted)", - MFException::COULD_NOT_BE_MODIFIED_ALREADY_DELETED, - $sPath, - $iLine - ); + throw new MFException('could not be modified (marked as deleted)', MFException::COULD_NOT_BE_MODIFIED_ALREADY_DELETED, $oNode, $sPath, $oParentFallbackNode); } $oExisting->ReplaceWithSingleNode($oNode); if (!$this->IsInDefinition()) { diff --git a/setup/modulediscovery.class.inc.php b/setup/modulediscovery.class.inc.php index a37d261db..e90ee2ca7 100644 --- a/setup/modulediscovery.class.inc.php +++ b/setup/modulediscovery.class.inc.php @@ -118,9 +118,6 @@ class ModuleDiscovery $aArgs['module_file'] = $sFilePath; list($sModuleName, $sModuleVersion) = static::GetModuleName($sId); - if ($sModuleVersion == '') { - $sModuleVersion = '1.0.0'; - } if (array_key_exists($sModuleName, self::$m_aModuleVersionByName)) { if (version_compare($sModuleVersion, self::$m_aModuleVersionByName[$sModuleName]['version'], '>')) { @@ -217,9 +214,11 @@ class ModuleDiscovery } ksort($aDependencies); $aOrderedModules = []; - $iLoopCount = 1; - while (($iLoopCount < count($aModules)) && (count($aDependencies) > 0)) { - foreach ($aDependencies as $sId => $aRemainingDeps) { + $iLoopCount = 0; + while(($iLoopCount < count($aModules)) && (count($aDependencies) > 0) ) + { + foreach($aDependencies as $sId => $aRemainingDeps) + { $bDependenciesSolved = true; foreach ($aRemainingDeps as $sDepId) { if (!self::DependencyIsResolved($sDepId, $aOrderedModules, $aSelectedModules)) { @@ -279,14 +278,10 @@ class ModuleDiscovery $bResult = false; $aModuleVersions = []; // Separate the module names from their version for an easier comparison later - foreach ($aOrderedModules as $sModuleId) { - $aMatches = []; - if (preg_match('|^([^/]+)/(.*)$|', $sModuleId, $aMatches)) { - $aModuleVersions[$aMatches[1]] = $aMatches[2]; - } else { - // No version number found, assume 1.0.0 - $aModuleVersions[$sModuleId] = '1.0.0'; - } + foreach($aOrderedModules as $sModuleId) + { + list($sModuleName, $sVersion) = self::GetModuleName($sModuleId); + $aModuleVersions[$sModuleName] = $sVersion; } if (preg_match_all('/([^\(\)&| ]+)/', $sDepString, $aMatches)) { $aReplacements = []; @@ -400,10 +395,16 @@ class ModuleDiscovery if (preg_match('!^(.*)/(.*)$!', $sModuleId, $aMatches)) { $sName = $aMatches[1]; $sVersion = $aMatches[2]; - } else { - $sName = $sModuleId; - $sVersion = ""; + if ($sVersion === ""){ + $sVersion = "1.0.0"; + } } + else + { + $sName = $sModuleId; + $sVersion = "1.0.0"; + } + return [$sName, $sVersion]; } diff --git a/sources/Application/TwigBase/Controller/Controller.php b/sources/Application/TwigBase/Controller/Controller.php index d36f6385a..6aae6adf2 100644 --- a/sources/Application/TwigBase/Controller/Controller.php +++ b/sources/Application/TwigBase/Controller/Controller.php @@ -754,7 +754,7 @@ abstract class Controller extends AbstractController { // iTop 3.1 and older compatibility, if not an URI we don't know if its relative to app root or module root if (strpos($sLinkedScript, "://") === false) { - $this->m_oPage->add_linked_script($sLinkedScript); + $this->m_oPage->LinkScriptFromAppRoot(utils::LocalPath($sLinkedScript, APPROOT)); return; } diff --git a/sources/Application/WebPage/WebPage.php b/sources/Application/WebPage/WebPage.php index a09ac4918..ed699ffcd 100644 --- a/sources/Application/WebPage/WebPage.php +++ b/sources/Application/WebPage/WebPage.php @@ -1268,19 +1268,20 @@ JS; */ protected function AddCompatibilityFiles(string $sFileType, string $sMode): void { - $sConstantName = 'COMPATIBILITY_'.strtoupper($sMode).'_LINKED_'.($sFileType === static::ENUM_COMPATIBILITY_FILE_TYPE_CSS ? 'STYLESHEETS' : 'SCRIPTS').'_REL_PATH'; - $sMethodName = 'add_linked_'.($sFileType === static::ENUM_COMPATIBILITY_FILE_TYPE_CSS ? 'stylesheet' : 'script'); + $sConstantName = 'COMPATIBILITY_'.strtoupper($sMode).'_LINKED_'. ($sFileType === static::ENUM_COMPATIBILITY_FILE_TYPE_CSS ? 'STYLESHEETS' : 'SCRIPTS') .'_REL_PATH'; + $sMethodName = 'Link'.($sFileType === static::ENUM_COMPATIBILITY_FILE_TYPE_CSS ? 'Resource' : 'Script').'FromAppRoot'; + // Add ancestors files foreach (array_reverse(class_parents(static::class)) as $sParentClass) { foreach (constant($sParentClass.'::'.$sConstantName) as $sFile) { - $this->$sMethodName(utils::GetAbsoluteUrlAppRoot().$sFile); + $this->$sMethodName($sFile); } } // Add current class files foreach (constant('static::'.$sConstantName) as $sFile) { - $this->$sMethodName(utils::GetAbsoluteUrlAppRoot().$sFile); + $this->$sMethodName($sFile); } } diff --git a/sources/Controller/Base/Layout/ObjectController.php b/sources/Controller/Base/Layout/ObjectController.php index 043633dcf..0ff57825c 100644 --- a/sources/Controller/Base/Layout/ObjectController.php +++ b/sources/Controller/Base/Layout/ObjectController.php @@ -632,6 +632,7 @@ JS; $aResult['data'] = ['error_message' => $e->getHtmlMessage()]; } else { $oPage->AddHeaderMessage($e->getHtmlMessage(), 'message_error'); + $oObj->Reload(); $oObj->DisplayModifyForm( $oPage, ['wizard_container' => true] diff --git a/sources/SessionTracker/SessionHandler.php b/sources/SessionTracker/SessionHandler.php index 5f3c31226..72244b4a7 100644 --- a/sources/SessionTracker/SessionHandler.php +++ b/sources/SessionTracker/SessionHandler.php @@ -139,15 +139,15 @@ class SessionHandler extends \SessionHandler // - Data corruption (not a json / not an array / no previous creation_time key) $iCreationTime = time(); - $aJson = []; + $aJson=[]; if (! is_null($sPreviousFileVersionContent)) { $aJson = json_decode($sPreviousFileVersionContent, true); - if (is_array($aJson)) { + if (is_array($aJson)){ if (array_key_exists('creation_time', $aJson)) { $iCreationTime = $aJson['creation_time']; } - } else { - $aJson = []; + } else { + $aJson=[]; } } @@ -155,42 +155,42 @@ class SessionHandler extends \SessionHandler 'login_mode' => Session::Get('login_mode'), 'user_id' => $sUserId, 'creation_time' => $iCreationTime, - 'context' => implode('|', ContextTag::GetStack()), + 'context' => implode('|', ContextTag::GetStack()) ]; $oiSessionHandlerExtension = $this->GetSessionHandlerExtension(); - if (! is_null($oiSessionHandlerExtension)) { + if (! is_null($oiSessionHandlerExtension)){ $oiSessionHandlerExtension->CompleteSessionData($aJson, $aData); } - return json_encode( + return json_encode ( $aData ); - } catch (Exception $e) { + } catch(Exception $e) { IssueLog::Error(__METHOD__, null, [ 'error' => $e->getMessage() ]); } return null; } - private function GetSessionHandlerExtension(): ?iSessionHandlerExtension + private function GetSessionHandlerExtension() : ?iSessionHandlerExtension { $sSessionHandlerExtensionClass = utils::GetConfig()->Get('sessions_tracking.session_handler_extension'); - if (strlen($sSessionHandlerExtensionClass) != 0) { - try { - if (! class_exists($sSessionHandlerExtensionClass)) { + if (strlen($sSessionHandlerExtensionClass) !=0){ + try{ + if (! class_exists($sSessionHandlerExtensionClass)){ throw new \Exception("Cannot find class"); } /** @var iSessionHandlerExtension $oSessionHandlerExtension */ - $oSessionHandlerExtension = new $sSessionHandlerExtensionClass(); - if ($oSessionHandlerExtension instanceof iSessionHandlerExtension) { + $oSessionHandlerExtension = new $sSessionHandlerExtensionClass; + if ($oSessionHandlerExtension instanceof iSessionHandlerExtension){ return $oSessionHandlerExtension; } throw new \Exception("Not an instance of iSessionHandlerExtension"); - } catch (\Exception $e) { - IssueLog::Error(__METHOD__.': cannot instanciate iSessionHandlerExtension', null, ['sessions_tracking.session_handler_extension' => $sSessionHandlerExtensionClass]); + } catch(\Exception $e) { + IssueLog::Error(__METHOD__ . ': cannot instanciate iSessionHandlerExtension', null, ['sessions_tracking.session_handler_extension' => $sSessionHandlerExtensionClass]); } } diff --git a/synchro/synchrodatasource.class.inc.php b/synchro/synchrodatasource.class.inc.php index 449b3742c..f67114c4b 100644 --- a/synchro/synchrodatasource.class.inc.php +++ b/synchro/synchrodatasource.class.inc.php @@ -2397,8 +2397,11 @@ class SynchroReplica extends DBObject implements iDisplay } } // Really modified ? - if ($oDestObj->IsModified()) { - $oDestObj::SetCurrentChange($oChange); + if ($oDestObj->IsModified()) + { + if(method_exists(get_class($oDestObj), "SetCurrentChange")){ + $oDestObj::SetCurrentChange($oChange); + } $oDestObj->DBUpdate(); $bModified = true; $oStatLog->AddTrace('Updated object - Values: {'.implode(', ', $aValueTrace).'}', $this); @@ -2448,7 +2451,10 @@ class SynchroReplica extends DBObject implements iDisplay $aValueTrace[] = "$sAttCode: $value"; } } - $oDestObj::SetCurrentChange($oChange); + + if(method_exists(get_class($oDestObj), "SetCurrentChange")){ + $oDestObj::SetCurrentChange($oChange); + } $iNew = $oDestObj->DBInsert(); $this->Set('dest_id', $oDestObj->GetKey()); diff --git a/tests/php-unit-tests/unitary-tests/modulediscovery/ModuleDiscoveryTest.php b/tests/php-unit-tests/unitary-tests/modulediscovery/ModuleDiscoveryTest.php new file mode 100644 index 000000000..ec573f84c --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/modulediscovery/ModuleDiscoveryTest.php @@ -0,0 +1,51 @@ + [ + 'sModuleId' => 'a/1.2.3', + 'name' => 'a', + 'version' => '1.2.3', + ], + 'develop' => [ + 'sModuleId' => 'a/1.2.3-dev', + 'name' => 'a', + 'version' => '1.2.3-dev', + ], + 'missing version => 1.0.0' => [ + 'sModuleId' => 'a/', + 'name' => 'a', + 'version' => '1.0.0', + ], + 'missing everything except name' => [ + 'sModuleId' => 'a', + 'name' => 'a', + 'version' => '1.0.0', + ], + ]; + } + + protected function setUp(): void + { + parent::setUp(); + + $this->RequireOnceItopFile('setup/modulediscovery.class.inc.php'); + } + + /** + * @dataProvider GetModuleNameProvider + */ + public function testGetModuleName($sModuleId, $expectedName, $expectedVersion) + { + $this->assertEquals([$expectedName, $expectedVersion], \ModuleDiscovery::GetModuleName($sModuleId)); + } + +} diff --git a/tests/php-unit-tests/unitary-tests/sources/SessionTracker/SessionHandlerTest.php b/tests/php-unit-tests/unitary-tests/sources/SessionTracker/SessionHandlerTest.php index a3451c8d4..44a958c45 100644 --- a/tests/php-unit-tests/unitary-tests/sources/SessionTracker/SessionHandlerTest.php +++ b/tests/php-unit-tests/unitary-tests/sources/SessionTracker/SessionHandlerTest.php @@ -325,4 +325,4 @@ class SessionHandlerTest extends ItopDataTestCase $sContent = $this->GenerateSessionContent($oSessionHandler, json_encode(null)); $this->assertNotNull($sContent, "Call to CompleteSessionData should NOT fail due to Argument #1 (\$aJson) must be of type array, null given"); } -} +} \ No newline at end of file