mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
N°8796 - Add PHP code style validation in iTop and extensions - format whole code base
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (C) 2013-2024 Combodo SAS
|
||||
*
|
||||
@@ -25,7 +26,7 @@
|
||||
|
||||
use Combodo\iTop\Application\WebPage\WebPage;
|
||||
|
||||
define('SAFE_MINIMUM_MEMORY', 256*1024*1024);
|
||||
define('SAFE_MINIMUM_MEMORY', 256 * 1024 * 1024);
|
||||
|
||||
require_once('../approot.inc.php');
|
||||
require_once(APPROOT.'/application/application.inc.php');
|
||||
@@ -39,37 +40,28 @@ LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be
|
||||
require_once(APPROOT.'/setup/setuppage.class.inc.php');
|
||||
require_once(APPROOT.'/setup/xmldataloader.class.inc.php');
|
||||
|
||||
|
||||
function SetMemoryLimit($oP)
|
||||
{
|
||||
$sMemoryLimit = trim(ini_get('memory_limit'));
|
||||
if (empty($sMemoryLimit))
|
||||
{
|
||||
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
|
||||
$oP->p("No memory limit has been defined in this instance of PHP");
|
||||
}
|
||||
else
|
||||
{
|
||||
$oP->p("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 (!utils::IsMemoryLimitOk($iMemoryLimit, SAFE_MINIMUM_MEMORY))
|
||||
{
|
||||
if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === FALSE)
|
||||
{
|
||||
$oP->p("memory_limit is too small: $iMemoryLimit and can not be increased by the script itself.");
|
||||
}
|
||||
else
|
||||
{
|
||||
$oP->p("memory_limit increased from $iMemoryLimit to ".SAFE_MINIMUM_MEMORY.".");
|
||||
if (!utils::IsMemoryLimitOk($iMemoryLimit, SAFE_MINIMUM_MEMORY)) {
|
||||
if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === false) {
|
||||
$oP->p("memory_limit is too small: $iMemoryLimit and can not be increased by the script itself.");
|
||||
} else {
|
||||
$oP->p("memory_limit increased from $iMemoryLimit to ".SAFE_MINIMUM_MEMORY.".");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Main
|
||||
@@ -87,9 +79,7 @@ $sFileName = Utils::ReadParam('file', '', false, 'raw_data');
|
||||
|
||||
$oP = new WebPage("iTop - Backoffice data loader");
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
// Note: the data model must be loaded first
|
||||
$oDataLoader = new XMLDataLoader();
|
||||
|
||||
@@ -102,8 +92,7 @@ try
|
||||
|
||||
SetMemoryLimit($oP);
|
||||
|
||||
|
||||
// The XMLDataLoader constructor has initialized the DB, let's start a transaction
|
||||
// The XMLDataLoader constructor has initialized the DB, let's start a transaction
|
||||
CMDBSource::Query('START TRANSACTION');
|
||||
|
||||
$oP->p("Starting data load.");
|
||||
@@ -128,26 +117,21 @@ try
|
||||
}
|
||||
}
|
||||
$aWarnings = $oDataLoader->GetWarnings();
|
||||
if (count($aWarnings) > 0)
|
||||
{
|
||||
if (count($aWarnings) > 0) {
|
||||
$oP->p('Warnings ('.count($aWarnings).')');
|
||||
foreach ($aWarnings as $sMsg)
|
||||
{
|
||||
foreach ($aWarnings as $sMsg) {
|
||||
$oP->p(' * '.$sMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$oP->p("An error happened while loading the data: ".$e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$oP->p("An error happened while loading the data: ".$e->getMessage());
|
||||
$oP->p("Aborting (no data written)...");
|
||||
CMDBSource::Query('ROLLBACK');
|
||||
}
|
||||
|
||||
if (function_exists('memory_get_peak_usage'))
|
||||
{
|
||||
if (function_exists('memory_get_peak_usage')) {
|
||||
$oP->p("Information: memory peak usage: ".memory_get_peak_usage());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user