diff --git a/system/modules/tabimporter/Tabimporter.php b/system/modules/tabimporter/Tabimporter.php index e820c64..fa6a791 100644 --- a/system/modules/tabimporter/Tabimporter.php +++ b/system/modules/tabimporter/Tabimporter.php @@ -439,9 +439,9 @@ public function runStep($intStep, $line=false) elseif(in_array('missing',$arrTableimport['deleteOnStart']) && is_array($arrTableimport['existentKeysSource']) && is_array($arrTableimport['existentKeysTarget'])) { $arrToDelete=array_diff($arrTableimport['existentKeysTarget'],$arrTableimport['existentKeysSource']); - if(count($arrToDelete>0)) + if(count($arrToDelete)>0) { - $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['deleteKeyField']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); + $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['uniqueTarget']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); $this->updateStatus($arrCheck['result'], $objSteps->abortOnError, $objSteps->title, sprintf($GLOBALS['TL_LANG']['tl_tabimporter']['missing_ok'],$arrTableimport['targetTable']), @@ -470,9 +470,9 @@ public function runStep($intStep, $line=false) { $arrNotExistent=array_diff($arrTableimport['existentKeysSource'],$arrTableimport['existentKeysTarget']); $arrToDelete=array_diff($arrTableimport['existentKeysTarget'],$arrNotExistent); - if(count($arrToDelete>0)) + if(count($arrToDelete)>0) { - $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['deleteKeyField']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); + $arrCheck = $this->performSQL("DELETE FROM ".$arrTableimport['targetTable']."_tabimport WHERE ".$arrTableimport['uniqueTarget']." IN ('".implode('\',\'',$arrToDelete)."')",array(),false); $this->updateStatus($arrCheck['result'], $objSteps->abortOnError, $objSteps->title, sprintf($GLOBALS['TL_LANG']['tl_tabimporter']['existent_ok'],$arrTableimport['targetTable']), @@ -955,7 +955,7 @@ public function getExistentKeysTarget($arrTableimport) } else { - $objKeys = $this->Database->prepare("SELECT ".$arrTableimport['uniqueTarget']." FROM ".$arrTableimport['targetTable']." WHERE ".$arrTableimport['uniqueTarget']." IN ('".implode('\',\'',$arrTableimport['existentKeysSource'])."')") + $objKeys = $this->Database->prepare("SELECT ".$arrTableimport['uniqueTarget']." FROM ".$arrTableimport['targetTable']." ") ->executeUncached(); $arrKeys = $objKeys->fetchEach($arrTableimport['uniqueTarget']); diff --git a/system/modules/tabimporter/TabimporterSource_csv.php b/system/modules/tabimporter/TabimporterSource_csv.php index 4d22ebe..a2cc4da 100644 --- a/system/modules/tabimporter/TabimporterSource_csv.php +++ b/system/modules/tabimporter/TabimporterSource_csv.php @@ -82,19 +82,24 @@ public function getAllData($arrTableimport) for($i=0;$i < sizeof($arrContent); $i++) { $arrContent[$i] = $this->String->splitCsv($arrContent[$i], $strDelimiter); - - // get field names ba first line - if($arrTableimport['hasFieldnames']) + $arrNewContent = array(); + + //skip first row with field names + if ($i == 0 && $arrTableimport['hasFieldnames']) continue; + + // get field names of first line or set key to field_x + for($ii=0;$ii0) - { - unset($arrContent[$i][$ii]); - } - } - } + $arrNewContent[$arrContent[0][$ii]] = $arrContent[$i][$ii]; + }else{ + $arrNewContent['field_'.$ii] = $arrContent[$i][$ii]; + } + } + + $arrContent[$i] = $arrNewContent; } @@ -126,7 +131,7 @@ public function getExistentKeysSource($arrTableimport) $arrKeys[] = $arrData[($arrTableimport['hasFieldnames'] ? $arrTableimport['uniqueSource'] : - str_replace('field_','',$arrTableimport['uniqueSource']))]; + $arrTableimport['uniqueSource'])]; } if(!$arrKeys || count($arrKeys)<1)