Trac #86 - CSV format aligned with standard specifications

Trac #93 - Fixed issue within the setup data load (related to memory_limit)
Fixed issues with the consultant toolkit: upgrade an existing DB (add new class/attribute)
Developed core services to allow for demonstrating impact computation capability
Deprecated option operation=direct on page UI.php

SVN:trunk[313]
This commit is contained in:
Romain Quetiez
2010-03-08 09:10:16 +00:00
parent 10fa31807b
commit 5a09dc6e2b
16 changed files with 2131 additions and 1909 deletions

View File

@@ -5,49 +5,64 @@
* 'file' string Name of the file to load
* 'session_status' string 'start', 'continue' or 'end'
* 'percent' integer 0..100 the percentage of completion once the file has been loaded
*/
*/
define('SAFE_MINIMUM_MEMORY', 32*1024*1024);
require_once('../application/utils.inc.php');
require_once('./setuppage.class.inc.php');
$iMemoryLimit = utils::ConvertToBytes(ini_get('memory_limit'));
if ($iMemoryLimit < SAFE_MINIMUM_MEMORY)
{
if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === FALSE)
{
SetupWebPage::error("memory_limit is too small: $iMemoryLimit and can not be increased by the script itself.");
}
else
{
SetupWebPage::log("memory_limit increased from $iMemoryLimit to ".SAFE_MINIMUM_MEMORY.".");
}
}
function FatalErrorCatcher($sOutput)
{
if ( preg_match('|<phpfatalerror>.*</phpfatalerror>|s', $sOutput, &$aMatches) )
{
$sMemoryLimit = trim(ini_get('memory_limit'));
if (empty($sMemoryLimit))
{
// On some PHP installations, memory_limit does not exist as a PHP setting!
// (encountered on a 5.2.0 under Windows)
// In that case, ini_set will not work, let's keep track of this and proceed with the data load
SetupWebPage::log_info("No memory limit has been defined in this instance of PHP");
}
else
{
// Check that the limit will allow us to load the data
//
$iMemoryLimit = utils::ConvertToBytes($sMemoryLimit);
if ($iMemoryLimit < SAFE_MINIMUM_MEMORY)
{
if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === FALSE)
{
SetupWebPage::log_error("memory_limit is too small: $iMemoryLimit and can not be increased by the script itself.");
}
else
{
SetupWebPage::log_info("memory_limit increased from $iMemoryLimit to ".SAFE_MINIMUM_MEMORY.".");
}
}
}
function FatalErrorCatcher($sOutput)
{
if ( preg_match('|<phpfatalerror>.*</phpfatalerror>|s', $sOutput, $aMatches) )
{
header("HTTP/1.0 500 Internal server error.");
foreach ($aMatches as $sMatch)
{
$errors .= strip_tags($sMatch)."\n";
}
$sOutput = "$errors\n";
// Logging to a file does not work if the whole memory is exhausted...
//SetupWebPage::error("Fatal error - in $__FILE__ , $errors");
}
$sOutput = "$errors\n";
// Logging to a file does not work if the whole memory is exhausted...
//SetupWebPage::log_error("Fatal error - in $__FILE__ , $errors");
}
return $sOutput;
}
}
//Define some bogus, invalid HTML tags that no sane
//person would ever put in an actual document and tell
//PHP to delimit fatal error warnings with them.
//Define some bogus, invalid HTML tags that no sane
//person would ever put in an actual document and tell
//PHP to delimit fatal error warnings with them.
ini_set('error_prepend_string', '<phpfatalerror>');
ini_set('error_append_string', '</phpfatalerror>');
// Starts the capture of the ouput, and sets a filter to capture the fatal errors.
ob_start('FatalErrorCatcher'); // Start capturing the output, and pass it through the fatal error catcher
// Starts the capture of the ouput, and sets a filter to capture the fatal errors.
ob_start('FatalErrorCatcher'); // Start capturing the output, and pass it through the fatal error catcher
require_once('../core/config.class.inc.php');
require_once('../core/cmdbsource.class.inc.php');
require_once('./xmldataloader.class.inc.php');
@@ -58,14 +73,14 @@ define('TMP_CONFIG_FILE', '../tmp-config-itop.php');
// Never cache this page
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Fri, 17 Jul 1970 05:00:00 GMT"); // Date in the past
/**
* Main program
*/
$sFileName = Utils::ReadParam('file', '');
$sSessionStatus = Utils::ReadParam('session_status', '');
$iPercent = (integer)Utils::ReadParam('percent', 0);
SetupWebPage::log("Info - Loading file: $sFileName");
SetupWebPage::log_info("Loading file: $sFileName");
try
{
@@ -81,30 +96,30 @@ try
$oChange->Set("date", time());
$oChange->Set("userinfo", "Initialization");
$iChangeId = $oChange->DBInsert();
SetupWebPage::log("Info - starting data load session");
SetupWebPage::log_info("starting data load session");
$oDataLoader->StartSession($oChange);
}
$oDataLoader->LoadFile($sFileName);
$sResult = sprintf("Info - loading of %s done. (Overall %d %% completed).", basename($sFileName), $iPercent);
$sResult = sprintf("loading of %s done. (Overall %d %% completed).", basename($sFileName), $iPercent);
echo $sResult;
SetupWebPage::log($sResult);
SetupWebPage::log_info($sResult);
if ($sSessionStatus == 'end')
{
$oDataLoader->EndSession();
SetupWebPage::log("Info - ending data load session");
SetupWebPage::log_info("ending data load session");
}
}
catch(Exception $e)
{
echo "<p>An error happened while loading the data</p>\n";
echo '<p>'.$e."</p>\n";
SetupWebPage::log("Error - An error happened while loading the data. ".$e);
}
if (function_exists('memory_get_peak_usage'))
{
SetupWebPage::log("Info - loading file '$sFileName', peak memory usage. ".memory_get_peak_usage());
SetupWebPage::log_error("An error happened while loading the data. ".$e);
}
if (function_exists('memory_get_peak_usage'))
{
SetupWebPage::log_info("loading file '$sFileName', peak memory usage. ".memory_get_peak_usage());
}
?>