Browse Source

Protect against duplicate class definition in case of unattended installation

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2221 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 years ago
parent
commit
89c8e06c4c
1 changed files with 43 additions and 40 deletions
  1. 43 40
      datamodel/itop-change-mgmt-1.0.0/module.itop-change-mgmt.php

+ 43 - 40
datamodel/itop-change-mgmt-1.0.0/module.itop-change-mgmt.php

@@ -45,50 +45,53 @@ SetupWebPage::AddModule(
 	)
 );
 
-// Module installation handler
-//
-class ChangeManagementInstaller extends ModuleInstallerAPI
+if (!class_exists('ChangeManagementInstaller'))
 {
-	public static function BeforeWritingConfig(Config $oConfiguration)
+	// Module installation handler
+	//
+	class ChangeManagementInstaller extends ModuleInstallerAPI
 	{
-		// If you want to override/force some configuration values, do it here
-		return $oConfiguration;
-	}
-
-	/**
-	 * Handler called before creating or upgrading the database schema
-	 * @param $oConfiguration Config The new configuration of the application
-	 * @param $sPreviousVersion string PRevious version number of the module (empty string in case of first install)
-	 * @param $sCurrentVersion string Current version number of the module
-	 */
-	public static function BeforeDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
-	{
-		// If you want to migrate data from one format to another, do it here
-	}
+		public static function BeforeWritingConfig(Config $oConfiguration)
+		{
+			// If you want to override/force some configuration values, do it here
+			return $oConfiguration;
+		}
 	
-	/**
-	 * Handler called after the creation/update of the database schema
-	 * @param $oConfiguration Config The new configuration of the application
-	 * @param $sPreviousVersion string PRevious version number of the module (empty string in case of first install)
-	 * @param $sCurrentVersion string Current version number of the module
-	 */
-	public static function AfterDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
-	{
-		// Bug #464 - start_date was both in Ticket and Change tables
-		//
-		$sSourceTable = 'change';
-		$sSourceKeyField = 'id';
-
-		$sTargetTable = 'ticket';
-		$sTargetKeyField = 'id';
-
-		$sField = 'start_date';
-
-		if (CMDBSource::IsField($sSourceTable, $sField) && CMDBSource::IsField($sTargetTable, $sField) && CMDBSource::IsField($sSourceTable, $sSourceKeyField) && CMDBSource::IsField($sTargetTable, $sTargetKeyField))
+		/**
+		 * Handler called before creating or upgrading the database schema
+		 * @param $oConfiguration Config The new configuration of the application
+		 * @param $sPreviousVersion string PRevious version number of the module (empty string in case of first install)
+		 * @param $sCurrentVersion string Current version number of the module
+		 */
+		public static function BeforeDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
+		{
+			// If you want to migrate data from one format to another, do it here
+		}
+		
+		/**
+		 * Handler called after the creation/update of the database schema
+		 * @param $oConfiguration Config The new configuration of the application
+		 * @param $sPreviousVersion string PRevious version number of the module (empty string in case of first install)
+		 * @param $sCurrentVersion string Current version number of the module
+		 */
+		public static function AfterDatabaseCreation(Config $oConfiguration, $sPreviousVersion, $sCurrentVersion)
 		{
-			SetupPage::log_info("Issue #464 - Copying change/start_date into ticket/start_date"); 
-			$sRepair = "UPDATE `$sTargetTable`, `$sSourceTable` SET `$sTargetTable`.`$sField` = `$sSourceTable`.`$sField` WHERE `$sTargetTable`.`$sField` IS NULL AND`$sTargetTable`.`$sTargetKeyField` = `$sSourceTable`.`$sSourceKeyField`";
-			CMDBSource::Query($sRepair);
+			// Bug #464 - start_date was both in Ticket and Change tables
+			//
+			$sSourceTable = 'change';
+			$sSourceKeyField = 'id';
+	
+			$sTargetTable = 'ticket';
+			$sTargetKeyField = 'id';
+	
+			$sField = 'start_date';
+	
+			if (CMDBSource::IsField($sSourceTable, $sField) && CMDBSource::IsField($sTargetTable, $sField) && CMDBSource::IsField($sSourceTable, $sSourceKeyField) && CMDBSource::IsField($sTargetTable, $sTargetKeyField))
+			{
+				SetupPage::log_info("Issue #464 - Copying change/start_date into ticket/start_date"); 
+				$sRepair = "UPDATE `$sTargetTable`, `$sSourceTable` SET `$sTargetTable`.`$sField` = `$sSourceTable`.`$sField` WHERE `$sTargetTable`.`$sField` IS NULL AND`$sTargetTable`.`$sTargetKeyField` = `$sSourceTable`.`$sSourceKeyField`";
+				CMDBSource::Query($sRepair);
+			}
 		}
 	}
 }