Browse Source

Some progress on the 2.0 setup...

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2224 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 years ago
parent
commit
b65f4c6bdd
2 changed files with 173 additions and 3 deletions
  1. 143 3
      setup/setuputils.class.inc.php
  2. 30 0
      setup/wizardsteps.class.inc.php

+ 143 - 3
setup/setuputils.class.inc.php

@@ -913,7 +913,7 @@ EOF
 		$aParamValues = array(
 		$aParamValues = array(
 			'db_server' => $oWizard->GetParameter('db_server', ''),
 			'db_server' => $oWizard->GetParameter('db_server', ''),
 			'db_user' => $oWizard->GetParameter('db_user', ''),
 			'db_user' => $oWizard->GetParameter('db_user', ''),
-			'db_pwd' => $oWizard->GetParameter('db_server', ''),
+			'db_pwd' => $oWizard->GetParameter('db_pwd', ''),
 			'db_name' => $oWizard->GetParameter('db_name', ''),
 			'db_name' => $oWizard->GetParameter('db_name', ''),
 			'db_prefix' => $oWizard->GetParameter('db_prefix', ''),
 			'db_prefix' => $oWizard->GetParameter('db_prefix', ''),
 			'source_dir' => APPROOT.'datamodel',
 			'source_dir' => APPROOT.'datamodel',
@@ -921,9 +921,149 @@ EOF
 		$oConfig->UpdateFromParams($aParamValues, 'datamodel');
 		$oConfig->UpdateFromParams($aParamValues, 'datamodel');
 
 
 		$oProductionEnv = new RunTimeEnvironment();
 		$oProductionEnv = new RunTimeEnvironment();
-		$oConfig = new Config();
 		$aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, 'datamodel');
 		$aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, 'datamodel');
 
 
 		return $aAvailableModules;
 		return $aAvailableModules;
-	}	
+	}
+
+	/**
+	 * Checks if the content of a directory matches the given manifest
+	 * @param string $sBaseDir Path to the root directory of iTop
+	 * @param string $sSourceDir Relative path to the directory to check under $sBaseDir
+	 * @param Array $aDOMManifest Array of array('path' => relative_path 'size'=> iSize, 'md5' => sHexMD5)
+	 * @param Hash $aResult Used for recursion 
+	 * @return hash Hash array ('added' => array(), 'removed' => array(), 'modified' => array()) 
+	 */
+	public static function CheckDirAgainstManifest($sBaseDir, $sSourceDir, $aManifest, $aExcludeNames = array('.svn'), $aResult = null)
+	{
+		if ($aResult === null)
+		{
+			$aResult = array('added' => array(), 'removed' => array(), 'modified' => array());
+		}
+		
+		if (substr($sSourceDir, 0, 1) == '/')
+		{
+			$sSourceDir = substr($sSourceDir, 1);
+		}
+		
+		// Manifest limited to all the files supposed to be located in this directory
+		$aDirManifest = array(); 
+		foreach($aManifest as $aFileInfo)
+		{
+			$sDir = dirname($aFileInfo['path']);
+			if ($sDir == '.')
+			{
+				// Hmm... the file seems located at the root of iTop
+				$sDir = '';
+			}
+			if ($sDir == $sSourceDir)
+			{
+				$aDirManifest[basename($aFileInfo['path'])] = $aFileInfo;
+			}
+		}
+
+		// Read the content of the directory
+		foreach(glob($sBaseDir.'/'.$sSourceDir .'/*') as $sFilePath)
+		{
+			$sFile = basename($sFilePath);
+			
+			if (in_array(basename($sFile), $aExcludeNames)) continue;
+						
+			if(is_dir($sFilePath))
+			{
+				$aResult = self::CheckDirAgainstManifest($sBaseDir, $sSourceDir.'/'.$sFile, $aManifest, $aExcludeNames, $aResult);
+			}
+			else
+			{
+				if (!array_key_exists($sFile, $aDirManifest))
+				{
+//echo "New file ".$sFile." in $sSourceDir\n"; 
+					$aResult['added'][$sSourceDir.'/'.$sFile] = true;
+				}
+				else
+				{
+					$aStats = stat($sFilePath);
+					if ($aStats['size'] != $aDirManifest[$sFile]['size'])
+					{
+						// Different sizes
+						$aResult['modified'][$sSourceDir.'/'.$sFile] = 'Different sizes. Original size: '.$aDirManifest[$sFile]['size'].' bytes, actual file size on disk: '.$aStats['size'].' bytes.';
+					}
+					else
+					{
+						// Same size, compare the md5 signature
+						$sMD5 = md5_file($sFilePath);
+						if ($sMD5 != $aDirManifest[$sFile]['md5'])
+						{
+							$aResult['modified'][$sSourceDir.'/'.$sFile] = 'Content modified (MD5 checksums differ).';
+						}
+//else
+//{
+//	echo $sSourceDir.'/'.$sFile." unmodified ($sMD5 == {$aDirManifest[$sFile]['md5']})\n";
+//}
+					}
+//echo "Removing ".$sFile." from aDirManifest\n"; 
+					unset($aDirManifest[$sFile]);
+				}				
+			}
+		}
+		// What remains in the array are files that were deleted
+		foreach($aDirManifest as $sDeletedFile => $void)
+		{
+			$aResult['removed'][$sSourceDir.'/'.$sDeletedFile] = true;
+		}
+		return $aResult;
+	}
+	
+	public static function CheckDataModelFiles($sManifestFile, $sBaseDir)
+	{
+		$oXML = simplexml_load_file($sManifestFile);
+		$aManifest = array();
+		foreach($oXML as $oFileInfo)
+		{
+			$aManifest[] = array('path' => (string)$oFileInfo->path, 'size' => (int)$oFileInfo->size, 'md5' => (string)$oFileInfo->md5);
+		}
+		
+		$aResults = self::CheckDirAgainstManifest($sBaseDir, 'modules', $aManifest);
+		
+//		echo "<pre>Comparison of ".dirname($sBaseDir)."/modules:\n".print_r($aResults, true)."</pre>";
+		return $aResults;
+	}
+	
+	public static function CheckPortalFiles($sManifestFile, $sBaseDir)
+	{
+		$oXML = simplexml_load_file($sManifestFile);
+		$aManifest = array();
+		foreach($oXML as $oFileInfo)
+		{
+			$aManifest[] = array('path' => (string)$oFileInfo->path, 'size' => (int)$oFileInfo->size, 'md5' => (string)$oFileInfo->md5);
+		}
+		
+		$aResults = self::CheckDirAgainstManifest($sBaseDir, 'portal', $aManifest);
+		
+//		echo "<pre>Comparison of ".dirname($sBaseDir)."/portal:\n".print_r($aResults, true)."</pre>";
+		return $aResults;
+	}
+	
+	public static function CheckApplicationFiles($sManifestFile, $sBaseDir)
+	{
+		$oXML = simplexml_load_file($sManifestFile);
+		$aManifest = array();
+		foreach($oXML as $oFileInfo)
+		{
+			$aManifest[] = array('path' => (string)$oFileInfo->path, 'size' => (int)$oFileInfo->size, 'md5' => (string)$oFileInfo->md5);
+		}
+		
+		$aResults = array('added' => array(), 'removed' => array(), 'modified' => array());
+		foreach(array('addons', 'core', 'dictionaries', 'js', 'application', 'css', 'pages', 'synchro', 'webservices') as $sDir)
+		{
+			$aTmp = self::CheckDirAgainstManifest($sBaseDir, 'portal', $aManifest);
+			$aResults['added'] = array_merge($aResults['added'], $aTmp['added']);
+			$aResults['modified'] = array_merge($aResults['modified'], $aTmp['modified']);
+			$aResults['removed'] = array_merge($aResults['removed'], $aTmp['removed']);
+		}
+		
+//		echo "<pre>Comparison of ".dirname($sBaseDir)."/portal:\n".print_r($aResults, true)."</pre>";
+		return $aResults;
+	}
+	
 }
 }

