Explorar o código

Bug fix: when removing a module (like Incident Management) that contained Triggers to such objects, the remaining triggers must be deleted because they reference a non-existing class.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1402 a333f486-631f-4898-b8df-5754b55c2be0
dflaven %!s(int64=14) %!d(string=hai) anos
pai
achega
0802b2e5ae
Modificáronse 1 ficheiros con 28 adicións e 0 borrados
  1. 28 0
      modules/itop-tickets-1.0.0/module.itop-tickets.php

+ 28 - 0
modules/itop-tickets-1.0.0/module.itop-tickets.php

@@ -17,6 +17,7 @@ SetupWebPage::AddModule(
 		),
 		'mandatory' => true,
 		'visible' => false,
+		'installer' => 'TicketsInstaller',
 
 		// Components
 		//
@@ -41,4 +42,31 @@ SetupWebPage::AddModule(
 	)
 );
 
+// 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
+		$oSearch = new DBObjectSearch('TriggerOnObject');
+		$oSet = new DBObjectSet($oSearch);
+		$oChange = null;
+		while($oTrigger = $oSet->Fetch())
+		{
+			if (!MetaModel::IsValidClass($oTrigger->Get('target_class')))
+			{
+				if ($oChange == null)
+				{
+					// Create the change for its first use
+					$oChange = new CMDBChange;
+					$oChange->Set("date", time());
+					$oChange->Set("userinfo", "Uninstallation");
+					$oChange->DBInsert();
+				}
+				$oTrigger->DBDeleteTracked($oChange);
+			}
+		}
+	}
+}
 ?>