Parcourir la source

Improved the data load during the setup:
- Sample data are clearly separated from the structure data (inc. menus and user profiles)
- Both categories of data are enumerated from specific folders

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

romainq il y a 16 ans
Parent
commit
8b14ff179f

+ 0 - 8
setup/data/export.cmd

@@ -26,11 +26,3 @@ wget --output-document=19.infracontracts.xml --post-data="auth_user=%USER%&auth_
 wget --output-document=20.contactcontracts.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT lnkContactContract&format=xml"
 wget --output-document=21.auditcategories.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT AuditCategory&format=xml"
 wget --output-document=22.auditrules.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT AuditRule&format=xml"
-wget --output-document=23.dimensions.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_Dimensions&format=xml"
-wget --output-document=24.profiles.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_Profiles&format=xml"
-wget --output-document=25.classprojection.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_ClassProjection&format=xml"
-wget --output-document=26.profileprojection.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_ProfileProjection&format=xml"
-wget --output-document=27.actiongrant.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_ActionGrant&format=xml"
-wget --output-document=28.attributegrant.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_AttributeGrant&format=xml"
-wget --output-document=29.stimulusgrant.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_StimulusGrant&format=xml"
-pause

+ 0 - 0
setup/menus.xml → setup/data/structure/1.menus.xml


+ 0 - 0
setup/data/23.dimensions.xml → setup/data/structure/10.dimensions.xml


+ 0 - 0
setup/data/24.profiles.xml → setup/data/structure/11.profiles.xml


+ 0 - 0
setup/data/25.classprojection.xml → setup/data/structure/12.classprojection.xml


+ 0 - 0
setup/data/26.profileprojection.xml → setup/data/structure/13.profileprojection.xml


+ 0 - 0
setup/data/27.actiongrant.xml → setup/data/structure/14.actiongrant.xml


+ 0 - 0
setup/data/28.attributegrant.xml → setup/data/structure/15.attributegrant.xml


+ 0 - 0
setup/data/29.stimulusgrant.xml → setup/data/structure/16.stimulusgrant.xml


+ 3 - 2
setup/export_menus.cmd → setup/data/structure/export_menus.cmd

@@ -1,6 +1,7 @@
 SET WEBROOT=http://localhost:81
-SET USER=Erwan
-SET PWD=Taloc
+SET USER=admin
+SET PWD=admin
+
 REM The order (numbering) of the files is important since
 REM it dictates the order to import them back
 wget --output-document=1.menus.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%WEBROOT%/pages/export.php?expression=SELECT menuNode WHERE type%%3D%%27application%%27&format=xml"

+ 13 - 0
setup/data/structure/export_profiles.cmd

@@ -0,0 +1,13 @@
+SET WEBROOT=http://localhost:81
+SET USER=admin
+SET PWD=admin
+
+REM The order (numbering) of the files is important since
+REM it dictates the order to import them back
+wget --output-document=10.dimensions.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_Dimensions&format=xml"
+wget --output-document=11.profiles.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_Profiles&format=xml"
+wget --output-document=12.classprojection.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_ClassProjection&format=xml"
+wget --output-document=13.profileprojection.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_ProfileProjection&format=xml"
+wget --output-document=14.actiongrant.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_ActionGrant&format=xml"
+wget --output-document=15.attributegrant.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_AttributeGrant&format=xml"
+wget --output-document=16.stimulusgrant.xml --post-data="auth_user=%USER%&auth_pwd=%PWD%&operation=login" "%EXPORT%?expression=SELECT URP_StimulusGrant&format=xml"

+ 50 - 28
setup/index.php

@@ -8,7 +8,8 @@ require_once('../core/cmdbsource.class.inc.php');
 require_once('./setuppage.class.inc.php');
 define('TMP_CONFIG_FILE', '../tmp-config-itop.php');
 define('FINAL_CONFIG_FILE', '../config-itop.php');
-define('SETUP_DATA_DIR', './data');
+define('SETUP_STRUCTURE_DATA_DIR', './data/structure');
+define('SETUP_SAMPLE_DATA_DIR', './data');
 define('PHP_MIN_VERSION', '5.2.0');
 define('MYSQL_MIN_VERSION', '5.0.0');
 
