Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N°7216 import improves error handling missing or null data #612

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
accognet committed Sep 27, 2024
commit e9758a251cd9357e2d9bcd177f2064478a57b927
5 changes: 4 additions & 1 deletion core/bulkchange.class.inc.php
Original file line number Diff line number Diff line change
@@ -1181,6 +1181,9 @@ public function Process(CMDBChange $oChange = null)
foreach($this->m_aData as $iRow => $aRowData)
{
$sFormat = $sDateTimeFormat;
if(!isset($this->m_aData[$iRow][$iCol])){
continue;
}
$sValue = $this->m_aData[$iRow][$iCol];
if (!empty($sValue))
{
@@ -1241,7 +1244,7 @@ public function Process(CMDBChange $oChange = null)
foreach ($this->m_aData as $iRow => $aRowData) {
set_time_limit(intval($iLoopTimeLimit));
//stop if not enough cols in $aRowData
if(count($aRowData) != $iNBFields){
if(count($aRowData) < $iNBFields){
$aResult[$iRow]["__STATUS__"] = new RowStatus_Issue(Dict::Format('UI:CSVReport-Row-Issue-NbField',count($aRowData),$iNBFields) );
continue;
}
76 changes: 59 additions & 17 deletions tests/php-unit-tests/unitary-tests/core/BulkChangeTest.php
Original file line number Diff line number Diff line change
@@ -293,21 +293,21 @@ public function bulkChangeWithExistingDataProvider() {
["1", "Server1", "production", ""],
"csvData" =>
[[">Demo", "Server1"]],
"attributes"=>
["name" => 1],
"extKeys"=>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
["name"],
"expectedResult"=>
[
0 => ">Demo",
"org_id" => "n/a",
1 => "Server1",
"id" => "Invalid value for attribute",
"__STATUS__" => "Issue: ambiguous reconciliation",
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
],
"attributes"=>
["name" => 1],
"extKeys"=>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
["name"],
"expectedResult"=>
[
0 => ">Demo",
"org_id" => "n/a",
1 => "Server1",
"id" => "Invalid value for attribute",
"__STATUS__" => "Issue: ambiguous reconciliation",
"__ERRORS__" => "Allowed 'status' value(s): stock,implementation,production,obsolete",
],
"expectedResultHTML"=>
[
0 => "&gt;Demo",
@@ -321,9 +321,9 @@ public function bulkChangeWithExistingDataProvider() {
"Case 6 - 1 : Unexpected value (update)" => [
"initData"=>
["1", ">ServerTest", "production", ""],
"csvData"=>
"csvData"=>
[["Demo", ">ServerTest", "key - will be automatically overwritten by test", ">BadValue", ""]],
"attributes"=>
"attributes"=>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
["org_id" => ["name" => 0]],
@@ -579,6 +579,48 @@ public function bulkChangeWithExistingDataProvider() {
[ "id" => "{Id of the server created by the test}",
0 => "Demo", "org_id" => "n/a", 1 => ">ServerTest", 2 => "1", 3 => "production", 4 => "'2020-20-03' is an invalid value", "id" => 1, "__STATUS__" => "Issue: wrong date format"],
],
"Case 11 : Missing AttributeDateTime cell should issue an error" => [
"initData"=>
["1", "ServerTest", "production", "2020-02-01"],
"csvData"=>
[["Demo", "ServerTest", "1", "production"]],
"attributes"=>
["name" => 1, "id" => 2, "status" => 3, "purchase_date" => 4],
"extKeys"=>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
["id"],
"expectedResult"=>
[ 0 => "Demo", "org_id" => "n/a", 1 => "ServerTest", 2 => "1", 3 => "production", 4 => "'' is an invalid value", "id" => 1, "__STATUS__" => 'Issue: Not the expected number of fields (current : 4 fields, expected :5)'],
],
"Case 12 : Missing AttributeEnum cell should issue an error" => [
"initData"=>
["1", "ServerTest", "production", "2020-02-01"],
"csvData"=>
[["Demo", "ServerTest", "1", "2020-02-01"]], // missing status
"attributes"=>
["name" => 1, "id" => 2, "purchase_date" => 3, "status" => 4],
"extKeys"=>
["org_id" => ["name" => 0]],
"reconcilKeys"=>
["id"],
"expectedResult"=>
[ 0 => "Demo", "org_id" => "n/a", 1 => "ServerTest", 2 => "1", 3 => "2020-02-01", 4 => "'' is an invalid value", "id" => 1, "__STATUS__" => "Issue: Not the expected number of fields (current : 4 fields, expected :5)"],
],
"Case 13 : Missing AttributeExternalKey cell should issue an error" => [
"initData"=>
["1", "ServerTest", "production", "2020-02-01"],
"csvData"=>
[["ServerTest", "1", "production", "2020-02-01"]], // missing org_id
"attributes"=>
["name" => 0, "id" => 1, "status" => 2, "purchase_date" => 3],
"extKeys"=>
["org_id" => ["name" => 4]],
"reconcilKeys"=>
["id"],
"expectedResult"=>
[ 0 => "ServerTest", "org_id" => "n/a", 1 => "1", 2 => "1", 3 => "2020-02-01", 4 => "'' is an invalid value", "id" => 1, "__STATUS__" => "Issue: Not the expected number of fields (current : 4 fields, expected :5)"],
],
];
}