diff --git a/setup/data/export.cmd b/setup/data/export.cmd index 923d30177..d7200a315 100644 --- a/setup/data/export.cmd +++ b/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 diff --git a/setup/menus.xml b/setup/data/structure/1.menus.xml similarity index 100% rename from setup/menus.xml rename to setup/data/structure/1.menus.xml diff --git a/setup/data/23.dimensions.xml b/setup/data/structure/10.dimensions.xml similarity index 100% rename from setup/data/23.dimensions.xml rename to setup/data/structure/10.dimensions.xml diff --git a/setup/data/24.profiles.xml b/setup/data/structure/11.profiles.xml similarity index 100% rename from setup/data/24.profiles.xml rename to setup/data/structure/11.profiles.xml diff --git a/setup/data/25.classprojection.xml b/setup/data/structure/12.classprojection.xml similarity index 100% rename from setup/data/25.classprojection.xml rename to setup/data/structure/12.classprojection.xml diff --git a/setup/data/26.profileprojection.xml b/setup/data/structure/13.profileprojection.xml similarity index 100% rename from setup/data/26.profileprojection.xml rename to setup/data/structure/13.profileprojection.xml diff --git a/setup/data/27.actiongrant.xml b/setup/data/structure/14.actiongrant.xml similarity index 100% rename from setup/data/27.actiongrant.xml rename to setup/data/structure/14.actiongrant.xml diff --git a/setup/data/28.attributegrant.xml b/setup/data/structure/15.attributegrant.xml similarity index 100% rename from setup/data/28.attributegrant.xml rename to setup/data/structure/15.attributegrant.xml diff --git a/setup/data/29.stimulusgrant.xml b/setup/data/structure/16.stimulusgrant.xml similarity index 100% rename from setup/data/29.stimulusgrant.xml rename to setup/data/structure/16.stimulusgrant.xml diff --git a/setup/export_menus.cmd b/setup/data/structure/export_menus.cmd similarity index 90% rename from setup/export_menus.cmd rename to setup/data/structure/export_menus.cmd index e7cc514af..2370101e8 100644 --- a/setup/export_menus.cmd +++ b/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" diff --git a/setup/data/structure/export_profiles.cmd b/setup/data/structure/export_profiles.cmd new file mode 100644 index 000000000..3d2ea0aec --- /dev/null +++ b/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" diff --git a/setup/index.php b/setup/index.php index 12b255c38..0696dfd18 100644 --- a/setup/index.php +++ b/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 } } +//aFilesToLoad[aFilesToLoad.length] = './menus.xml'; // First load the menus + +function ListDataFiles($sDirectory, setup_web_page $oP) +{ + $aFilesToLoad = array(); + if ($hDir = @opendir($sDirectory)) + { + // 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[] = $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); + } + else + { + $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) { - if ($hDir = @opendir(SETUP_DATA_DIR)) + + $oP->add("\n"); + $oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n"); } - else + + // 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->error("Data directory (".SETUP_DATA_DIR.") no found or not readable."); + $oP->add("aFilesToLoad[aFilesToLoad.length] = '$sFile';\n"); } + $oP->add("}\n"); + + $oP->add("}\n"); + $oP->add("\n"); } /** diff --git a/setup/setup.js b/setup/setup.js index f407a199d..8c9e46008 100644 --- a/setup/setup.js +++ b/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: '
Loading data...