@@ -173,45 +174,66 @@ function CreateAdminAccount(setup_web_page $oP, Config $oConfig, $sAdminUser, $s
 	}
 }
 
-/**
- * Scans the ./data directory for XML files and output them as a Javascript array
- */ 
-function PopulateDataFilesList(setup_web_page $oP)
+//aFilesToLoad[aFilesToLoad.length] = './menus.xml'; // First load the menus
+
+function ListDataFiles($sDirectory, setup_web_page $oP)
 {
-	if ($hDir = @opendir(SETUP_DATA_DIR))
+	$aFilesToLoad = array();
+	if ($hDir = @opendir($sDirectory))
 	{
-		$aFilesToLoad = array();
-	    // This is the correct way to loop over the directory. (according the documentation)
-	    while (($sFile = readdir($hDir)) !== false)
+		// This is the correct way to loop over the directory. (according to the documentation)
+		while (($sFile = readdir($hDir)) !== false)
 		{
 			$sExtension = pathinfo($sFile, PATHINFO_EXTENSION );
 			if (strcasecmp($sExtension, 'xml') == 0)
 			{
-				$aFilesToLoad[] = SETUP_DATA_DIR.'/'.$sFile;
+				$aFilesToLoad[] = $sDirectory.'/'.$sFile;
 			}
-	    }
-	    closedir($hDir);
-	    // Load order is important we expect the files to be ordered
-	    // like numbered 1.Organizations.xml 2.Locations.xml , etc.
-	    asort($aFilesToLoad);
-		// Menus can be loaded any time... like here at the end
-	    
-		$oP->add("<script type=\"text/javascript\">\n");
-		$oP->add("function PopulateDataFilesList()\n");
-		$oP->add("{\n");
-		$index = 0;
-	    foreach($aFilesToLoad as $sFile)
-	    {
-			$oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n");
-			$index++;
 		}
-		$oP->add("}\n");
-		$oP->add("</script>\n");
+		closedir($hDir);
+		// Load order is important we expect the files to be ordered
+		// like numbered 1.Organizations.xml 2.Locations.xml , etc.
+		asort($aFilesToLoad);
 	}
 	else
 	{
-		$oP->error("Data directory (".SETUP_DATA_DIR.") no found or not readable.");
+		$oP->error("Data directory (".$sDirectory.") not found or not readable.");
 	}
+	return $aFilesToLoad;
+}
+
+
+/**
+ * Scans the ./data directory for XML files and output them as a Javascript array
+ */ 
+function PopulateDataFilesList(setup_web_page $oP)
+{
+
+	$oP->add("<script type=\"text/javascript\">\n");
+	$oP->add("function PopulateDataFilesList()\n");
+	$oP->add("{\n");
+
+	// Structure data
+	//
+	$aStructureDataFiles = ListDataFiles(SETUP_STRUCTURE_DATA_DIR, $oP);
+	foreach($aStructureDataFiles as $sFile)
+	{
+		$oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n");
+	}
+
+	// Sample data - loaded IIF wished by the user
+	//
+	$oP->add("if (($(\"#sample_data:checked\").length == 1))");
+	$oP->add("{");
+	$aSampleDataFiles = ListDataFiles(SETUP_SAMPLE_DATA_DIR, $oP);
+	foreach($aSampleDataFiles as $sFile)
+	{
+		$oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n");
+	}
+	$oP->add("}\n");
+
+	$oP->add("}\n");
+	$oP->add("</script>\n");
 }
 
 /**

+ 3 - 6
setup/setup.js

@@ -89,12 +89,9 @@ var aFilesToLoad = new Array();
 
 function DoLoadDataAsynchronous()
 {
-	// Check if sample data must be loaded, or just the menus
-	aFilesToLoad[aFilesToLoad.length] = './menus.xml'; // First load the menus
-	if (($("#sample_data:checked").length == 1))
-	{
-		PopulateDataFilesList(); // Function created in PHP to get the list of XML files on the server
-	}
+	// The array aFilesToLoad is populated by this function dynamically written on the server
+	PopulateDataFilesList();
+
 	$('#setup').block({message: '<p>Loading data...<br/><div id=\"progress\">0%</div></p>'});
 	$('#progress').progression( {Current:0, Maximum: 100, aBackgroundImg: 'orange-progress.gif', aTextColor: '#000000'} );
 	LoadNextDataFile('', '');