N°931: Integrity controls

This commit is contained in:
Eric
2018-09-11 12:25:01 +02:00
13 changed files with 2506 additions and 2344 deletions

1
.gitignore vendored
View File

@@ -4,6 +4,7 @@ env-*/*
# composer reserver directory, from sources, populate/update using "composer install"
vendor/*
test/vendor/*
# all datas but listing prevention
data/*

View File

@@ -34,5 +34,10 @@
<option name="SMART_TABS" value="true" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="XML">
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>

View File

@@ -10,7 +10,11 @@
<inspection_tool class="PhpUndefinedClassInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="DONT_REPORT_MULTI_RESOLVE" value="true" />
</inspection_tool>
<inspection_tool class="PhpUndefinedMethodInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpUnhandledExceptionInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpUnusedLocalVariableInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="DONT_REPORT_INSIDE_LIST" value="true" />
</inspection_tool>
<inspection_tool class="PhpUnusedParameterInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="DONT_REPORT_ABSTRACT_CLASS" value="true" />
</inspection_tool>

View File

@@ -46,6 +46,44 @@ iTop also offers mass import tools and web services to integrate with your IT
# About Us
iTop development is sponsored, led and supported by [Combodo][14].
# Contributors
We would like to give a special thank you to the people from the community who contributed to this project, including:
- Alves, David
- Beck, Pedro
- Bilger, Jean-François
- Cardoso, Anderson
- Cassaro, Bruno
- Casteleyn, Thomas
- Castro, Randall Badilla
- Colantoni, Maria Laura
- Dvořák, Lukáš
- Goethals, Stefan
- Gumble, David
- Hippler, Lars
- Khamit, Shamil
- Kunin, Vladimir
- Lassiter, Dennis
- Lucas, Jonathan
- Malik, Remie
- Rosenke, Stephan
- Seki, Shoji
- Shilov, Vladimir
- Tulio, Marco
- Turrubiates, Miguel
#### Aliases
- cprobst
- Karkoff1212
- Laura
- Schlobinux
- theBigOne
- ulmerspatz
#### Companies
- Hardis
- ITOMIG
[1]: https://sourceforge.net/p/itop/discussion/
[2]: https://sourceforge.net/p/itop/tickets/

File diff suppressed because it is too large Load Diff

View File

@@ -918,6 +918,10 @@ class ScalarExpression extends UnaryExpression
$aValue['label'] = $oObj->Get("friendlyname");
}
else
{
$aValue['label'] = Dict::S('Enum:Undefined');
}
}
catch (Exception $e)
{
@@ -934,6 +938,10 @@ class ScalarExpression extends UnaryExpression
$oObj = MetaModel::GetObject($sTarget, $this->GetValue(), true, true);
$aValue['label'] = $oObj->Get("friendlyname");
}
else
{
$aValue['label'] = Dict::S('Enum:Undefined');
}
}
catch (Exception $e)
{

View File

@@ -193,7 +193,7 @@
var result;
if( data && data.length ) {
for (var i=0; i < data.length; i++) {
if( data[i].result.toLowerCase() == q.toLowerCase() ) {
if( data[i].result.toLowerCase() === q.toLowerCase() ) {
result = data[i];
break;
}
@@ -386,6 +386,7 @@
$.ajax({
// try to leverage ajaxQueue plugin to abort previous requests
mode: "abort",
method: "POST",
// limit abortion to this input
port: "autocomplete" + input.name,
dataType: options.dataType,

View File

@@ -1,208 +1,208 @@
<?php
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
/**
* Does load data from XML files (currently used in the setup only)
*
* @copyright Copyright (C) 2010-2018 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
/**
* This page is called to perform "asynchronously" the setup actions
* parameters
* 'operation': one of 'compile_data_model', 'update_db_schema', 'after_db_creation', 'file'
*
* if 'operation' == 'update_db_schema':
* 'mode': install | upgrade
*
* if 'operation' == 'after_db_creation':
* 'mode': install | upgrade
*
* if 'operation' == 'file':
* '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', 64*1024*1024);
require_once('../approot.inc.php');
require_once(APPROOT.'/application/utils.inc.php');
require_once(APPROOT.'/setup/setuppage.class.inc.php');
require_once(APPROOT.'/setup/moduleinstaller.class.inc.php');
ini_set('max_execution_time', max(3600, ini_get('max_execution_time'))); // Under Windows SQL/backup operations are part of the timeout and require extra time
date_default_timezone_set('Europe/Paris'); // Just to avoid a warning if the timezone is not set in php.ini
$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
SetupPage::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)
{
SetupPage::log_error("memory_limit is too small: $iMemoryLimit and can not be increased by the script itself.");
}
else
{
SetupPage::log_info("memory_limit increased from $iMemoryLimit to ".SAFE_MINIMUM_MEMORY.".");
}
}
}
define('PHP_FATAL_ERROR_TAG', 'phpfatalerror');
/**
* Handler for register_shutdown_function, to catch PHP errors
*/
function ShutdownCallback()
{
$error = error_get_last();
$bIsErrorToReport = (($error !== null) && ($error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR)));
if (!$bIsErrorToReport)
{
return;
}
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
$sLogMessage = "PHP error occured : msg=$errstr, no=$errno, file=$errfile, line=$errline";
SetupPage::log_error("Setup error: $sLogMessage");
echo '<'.PHP_FATAL_ERROR_TAG.'>'.$sLogMessage.'</'.PHP_FATAL_ERROR_TAG.'>';
}
function FatalErrorCatcher($sOutput)
{
if (preg_match('|<'.PHP_FATAL_ERROR_TAG.'>.*</'.PHP_FATAL_ERROR_TAG.'>|s', $sOutput, $aMatches))
{
header("HTTP/1.0 500 Internal server error.");
$errors = '';
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...
//SetupPage::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.
ini_set('error_prepend_string', '<'.PHP_FATAL_ERROR_TAG.'>');
ini_set('error_append_string', '</'.PHP_FATAL_ERROR_TAG.'>');
// callback on errors to log
register_shutdown_function('ShutdownCallback');
// 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(APPROOT.'/core/config.class.inc.php');
require_once(APPROOT.'/core/log.class.inc.php');
require_once(APPROOT.'/core/kpi.class.inc.php');
require_once(APPROOT.'/core/cmdbsource.class.inc.php');
require_once('./xmldataloader.class.inc.php');
require_once(APPROOT.'/application/ajaxwebpage.class.inc.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
*/
$sOperation = Utils::ReadParam('operation', '');
try
{
switch($sOperation)
{
case 'async_action':
ini_set('max_execution_time', max(240, ini_get('max_execution_time')));
// While running the setup it is desirable to see any error that may happen
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
require_once(APPROOT.'/setup/wizardcontroller.class.inc.php');
require_once(APPROOT.'/setup/wizardsteps.class.inc.php');
$sClass = utils::ReadParam('step_class', '');
$sState = utils::ReadParam('step_state', '');
$sActionCode = utils::ReadParam('code', '');
$aParams = utils::ReadParam('params', array(), false, 'raw_data');
$oPage = new ajax_page('');
$oDummyController = new WizardController('');
if (is_subclass_of($sClass, 'WizardStep'))
{
/** @var WizardStep $oStep */
$oStep = new $sClass($oDummyController, $sState);
$sConfigFile = utils::GetConfigFilePath();
if (file_exists($sConfigFile) && !is_writable($sConfigFile) && $oStep->RequiresWritableConfig())
{
$oPage->error("<b>Error:</b> the configuration file '".$sConfigFile."' already exists and cannot be overwritten.");
$oPage->p("The wizard cannot modify the configuration file for you. If you want to upgrade ".ITOP_APPLICATION.", make sure that the file '<b>".realpath($sConfigFile)."</b>' can be modified by the web server.");
$oPage->output();
}
else
{
$oStep->AsyncAction($oPage, $sActionCode, $aParams);
}
}
$oPage->output();
break;
default:
throw(new Exception("Error unsupported operation '$sOperation'"));
}
}
catch(Exception $e)
{
header("HTTP/1.0 500 Internal server error.");
echo "<p>An error happened while processing the installation:</p>\n";
echo '<p>'.$e."</p>\n";
SetupPage::log_error("An error happened while processing the installation: ".$e);
}
if (function_exists('memory_get_peak_usage'))
{
if ($sOperation == 'file')
{
SetupPage::log_info("loading file '$sFileName', peak memory usage. ".memory_get_peak_usage());
}
else
{
SetupPage::log_info("operation '$sOperation', peak memory usage. ".memory_get_peak_usage());
}
}
<?php
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
/**
* Does load data from XML files (currently used in the setup only)
*
* @copyright Copyright (C) 2010-2018 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
/**
* This page is called to perform "asynchronously" the setup actions
* parameters
* 'operation': one of 'compile_data_model', 'update_db_schema', 'after_db_creation', 'file'
*
* if 'operation' == 'update_db_schema':
* 'mode': install | upgrade
*
* if 'operation' == 'after_db_creation':
* 'mode': install | upgrade
*
* if 'operation' == 'file':
* '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', 64*1024*1024);
require_once('../approot.inc.php');
require_once(APPROOT.'/application/utils.inc.php');
require_once(APPROOT.'/setup/setuppage.class.inc.php');
require_once(APPROOT.'/setup/moduleinstaller.class.inc.php');
ini_set('max_execution_time', max(3600, ini_get('max_execution_time'))); // Under Windows SQL/backup operations are part of the timeout and require extra time
date_default_timezone_set('Europe/Paris'); // Just to avoid a warning if the timezone is not set in php.ini
$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
SetupPage::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 (!utils::IsMemoryLimitOk($iMemoryLimit, SAFE_MINIMUM_MEMORY))
{
if (ini_set('memory_limit', SAFE_MINIMUM_MEMORY) === FALSE)
{
SetupPage::log_error("memory_limit is too small: $iMemoryLimit and can not be increased by the script itself.");
}
else
{
SetupPage::log_info("memory_limit increased from $iMemoryLimit to ".SAFE_MINIMUM_MEMORY.".");
}
}
}
define('PHP_FATAL_ERROR_TAG', 'phpfatalerror');
/**
* Handler for register_shutdown_function, to catch PHP errors
*/
function ShutdownCallback()
{
$error = error_get_last();
$bIsErrorToReport = (($error !== null) && ($error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR)));
if (!$bIsErrorToReport)
{
return;
}
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
$sLogMessage = "PHP error occured : msg=$errstr, no=$errno, file=$errfile, line=$errline";
SetupPage::log_error("Setup error: $sLogMessage");
echo '<'.PHP_FATAL_ERROR_TAG.'>'.$sLogMessage.'</'.PHP_FATAL_ERROR_TAG.'>';
}
function FatalErrorCatcher($sOutput)
{
if (preg_match('|<'.PHP_FATAL_ERROR_TAG.'>.*</'.PHP_FATAL_ERROR_TAG.'>|s', $sOutput, $aMatches))
{
header("HTTP/1.0 500 Internal server error.");
$errors = '';
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...
//SetupPage::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.
ini_set('error_prepend_string', '<'.PHP_FATAL_ERROR_TAG.'>');
ini_set('error_append_string', '</'.PHP_FATAL_ERROR_TAG.'>');
// callback on errors to log
register_shutdown_function('ShutdownCallback');
// 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(APPROOT.'/core/config.class.inc.php');
require_once(APPROOT.'/core/log.class.inc.php');
require_once(APPROOT.'/core/kpi.class.inc.php');
require_once(APPROOT.'/core/cmdbsource.class.inc.php');
require_once('./xmldataloader.class.inc.php');
require_once(APPROOT.'/application/ajaxwebpage.class.inc.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
*/
$sOperation = Utils::ReadParam('operation', '');
try
{
switch($sOperation)
{
case 'async_action':
ini_set('max_execution_time', max(240, ini_get('max_execution_time')));
// While running the setup it is desirable to see any error that may happen
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
require_once(APPROOT.'/setup/wizardcontroller.class.inc.php');
require_once(APPROOT.'/setup/wizardsteps.class.inc.php');
$sClass = utils::ReadParam('step_class', '');
$sState = utils::ReadParam('step_state', '');
$sActionCode = utils::ReadParam('code', '');
$aParams = utils::ReadParam('params', array(), false, 'raw_data');
$oPage = new ajax_page('');
$oDummyController = new WizardController('');
if (is_subclass_of($sClass, 'WizardStep'))
{
/** @var WizardStep $oStep */
$oStep = new $sClass($oDummyController, $sState);
$sConfigFile = utils::GetConfigFilePath();
if (file_exists($sConfigFile) && !is_writable($sConfigFile) && $oStep->RequiresWritableConfig())
{
$oPage->error("<b>Error:</b> the configuration file '".$sConfigFile."' already exists and cannot be overwritten.");
$oPage->p("The wizard cannot modify the configuration file for you. If you want to upgrade ".ITOP_APPLICATION.", make sure that the file '<b>".realpath($sConfigFile)."</b>' can be modified by the web server.");
$oPage->output();
}
else
{
$oStep->AsyncAction($oPage, $sActionCode, $aParams);
}
}
$oPage->output();
break;
default:
throw(new Exception("Error unsupported operation '$sOperation'"));
}
}
catch(Exception $e)
{
header("HTTP/1.0 500 Internal server error.");
echo "<p>An error happened while processing the installation:</p>\n";
echo '<p>'.$e."</p>\n";
SetupPage::log_error("An error happened while processing the installation: ".$e);
}
if (function_exists('memory_get_peak_usage'))
{
if ($sOperation == 'file')
{
SetupPage::log_info("loading file '$sFileName', peak memory usage. ".memory_get_peak_usage());
}
else
{
SetupPage::log_info("operation '$sOperation', peak memory usage. ".memory_get_peak_usage());
}
}

View File

@@ -274,7 +274,7 @@ class SetupUtils
// Check that the limit will allow us to load the data
//
$iMemoryLimit = utils::ConvertToBytes($sMemoryLimit);
if ($iMemoryLimit < self::MIN_MEMORY_LIMIT)
if (!utils::IsMemoryLimitOk($iMemoryLimit, self::MIN_MEMORY_LIMIT))
{
$aResult[] = new CheckResult(CheckResult::ERROR, "memory_limit ($iMemoryLimit) is too small, the minimum value to run the application is ".self::MIN_MEMORY_LIMIT.".");
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Copyright (C) 2018 Dennis Lassiter
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with iTop. If not, see <http://www.gnu.org/licenses/>
*
*/
class UtilsTest extends \Combodo\iTop\Test\UnitTest\ItopTestCase
{
public function setUp()
{
parent::setUp();
require_once(APPROOT . 'application/utils.inc.php');
}
/**
* @dataProvider memoryLimitDataProvider
*/
public function testIsMemoryLimit($expected, $memoryLimit, $requiredMemory)
{
$this->assertSame($expected, utils::IsMemoryLimitOk($memoryLimit, $requiredMemory));
}
/**
* DataProvider for testIsMemoryLimitOk
*
* @return array
*/
public function memoryLimitDataProvider()
{
return [
[true, '-1', 1024],
[true, -1, 1024],
[true, 1024, 1024],
[true, 2048, 1024],
[false, 1024, 2048],
];
}
}

View File

@@ -412,6 +412,11 @@ class CriterionConversionTest extends ItopDataTestCase
'ExpectedOQL' => "SELECT `Contact` FROM Contact AS `Contact` JOIN Organization AS `Organization` ON `Contact`.org_id = `Organization`.id JOIN Organization AS `Organization1` ON `Organization`.parent_id BELOW `Organization1`.id WHERE (`Organization1`.`id` = '1')",
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key', 'operator' => 'IN')),
),
'key IN 2' => array(
'OQL' => "SELECT Contact WHERE org_id IN ('1', '999999')",
'ExpectedOQL' => "SELECT `Contact` FROM Contact AS `Contact` JOIN Organization AS `Organization` ON `Contact`.org_id = `Organization`.id JOIN Organization AS `Organization1` ON `Organization`.parent_id BELOW `Organization1`.id WHERE (`Organization1`.`id` = '1')",
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key', 'operator' => 'IN')),
),
'key empty' => array(
'OQL' => "SELECT Person WHERE location_id = '0'",
'ExpectedOQL' => "SELECT `Person` FROM Person AS `Person` WHERE (`Person`.`location_id` = '0')",
@@ -438,8 +443,8 @@ class CriterionConversionTest extends ItopDataTestCase
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key')),
),
'Hierarchical below 2' => array(
'OQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('2', '4')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'ExpectedOQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('2', '4')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'OQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('1', '2')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'ExpectedOQL' => "SELECT `Organization` FROM Organization AS `Organization` JOIN Organization AS `Organization1` ON `Organization`.parent_id = `Organization1`.id JOIN Organization AS `Organization11` ON `Organization1`.parent_id BELOW `Organization11`.id WHERE (((`Organization11`.`id` IN ('1', '2')) OR (`Organization`.`parent_id` = '0')) AND 1)",
'ExpectedCriterion' => array(array('widget' => 'hierarchical_key')),
),
'IP range' => array(

View File

@@ -19,6 +19,28 @@ class TagSetFieldDataTest extends ItopDataTestCase
// Need commit to create the FULLTEXT INDEX of MySQL
const USE_TRANSACTION = false;
public function testGetAllowedValues()
{
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iInitialCount = count($aAllowedValues);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(1, $iCurrCount - $iInitialCount);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag2', 'Second');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(2, $iCurrCount - $iInitialCount);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag3', 'Third');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(3, $iCurrCount - $iInitialCount);
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag4', 'Fourth');
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
$iCurrCount = count($aAllowedValues);
static::assertEquals(4, $iCurrCount - $iInitialCount);
}
public function testDoCheckToWrite()
{
$aAllowedValues = TagSetFieldData::GetAllowedValues(TAG_CLASS, TAG_ATTCODE);
@@ -67,8 +89,6 @@ class TagSetFieldDataTest extends ItopDataTestCase
}
/**
* @expectedException \CoreException
*
* @throws \CoreException
* @throws \CoreUnexpectedValue
*/
@@ -76,19 +96,34 @@ class TagSetFieldDataTest extends ItopDataTestCase
{
$oTagData = $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$oTagData->DBDelete();
$oTagData = $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
$oTicket = $this->CreateTicket(1);
$oTicket->Set(TAG_ATTCODE, 'tag1');
$oTicket->DBWrite();
$oTagData->DBDelete($oDeletionPlan);
try
{
$oTagData->DBDelete();
}
catch (\CoreException $e)
{
static::assertTrue(true);
return;
}
static::assertFalse(true);
}
public function testComputeValues()
{
$sTagClass = \MetaModel::GetTagDataClass(TAG_CLASS, TAG_ATTCODE);
$oTagData = $this->createObject($sTagClass, array(
'tag_code' => 'tag1',
'tag_label' => 'First',
));
$this->debug("Created {$oTagData->Get('tag_class')}::{$oTagData->Get('tag_attcode')}");
static::assertEquals(TAG_CLASS, $oTagData->Get('tag_class'));
static::assertEquals(TAG_ATTCODE, $oTagData->Get('tag_attcode'));
}
public function testGetAllowedValues()
{
}
}

View File

@@ -1,170 +1,170 @@
<?php
// Copyright (C) 2010-2012 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
/**
* Does load data from XML files (currently used in the setup and the backoffice data loader utility)
*
* @copyright Copyright (C) 2010-2012 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
/**
* This page is called to load an XML file into the database
* parameters
* 'file' string Name of the file to load
*/
define('SAFE_MINIMUM_MEMORY', 256*1024*1024);
require_once('../approot.inc.php');
require_once(APPROOT.'/application/application.inc.php');
require_once(APPROOT.'/application/startup.inc.php');
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
// required because the class xmldataloader is reporting errors in the setup.log file
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))
{
// 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
{
// 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)
{
$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
//
////////////////////////////////////////////////////////////////////////////////
// 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', '', false, 'raw_data');
$oP = new WebPage("iTop - Backoffice data loader");
try
{
// Note: the data model must be loaded first
$oDataLoader = new XMLDataLoader();
if (empty($sFileName))
{
throw(new Exception("Missing argument 'file'"));
}
if (!file_exists($sFileName))
{
throw(new Exception("File $sFileName does not exist"));
}
SetMemoryLimit($oP);
// The XMLDataLoader constructor has initialized the DB, let's start a transaction
CMDBSource::Query('START TRANSACTION');
$oChange = MetaModel::NewObject("CMDBChange");
$oChange->Set("date", time());
$oChange->Set("userinfo", "Initialization");
$iChangeId = $oChange->DBInsert();
$oP->p("Starting data load.");
$oDataLoader->StartSession($oChange);
$oDataLoader->LoadFile($sFileName);
$oP->p("Ending data load session");
if ($oDataLoader->EndSession(true /* strict */))
{
$iCountCreated = $oDataLoader->GetCountCreated();
CMDBSource::Query('COMMIT');
$oP->p("Data successfully written into the DB: $iCountCreated objects created");
}
else
{
CMDBSource::Query('ROLLBACK');
$oP->p("Some issues have been encountered, changes will not be recorded, please review the source data");
$aErrors = $oDataLoader->GetErrors();
if (count($aErrors) > 0)
{
$oP->p('Errors ('.count($aErrors).')');
foreach ($aErrors as $sMsg)
{
$oP->p(' * '.$sMsg);
}
}
$aWarnings = $oDataLoader->GetWarnings();
if (count($aWarnings) > 0)
{
$oP->p('Warnings ('.count($aWarnings).')');
foreach ($aWarnings as $sMsg)
{
$oP->p(' * '.$sMsg);
}
}
}
}
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'))
{
$oP->p("Information: memory peak usage: ".memory_get_peak_usage());
}
$oP->Output();
?>
<?php
// Copyright (C) 2010-2012 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
/**
* Does load data from XML files (currently used in the setup and the backoffice data loader utility)
*
* @copyright Copyright (C) 2010-2012 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
/**
* This page is called to load an XML file into the database
* parameters
* 'file' string Name of the file to load
*/
define('SAFE_MINIMUM_MEMORY', 256*1024*1024);
require_once('../approot.inc.php');
require_once(APPROOT.'/application/application.inc.php');
require_once(APPROOT.'/application/startup.inc.php');
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
// required because the class xmldataloader is reporting errors in the setup.log file
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))
{
// 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
{
// 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.".");
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Main
//
////////////////////////////////////////////////////////////////////////////////
// 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', '', false, 'raw_data');
$oP = new WebPage("iTop - Backoffice data loader");
try
{
// Note: the data model must be loaded first
$oDataLoader = new XMLDataLoader();
if (empty($sFileName))
{
throw(new Exception("Missing argument 'file'"));
}
if (!file_exists($sFileName))
{
throw(new Exception("File $sFileName does not exist"));
}
SetMemoryLimit($oP);
// The XMLDataLoader constructor has initialized the DB, let's start a transaction
CMDBSource::Query('START TRANSACTION');
$oChange = MetaModel::NewObject("CMDBChange");
$oChange->Set("date", time());
$oChange->Set("userinfo", "Initialization");
$iChangeId = $oChange->DBInsert();
$oP->p("Starting data load.");
$oDataLoader->StartSession($oChange);
$oDataLoader->LoadFile($sFileName);
$oP->p("Ending data load session");
if ($oDataLoader->EndSession(true /* strict */))
{
$iCountCreated = $oDataLoader->GetCountCreated();
CMDBSource::Query('COMMIT');
$oP->p("Data successfully written into the DB: $iCountCreated objects created");
}
else
{
CMDBSource::Query('ROLLBACK');
$oP->p("Some issues have been encountered, changes will not be recorded, please review the source data");
$aErrors = $oDataLoader->GetErrors();
if (count($aErrors) > 0)
{
$oP->p('Errors ('.count($aErrors).')');
foreach ($aErrors as $sMsg)
{
$oP->p(' * '.$sMsg);
}
}
$aWarnings = $oDataLoader->GetWarnings();
if (count($aWarnings) > 0)
{
$oP->p('Warnings ('.count($aWarnings).')');
foreach ($aWarnings as $sMsg)
{
$oP->p(' * '.$sMsg);
}
}
}
}
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'))
{
$oP->p("Information: memory peak usage: ".memory_get_peak_usage());
}
$oP->Output();
?>