Bläddra i källkod

Automatically remove duplicated modules (by keeping only the most recent one) when loading modules, independently of the loading order.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4218 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 9 år sedan
förälder
incheckning
b1a5326d43
2 ändrade filer med 31 tillägg och 54 borttagningar
  1. 0 1
      setup/modelfactory.class.inc.php
  2. 31 53
      setup/modulediscovery.class.inc.php

+ 0 - 1
setup/modelfactory.class.inc.php

@@ -1226,7 +1226,6 @@ EOF
 	public function FindModules()
 	public function FindModules()
 	{
 	{
 		$aAvailableModules = ModuleDiscovery::GetAvailableModules($this->aRootDirs);
 		$aAvailableModules = ModuleDiscovery::GetAvailableModules($this->aRootDirs);
-		$aAvailableModules = ModuleDiscovery::RemoveDuplicateModules($aAvailableModules);
 		$aResult = array();
 		$aResult = array();
 		foreach($aAvailableModules as $sId => $aModule)
 		foreach($aAvailableModules as $sId => $aModule)
 		{
 		{

+ 31 - 53
setup/modulediscovery.class.inc.php

@@ -47,6 +47,7 @@ class ModuleDiscovery
 	// Cache the results and the source directories
 	// Cache the results and the source directories
 	protected static $m_aSearchDirs = null;
 	protected static $m_aSearchDirs = null;
 	protected static $m_aModules = array();
 	protected static $m_aModules = array();
+	protected static $m_aModuleVersionByName = array();
 
 
 	// All the entries below are list of file paths relative to the module directory
 	// All the entries below are list of file paths relative to the module directory
 	protected static $m_aFilesList = array('datamodel', 'webservice', 'dictionary', 'data.struct', 'data.sample');
 	protected static $m_aFilesList = array('datamodel', 'webservice', 'dictionary', 'data.struct', 'data.sample');
@@ -77,6 +78,31 @@ class ModuleDiscovery
 		$aArgs['root_dir'] = dirname($sFilePath);
 		$aArgs['root_dir'] = dirname($sFilePath);
 		$aArgs['module_file'] = $sFilePath;
 		$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], '>'))
+			{
+				// Newer version, let's upgrade
+				self::$m_aModuleVersionByName[$sModuleName] = $sModuleVersion;
+			}
+			else
+			{
+				// Older (or equal) version, let's ignore it
+				return;
+			}
+		}
+		else
+		{
+			// First version to be loaded for this module, remember it
+			self::$m_aModuleVersionByName[$sModuleName] = $sModuleVersion;
+		}
+		
 		self::$m_aModules[$sId] = $aArgs;
 		self::$m_aModules[$sId] = $aArgs;
 
 
 		foreach(self::$m_aFilesList as $sAttribute)
 		foreach(self::$m_aFilesList as $sAttribute)
@@ -193,62 +219,13 @@ class ModuleDiscovery
 	/**
 	/**
 	 * Remove the duplicate modules (i.e. modules with the same name but with a different version) from the supplied list of modules
 	 * Remove the duplicate modules (i.e. modules with the same name but with a different version) from the supplied list of modules
 	 * @param hash $aModules
 	 * @param hash $aModules
-	 * @return hash The ordered a duplicate-free list of modules
+	 * @return hash The ordered modules as a duplicate-free list of modules
 	 */
 	 */
 	public static function RemoveDuplicateModules($aModules)
 	public static function RemoveDuplicateModules($aModules)
 	{
 	{
-		$aRes = array();
-		$aIndex = array();
-		foreach($aModules as $sModuleId => $aModuleInfo)
-		{
-			if (preg_match('|^([^/]+)/(.*)$|', $sModuleId, $aMatches))
-			{
-				$sModuleName = $aMatches[1];
-				$sModuleVersion = $aMatches[2];
-			}
-			else
-			{
-				// No version number found, assume 1.0.0
-				$sModuleName = str_replace('/', '', $sModuleId);
-				$sModuleVersion = '1.0.0';
-			}
-			// The last version encountered has precedence
-			$aIndex[$sModuleName] = $sModuleVersion;
-		}
-	
-		foreach($aModules as $sModuleId => $aModuleInfo)
-		{
-			if (preg_match('|^([^/]+)/(.*)$|', $sModuleId, $aMatches))
-			{
-				$sModuleName = $aMatches[1];
-				$sModuleVersion = $aMatches[2];
-			}
-			else
-			{
-				// No version number found, assume 1.0.0
-				$sModuleName = str_replace('/', '', $sModuleId);
-				$sModuleVersion = '1.0.0';
-			}
-			if ($aIndex[$sModuleName] == $sModuleVersion)
-			{
-				// Ok, this this the last (or only) version of this module in the list, keep it
-				$aRes[$sModuleId] = $aModuleInfo;
-			}
-			else
-			{
-				if(version_compare($sModuleVersion, $aIndex[$sModuleName], '<'))
-				{
-					SetupPage::log_info("Module $sModuleId will be upgraded to $sModuleName/{$aIndex[$sModuleName]}.");
-				}
-				else
-				{
-					SetupPage::log_warning("Module $sModuleId will be DOWNGRADED to $sModuleName/{$aIndex[$sModuleName]} since the older version is to be loaded AFTER the more recent version.");
-				}
-			}
-		}
-		// If needed re-arrange the list ot take care of inter dependencies
-		$aRes = self::OrderModulesByDependencies($aRes, true);
-		return $aRes;
+		// No longer needed, kept only for compatibility
+		// The de-duplication is now done directly by the AddModule method
+		return $aModules;
 	}
 	}
 		
 		
 	protected static function DependencyIsResolved($sDepString, $aOrderedModules, $aSelectedModules)
 	protected static function DependencyIsResolved($sDepString, $aOrderedModules, $aSelectedModules)
@@ -386,6 +363,7 @@ class ModuleDiscovery
 	{
 	{
 		self::$m_aSearchDirs = null;
 		self::$m_aSearchDirs = null;
 		self::$m_aModules = array();
 		self::$m_aModules = array();
+		self::$m_aModuleVersionByName = array();
 	}
 	}
 
 
 	/**
 	/**