+ 30 - 0
setup/wizardsteps.class.inc.php

@@ -377,6 +377,36 @@ class WizStepDetectedInfo extends WizardStep
 	public function Display(WebPage $oPage)
 	public function Display(WebPage $oPage)
 	{
 	{
 		$oPage->p('Info about the detected version');
 		$oPage->p('Info about the detected version');
+		$sSourceDir = $this->oWizard->GetParameter('source_dir', '');
+		$aInstalledModules = SetupUtils::AnalyzeInstallation($this->oWizard);		
+		$sVersion = $aInstalledModules[ROOT_MODULE]['version_db'];
+		
+		if (preg_match('/^([0-9]+)\.([0-9]+)\.([0-9]+)\.(.*)$/', $sVersion, $aMatches))
+		{
+			$sVersion = $aMatches[1].'.'.$aMatches[2].'.'.$aMatches[3];
+		}
+		
+		$sKnownManifestFile = APPROOT.'setup/known-versions/'.$sVersion.'/manifest.xml';
+		if ($sSourceDir != '')
+		{
+			if (file_exists($sKnownManifestFile))
+			{
+				$aDMchanges = SetupUtils::CheckDataModelFiles($sKnownManifestFile, $sSourceDir);
+				$aPortalChanges = SetupUtils::CheckPortalFiles($sKnownManifestFile, $sSourceDir);
+				$aCodeChanges = SetupUtils::CheckApplicationFiles($sKnownManifestFile, $sSourceDir);
+				
+				$oPage->add("Changes detected compared to $sVersion:<br/>DataModel:<br/><pre>".print_r($aDMchanges, true)."</pre><br/>Portal:<br/><pre>".print_r($aPortalChanges, true)."</pre><br/>Code:<br/><pre>".print_r($aCodeChanges, true)."</pre>");
+			}
+			else
+			{
+				$oPage->p("Unknown version $sVersion. Do you want to upgrade anyway ??? NOT GUARANTEED AT ALL !!!");
+			}
+		}
+		else
+		{
+			$oPage->p("No source dir provided assuming that the installed version '$sVersion' is genuine iTop build...");
+		}
+		
 	}
 	}
 }
 }