فهرست منبع

Life cycle images enhancements:
- precomputed images are now stored in the "lifecycle" directory of the module in which the class is declared.
- graphviz.php makes a proper usage of the data directory for its data files
- life cycles images are now transparent

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2297 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 12 سال پیش
والد
کامیت
e7f441b5dc

BIN
datamodels/2.x/itop-change-mgmt-itil/lifecycle/EmergencyChange.png


BIN
datamodels/2.x/itop-change-mgmt-itil/lifecycle/NormalChange.png


BIN
datamodels/2.x/itop-change-mgmt-itil/lifecycle/RoutineChange.png


BIN
datamodels/2.x/itop-incident-mgmt-itil/lifecycle/Incident.png


BIN
datamodels/2.x/itop-request-mgmt-itil/lifecycle/UserRequest.png


+ 43 - 12
pages/graphviz.php

@@ -62,9 +62,10 @@ function GraphvizLifecycle($sClass)
 		$aStates = MetaModel::EnumStates($sClass);
 		$aStimuli = MetaModel::EnumStimuli($sClass);
 		$sDotFileContent .= "digraph finite_state_machine {
+	graph [bgcolor = \"transparent\"];
 	rankdir=LR;
 	size=\"12,12\"
-	node [ fontname=Verdana ];
+	node [ fontname=Verdana style=filled fillcolor=\"#ffffff\" ];
 	edge [ fontname=Verdana ];
 ";
 		$aStatesLinks = array();
@@ -108,25 +109,55 @@ function GraphvizLifecycle($sClass)
 	return $sDotFileContent;
 }
 
-$sClass = utils::ReadParam('class', 'bizIncidentTicket', false, 'class');
-$sDir = dirname(__FILE__);
-$sImageFilePath = $sDir."/../images/lifecycle/".$sClass.".png";
+$sClass = utils::ReadParam('class', '', false, 'class');
+$oReflection = new ReflectionClass($sClass);
+$sDeclarationFile = $oReflection->getFileName();
+$sModuleDir = dirname($sDeclarationFile);
+
+$sImageFilePath = $sModuleDir."/lifecycle/".$sClass.".png";
 $sDotExecutable = MetaModel::GetConfig()->Get('graphviz_path');
 if (file_exists($sDotExecutable))
 {
 	// create the file with Graphviz
+	$sImageFilePath = APPROOT."data/lifecycle/".$sClass.".png";
+	if (!is_dir(APPROOT."data"))
+	{
+		@mkdir(APPROOT."data");
+	}
+	if (!is_dir(APPROOT."data/lifecycle"))
+	{
+		@mkdir(APPROOT."data/lifecycle");
+	}
 	$sDotDescription = GraphvizLifecycle($sClass);
-	$sDotFilePath = $sDir."/tmp-lifecycle.dot";
-	// From now on, fail silently, since the image file may
-	// already exist and we should not "pollute" the page's output
-	// with warnings in case we are unable to refresh the image
+	$sDotFilePath = APPROOT."data/lifecycle/{$sClass}.dot";
+	
 	$rFile = @fopen($sDotFilePath, "w");
 	@fwrite($rFile, $sDotDescription);
 	@fclose($rFile);
-	//echo "<p>Executing command: <tt>$sDotExecutable -Tpng < $sDotFilePath > $sImageFilePath</tt></p>\n";
-	@exec("$sDotExecutable -Tpng < $sDotFilePath > $sImageFilePath");
+	$aOutput = array();
+	$CommandLine = "$sDotExecutable -v -Tpng < $sDotFilePath -o$sImageFilePath 2>&1";
+	
+	exec($CommandLine, $aOutput, $iRetCode);
+	if ($iRetCode != 0)
+	{
+		header('Content-type: text/html');
+		echo "<p><b>Error:</b></p>";
+		echo "<p>The command: <pre>$CommandLine</pre> returned $iRetCode</p>";
+		echo "<p>The output of the command is:<pre>\n".implode("\n", $aOutput)."</pre></p>";
+		echo "<hr>";
+		echo "<p>Content of the '".basename($sDotFilePath)."' file:<pre>\n$sDotDescription</pre>";
+	}
+	else
+	{
+		header('Content-type: image/png');
+		echo file_get_contents($sImageFilePath);
+	}
+	@unlink($sDotFilePath);
+}
+else
+{
+	header('Content-type: image/png');
+	echo file_get_contents($sImageFilePath);
 }
 
-header('Content-type: image/png');
-echo file_get_contents($sImageFilePath);
 ?>